【问题标题】:testNG parallel execution not workingtestNG并行执行不起作用
【发布时间】:2013-11-26 06:38:34
【问题描述】:

我正在尝试使用 testNG 为两个浏览器并行运行以下测试,同时运行两个浏览器都使用 URL 启动,但仅对一个浏览器进行完整的测试执行。

这是我的测试套件类

@Test (groups = {"Enable"}) 
@SuppressWarnings("unused")
public class EETestSuite_01 extends ApplicationFunctions{
    String URL = Globals.GC_EMPTY;

    @BeforeTest
    @Parameters("browser")
    public void loadTest(String browser) throws IOException{
        InitializeTestEnv("EE|BizApp");
        if(browser.equalsIgnoreCase("Firefox"))
               GetBrowser("Firefox");
            else if(browser.equalsIgnoreCase("Chrome")){
               GetBrowser("Chrome");
            }

    }

    @AfterMethod
    public void cleartest() throws InterruptedException{
        driver.close();
        driver.quit();
        driver = null;
    }


    public void TC001_Phone_First_Acquisition_Journey_PAYM() throws InterruptedException{
        URL = EnvDetail.get(Globals.GC_HOME_PAGE);
        Map<String,String> TDChoosePlan = null;
        TDChoosePlan = getData(appName+Globals.GC_TEST_DATA_SHEET,"ChoosePlan",1);
        try{
            launchApp(URL); 
            //driver.navigate().to("javascript:document.getElementById('overridelink').click()");
            EEHomePage homePage = PageFactory.initElements(driver, EEHomePage.class);
            EEShopPage shopPage = homePage.GetToShopPage();
            EEPhoneMatrixPage phonePage = shopPage.GetToPhoneMatrixPage();
            EEChoosePlanPage planPage = phonePage.ChoosePhone("NokiaLumia1020"); // Implement select phone
            EEAddonsPage addonPage = planPage.SelectPhonesPlan(TDChoosePlan);
            EEBasket basketPage = addonPage.GoToBasketPage();
            EESecureCheckOut secureChkOutPage = basketPage.GoToSecureCheckOutPage();
            secureChkOutPage.ChooseNonExistingCustomer();
            EEConfirmation confPage = secureChkOutPage.FillUserRegisterForm(2);
        }catch(Exception e){
            e.printStackTrace();
        }       
    }


}

我的 XML 看起来像这样

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name = "EEAutomationTestSuite" verbose="2" parallel = "tests" thread-count="100">

<test name="PAYM Acquisition in Chrome">
  <parameter name="browser" value="Firefox"></parameter>
   <classes>
     <class name="com.testsuite.EETestSuite_01">
    </class>
  </classes>
</test>

<test name="PAYM Acquisition in FF">
  <parameter name="browser" value="Firefox"></parameter>
   <classes>
     <class name="com.testsuite.EETestSuite_01">
    </class>
  </classes>
</test>
</suite>

我的主页代码是这样的

*/  public EEShopPage GetToShopPage() throws InterruptedException{

       // longWait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(OR.getProperty("wblShopHeader"))));   
        lblShopHeader = driver.findElement(By.cssSelector(OR.getProperty("wblShopHeader")));
        Actions builder = new Actions(driver); 
        Actions hoverOverRegistrar = builder.moveToElement(lblShopHeader);
        hoverOverRegistrar.perform();Thread.sleep(10000);
        lnkStartShopping = driver.findElement(By.cssSelector(OR.getProperty("lnkStartShopping")));
        mediumWait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(OR.getProperty("lnkStartShopping"))));
        lnkStartShopping.click();
        return PageFactory.initElements(driver,EEShopPage.class );
    }
}

这是司机

public static void GetBrowser(String browser){
        try{
            if (browser.equalsIgnoreCase("firefox")) {              
//              FirefoxProfile firefoxProfile = new FirefoxProfile();
//              File pathToBinary = new File(Globals.GC_FIREFOX_BIN_PATH);
//              FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
                //firefoxProfile.setPreference("webdriver.load.strategy","unstable");
                driver = new FirefoxDriver();
            } else if (browser.equalsIgnoreCase("iexplorer")){
                System.setProperty("webdriver.ie.driver", System.getProperty("user.dir") + 
                                   "//resource//drivers//IEDriverServer.exe");          
                DesiredCapabilities capabilities = new DesiredCapabilities(); 
                capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                driver = new InternetExplorerDriver(capabilities);
            } else if (browser.equalsIgnoreCase("chrome")){
                System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + 
                                   "//resource//drivers//chromedriver.exe");

我只是猜测主页中有一个悬停动作,对于一个浏览器它工作正常,但对于另一个浏览器没有任何反应....是焦点问题吗??

请告诉我如何通过示例解决此问题

【问题讨论】:

    标签: java selenium selenium-webdriver testng


    【解决方案1】:

    我无法从您的代码中判断出您为页面对象 EEHomePage 使用的构造函数。

    因为,如果您使用默认构造函数,那么您的 PageFactory 将无法初始化您的 Web 元素,除非它们由 @FindBy 注释定义,

    PageFactory 将 webDriver 和 Object 类作为参数,并在内部使用提供的 webDriver 初始化该 Object 类。这可以通过以下两种方式实现:

    1) 使用@FindBy 注释在您的pageObjects 中定义您的webElements,如下所示:

     @FindBy(css=//your locator value here)
        private WebElement lblShopHeader;
    

    2) 定义构造函数并通过 PageFactory 提供的 webdriver 初始化您的 pageobject webdriver,如下所示:

    EEHomeShop(WebDriver driver){
    
       this.driver=driver;
    
      }
    

    【讨论】:

      猜你喜欢
      • 2020-03-01
      • 2020-08-08
      • 2020-03-01
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多