使用selenium webdriver Grid运行它们时,脚本没有按预期运行 [英] Scripts are not running as expected while running them using selenium webdriver Grid

查看:82
本文介绍了使用selenium webdriver Grid运行它们时,脚本没有按预期运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一次在三个浏览器IE,Chrome和Firefox上运行相同的脚本(即并行)。我在 Testng.xml中使用以下代码 file

 < test name =RunTests-1> 
< parameter name =browservalue =firefox/>
< parameter name =portvalue =http:// localhost:4444 / wd / hub/>
< classes>
< class name =Com.TestSuite.class1/>
< / classes>
< / test>
< test name =RunTests-2>
< parameter name =browservalue =chrome/>
< parameter name =portvalue =http:// localhost:4444 / wd / hub/>
< classes>
< class name =Com.TestSuite.class1/>
< / classes>
< / test>
< test name =RunTests-3>
< parameter name =browservalue =internet explorer/>
< parameter name =portvalue =http:// localhost:4444 / wd / hub/>
< classes>
< class name =Com.TestSuite.class1/>
< / classes>
< / test>

使用TestNG运行它时,它打开3个浏览器并执行脚本。但问题出在执行脚本时,它正在脚本中执行一些操作(如在文本框中输入文本,单击按钮等)两次在一个浏览器中执行,而在其他浏览器中完全没有执行。请让我知道可能是什么原因。 当您将变量声明为时,静态。它将被视为服务器端变量。在你的情况下,当你启动三个浏览器。它将为所有三个浏览器会话使用单个驱动程序实例。仅因为这个原因,该动作在同一浏览器中反复执行。要解决该问题,请从网络驱动程序定义中移除 Static关键字

例如:




$ b

私人WebDriver驱动程序= null;

I want to run same script on three browser IE, Chrome and Firefox at a time (i.e., parallel). I am using the following code in Testng.xml file

 <test name="RunTests-1">
    <parameter name="browser" value="firefox" />     
    <parameter name="port" value="http://localhost:4444/wd/hub" />
    <classes>
        <class name="Com.TestSuite.class1"/>
    </classes>
</test>  
<test name="RunTests-2">
    <parameter name="browser" value="chrome" />     
    <parameter name="port" value="http://localhost:4444/wd/hub" />
    <classes>
        <class name="Com.TestSuite.class1"/>
    </classes>
</test>
<test name="RunTests-3">
    <parameter name="browser" value="internet explorer" />     
    <parameter name="port" value="http://localhost:4444/wd/hub" />
    <classes>
        <class name="Com.TestSuite.class1"/>
    </classes>
</test> 

while running it using TestNG, it is opening 3 browsers and executing the script. But the problem is while executing the script, it is performing some operations in the script(like entering a text in text field, clicking on a button etc) twice in one browser and not at all performing in other browsers. Please let me know what may be the reason for that.

解决方案

When you declare the variable as a Static. It will consider as a server side variable. In your case when you launch three browsers. It will use single driver instance for all the three browser sessions. For that reason alone the action is performing repeatedly in a same browser. To resolve the issue remove the Static keyword from the web driver definition.

Eg:

private WebDriver driver = null;

这篇关于使用selenium webdriver Grid运行它们时,脚本没有按预期运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆