1
votes

I am trying to run following test in parallel for two browsers using testNG, while running both the browsers are getting launched with the URL, but the complete test execution is happening for only one browser.

Here is my Test Suite class

@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();
        }       
    }


}

My XML looks like this

<!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>

And my code for the Home page is this

*/  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 );
    }
}

Here is the driver

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");

I am just guessing that there is a hover action in the home page, and for one browser it works fine but for the other nothing happens.... is it due focus issue ??

Please let me know how to solve this with an example

1

1 Answers

1
votes

I cannot make it out from your code, which constructor you are using for your page Object EEHomePage.

Because, if you are using default constructor then your PageFactory will not be able to initialize your web elements unless they are defined by @FindBy annotation,

PageFactory takes webDriver and Object class as arguments and internally initializes that Object class with provided webDriver.This can be achieved by two ways as below :

1) either define your webElements in your pageObjects using @FindBy annotations as follow :

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

OR

2) define constructor and initialize your pageobject webdriver by PageFactory provided webdriver as follow :

EEHomeShop(WebDriver driver){

   this.driver=driver;

  }