简体   繁体   English

Selenium Grid与页面对象模型页面工厂

[英]Selenium Grid With Page Object Model Page Factory

How would I initialize the browser if I want to test on multiple browsers using Page Object Model Page Factory? 如果我想使用Page Object Model Page Factory在多个浏览器上进行测试,我将如何初始化浏览器?

Currently I have iniatialized the browsers in my Base Class like this. 目前我已经在我的基类中对这些浏览器进行了初始化。

// initialise driver/browser

 public void initDriver() throws MalformedURLException{
   if(CONFIG.getProperty("browser").equals("firefox")){
       cap = DesiredCapabilities.firefox();
       cap.setBrowserName("firefox"); // chrome,iexplore
       cap.setPlatform(Platform.ANY);
   }else if (CONFIG.getProperty("browser").equals("chrome")){
       cap = DesiredCapabilities.chrome(); // no need path of chrome exe
       cap.setBrowserName("chrome");
       cap.setPlatform(Platform.ANY);
   }else if (CONFIG.getProperty("browser").equals("iexplore")){
       cap = DesiredCapabilities.internetExplorer(); // no need path of chrome exe
       cap.setBrowserName("iexplore");
       cap.setPlatform(Platform.WINDOWS);
   }
   if(driver == null){
       driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),cap);
   }
   String waitTime=CONFIG.getProperty("default_implicitWait");
   driver.manage().timeouts().implicitlyWait(Long.parseLong(waitTime), TimeUnit.SECONDS);
   }

This however only runs my test my test only on one of the browsers. 然而,这仅在我的测试中运行我的测试仅在其中一个浏览器上。

This is my testng.xml file 这是我的testng.xml文件

<suite name="Selenium Grid with webdriver" >
<listeners>
    <listener class-name="Codes.listener.TestsListenerAdapter" />
</listeners>
<test name="Login test">
    <classes>
        <class name="Codes.testCases.LoginTest" ></class>  
    </classes>
</test>
</suite>

Your browser initialization seems ok but I am wondering , why cap is not initialized when driver == null You should improve your testng.xml in following way: 您的浏览器初始化似乎没问题,但我想知道,为什么在driver == null时未初始化cap您应该按以下方式改进testng.xml

To Run the test methods parallely: 并行运行测试方法:

<suite name="Selenium Grid with webdriver" parallel="methods" thread-count="5" >
    <listeners>
        <listener class-name="Codes.listener.TestsListenerAdapter" />
    </listeners>
    <test name="Login test">
        <classes>
            <class name="Codes.testCases.LoginTest" ></class>  
        </classes>
    </test>
</suite>

Similarly you can define parallel = "classes" or parallel = "tests" to choose the parallel execution level. 类似地,您可以定义parallel = "classes"parallel = "tests"来选择并行执行级别。

As @Priyanshu mentioned, you need to change your testng.xml. 正如@Priyanshu所提到的,你需要改变你的testng.xml。 I believe that you have updated your testng.xml but as per your above testng.xml file you have only one <class> in <test> , so in your cases parallel="methods" (I assume you wanna execute different test scripts in parallel and not different methods of same test script) or parallel="classes" will not work. 我相信你已经更新了你的testng.xml但是根据你上面的testng.xml文件,你在<test>只有一个<class> <test> ,所以在你的情况下parallel="methods" (我假设你想要执行不同的测试脚本)并行而不是相同测试脚本的不同方法)或parallel="classes"将不起作用。 Change it to parallel="tests" and then try running it like this :- 将其更改为parallel="tests" ,然后尝试像这样运行: -

<suite name="Selenium Grid with webdriver" parallel="tests" thread-count="5" >
    <listeners>
        <listener class-name="Codes.listener.TestsListenerAdapter" />
    </listeners>
    <test name="Login test">
        <classes>
            <class name="Codes.testCases.LoginTest" ></class>  
        </classes>
    </test>

    <test name="Login test2">
        <classes>
            <class name="Codes.testCases.LoginTest2" ></class>  
        </classes>
    </test>

   <test name="Login test3"> 

   <!-- class etc.. etc.. -->

   </test>

</suite>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM