如何通过 Java-TestNG 在 selenium RC 中设置 Grid 2

发布于 2024-12-20 03:47:16 字数 4561 浏览 0 评论 0原文

我是 Grid 新手,正在尝试在 Selenium RC 中设置 Grid 2。

我已经下载了selenium-server-standalone-2.1.0.jar。我还有我的 TestNG 测试用例。

我有一个测试 XML,如下所示:

<suite thread-count="1" name="Suite" parallel="tests" verbose="10"><!-- tests -->
        <test name="FFTest" preserve-order="true">
        <parameter name="selenium.host" value="localhost"></parameter>
        <parameter name="selenium.port" value="5569"></parameter>
        <parameter name="selenium.browser" value="*firefox"></parameter>
        <parameter name="selenium.url" value="http://www.google.com"></parameter>
        <classes>

            <class name="EmployeeHealth.TestScripts.EmployeeHealthRegressionSuite">
                <methods>
                    <include name="InitScript"></include> 
                    <include name="SelectAvoidableAdmissionModule"></include>
                    </methods>  
            </class>


        </classes>
    </test>
<test name="IETest" preserve-order="true">
    <parameter name="selenium.host" value="localhost"></parameter>
    <parameter name="selenium.port" value="5579"></parameter>
    <parameter name="selenium.browser" value="*iehta"></parameter>
    <parameter name="selenium.url" value="http://www.google.com"></parameter>
    <classes>

        <class name="EmployeeHealth.TestScripts.EmployeeHealthRegressionSuite">
            <methods>
                <include name="InitScript"></include> 
                <include name="SelectAvoidableAdmissionModule"></include>
                </methods>  
        </class>


    </classes>
</test>
</suite>    

我按照以下步骤进行操作:

启动集线器:

        java -jar selenium-server-standalone-2.5.0.jar -role hub

启动支持 Firefox 的远程控制

        java -jar selenium-server-standalone-2.5.0.jar -role RC -hub http://localhost:4444/grid/register -browser browserName=firefox,platform=WINDOWS -port 5579

启动另一个支持 Internet 探索的 RC

        java -jar selenium-server-standalone-2.5.0.jar -role RC -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=WINDOWS -port 5556.

在我的 SetUp.java 文件中,创建 selenium 对象,如:

        selenium =  new DefaultSelenium(host,Integer.parseInt(port),
                        browser, url);


                if ( browser.equalsIgnoreCase("*chrome")) {
                    RemoteControlConfiguration rcc = new RemoteControlConfiguration();
                    rcc.setFirefoxProfileTemplate(new File(
                            "test\\Resources\\ThirdParty\\FirefoxProfile\\"));
                    seleniumServer = new SeleniumServer(rcc);

                } else {
                    RemoteControlConfiguration rcc = new RemoteControlConfiguration();
                    rcc.setFirefoxProfileTemplate(new File("Object Repository\\SSL"));
                            //"src\\Script\\lib\\ThirdParty\\FirefoxProfile\\"));C:\\Biju\\NewFrameworkStrcuture\\Framework\\ABC_JSAF\\

                    seleniumServer = new SeleniumServer(rcc);
                    RemoteControlConfiguration a= seleniumServer.getConfiguration();
                    File uimap=new File("src\\Script\\lib\\user-extensions.js");
                    a.setUserExtensions(uimap);
                    //seleniumServer = new SeleniumServer();
                }
                //seleniumServer.start();
                selenium.start();
                selenium.windowMaximize();
                selenium.windowFocus();

通过这种方式,当 am运行 xml 文件,测试按顺序运行(首先是 Firefox,然后是 IE)。但不是并行的。

我还尝试提供 @Test 参数,例如

  @Test(dataProvider="CommonTestData",threadPoolSize = 3)

但我没有看到序列有任何变化。

有人知道为什么会发生这种情况吗?..

感谢您的帮助。


阿杰,谢谢你的回复。

我在 XML 套件中进行了更改,并将 dataprovider 函数设置为“parallel=true”,还添加了调用函数 @Test 参数“InvoationCount=2”,并配置了节点,并且能够并行启动 1 个 IE 和 1 个 FF。

但现在的问题是,在一个浏览器(比如 IE)中,我的测试用例执行得很好。但是在另一个浏览器(FF)中,启动浏览器后,我没有看到任何其他操作在其上执行。甚至没有打开我的网址。在控制台中我收到错误: “配置失败:@BeforeClass Seleniumstart ("localhost", "5569", "*firefox", "http://www.google.com" ) com.thoughtworks.selenium.SeleniumException:错误服务器异常:sessionId 不应该
无效的;这次会议开始了吗?” 对此有什么想法吗?...

I am new to Grid and am trying to set up Grid 2 in Selenium RC.

I have downloaded the selenium-server-standalone-2.1.0.jar. Also I have my TestNG test cases.

And I have a test XML like:

<suite thread-count="1" name="Suite" parallel="tests" verbose="10"><!-- tests -->
        <test name="FFTest" preserve-order="true">
        <parameter name="selenium.host" value="localhost"></parameter>
        <parameter name="selenium.port" value="5569"></parameter>
        <parameter name="selenium.browser" value="*firefox"></parameter>
        <parameter name="selenium.url" value="http://www.google.com"></parameter>
        <classes>

            <class name="EmployeeHealth.TestScripts.EmployeeHealthRegressionSuite">
                <methods>
                    <include name="InitScript"></include> 
                    <include name="SelectAvoidableAdmissionModule"></include>
                    </methods>  
            </class>


        </classes>
    </test>
<test name="IETest" preserve-order="true">
    <parameter name="selenium.host" value="localhost"></parameter>
    <parameter name="selenium.port" value="5579"></parameter>
    <parameter name="selenium.browser" value="*iehta"></parameter>
    <parameter name="selenium.url" value="http://www.google.com"></parameter>
    <classes>

        <class name="EmployeeHealth.TestScripts.EmployeeHealthRegressionSuite">
            <methods>
                <include name="InitScript"></include> 
                <include name="SelectAvoidableAdmissionModule"></include>
                </methods>  
        </class>


    </classes>
</test>
</suite>    

And I followed the below steps:

Start Hub:

        java -jar selenium-server-standalone-2.5.0.jar -role hub

Start remote control supporting Firefox

        java -jar selenium-server-standalone-2.5.0.jar -role RC -hub http://localhost:4444/grid/register -browser browserName=firefox,platform=WINDOWS -port 5579

Start another RC supporting Internet explore

        java -jar selenium-server-standalone-2.5.0.jar -role RC -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=WINDOWS -port 5556.

And in my SetUp.java file, Am creating the selenium objects like:

        selenium =  new DefaultSelenium(host,Integer.parseInt(port),
                        browser, url);


                if ( browser.equalsIgnoreCase("*chrome")) {
                    RemoteControlConfiguration rcc = new RemoteControlConfiguration();
                    rcc.setFirefoxProfileTemplate(new File(
                            "test\\Resources\\ThirdParty\\FirefoxProfile\\"));
                    seleniumServer = new SeleniumServer(rcc);

                } else {
                    RemoteControlConfiguration rcc = new RemoteControlConfiguration();
                    rcc.setFirefoxProfileTemplate(new File("Object Repository\\SSL"));
                            //"src\\Script\\lib\\ThirdParty\\FirefoxProfile\\"));C:\\Biju\\NewFrameworkStrcuture\\Framework\\ABC_JSAF\\

                    seleniumServer = new SeleniumServer(rcc);
                    RemoteControlConfiguration a= seleniumServer.getConfiguration();
                    File uimap=new File("src\\Script\\lib\\user-extensions.js");
                    a.setUserExtensions(uimap);
                    //seleniumServer = new SeleniumServer();
                }
                //seleniumServer.start();
                selenium.start();
                selenium.windowMaximize();
                selenium.windowFocus();

By this way, when am running the xml file, the tests are running in sequence(First Firefox and then the IE). But not in parallel.

Also i tried giving the @Test parameter like

  @Test(dataProvider="CommonTestData",threadPoolSize = 3)

But i dont see any change in the seqence.

do any one got why this is happening?..

Appreciate for your help.


A J, Thanks for the reply.

I did changes in the XML suite and I made the dataprovider function as "parallel=true" and also added the Invokation function @Test parameter "InvoationCount=2",and configure the node and am able to launch 1 IE and 1 FF parallel.

But now the problem is, in one browser(Say IE), my test cases are executing perfectly.But in the other browser(FF) ,after launching the browser, I don't see any other action performing on it.Not even opening my URL. in the console I got error :
"FAILED CONFIGURATION: @BeforeClass Seleniumstart
("localhost", "5569", "*firefox", "http://www.google.com")
com.thoughtworks.selenium.SeleniumException: ERROR Server Exception: sessionId should not be
null; has this session been started yet?"
Any idea on this?..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦魇绽荼蘼 2024-12-27 03:47:16

如果您正在使用dataprovider,您还需要提及是否应该并行调用它。您的 CommonTestData 方法应该具有parallel=true 选项。

要使用 XML 执行,您需要将线程数增加到 1 以上才能并行执行。

If you are using dataprovider, you also need to mention whether it should be called in parallel. Your CommonTestData method should have parallel=true option.

For executing using the XML, you need to increase the thread count to more than 1 for parallel execution.

↘人皮目录ツ 2024-12-27 03:47:16

您的 Firefox XML 配置似乎尝试将测试发送到端口 5569 上的节点。但在实际的客户端节点连接字符串中,您将其指定为使用端口 5579。您的 IE 设置似乎尝试使用 5579,但以 5556 开头。

It looks like your Firefox XML config tries to send the test to a node on port 5569. But in your actual client node connection string you are assigning it to use port 5579. It also looks like your IE settings attempt to use 5579 but are started with 5556.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文