testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.98k stars 1.02k forks source link

When create Data driven framework with the TestNG dataProvider, Not able to do cross browser testing in parallel with TestNG xml file. If I remove Parallel works fine.But if I try parallel TestNG provide one data for browser then second data for next browser and throws error #2226

Closed SQALeaders closed 4 years ago

SQALeaders commented 4 years ago

TestNG Version

Note: only the latest version is supported

Expected behavior

When creating Data-driven framework with the TestNG dataProvider, Not able to do cross-browser testing in parallel with the TestNG XML file. If I remove Parallel works fine. But if I try to do parallel TestNG provide one data for browser then second data for the next browser and throws an error

TestNG Version - 7.1.0 Expected behavior If I have 10 data in excel file TestNG should run all 10 for each browser. Example if I run Chrome and Firefox both browsers should run all 10 data

Actual behavior TestNG gives first data for Chrome, second data for Firefox and throw error org.openqa.selenium.ElementNotInteractableException: element not interactable.

Is the issue reproductible on runner?

Maven IntelliJ Test case sample Testcase to verify valid login

public class VerifyValidLogin extends BaseClass {
@Test(dataProvider = "ExcelInput")
    public void VLogin(String EMail, String PWord) throws InterruptedException {
    WPHomePage HLClick = PageFactory.initElements(driver, WPHomePage.class);
    HLClick.ClickLogin();
    Thread.sleep(5000);
    WPLoginPage VVlogin = PageFactory.initElements(driver, WPLoginPage.class);
    VVlogin.VerifyLogin(EMail, PWord);
}

    @DataProvider(name = "ExcelInput")
    public Object[][] PassData()
    {
        ReadConficFile ExcelPath=new ReadConficFile();
        ReadExcelData ReadData=new ReadExcelData(ExcelPath.GetExcelData());
        int NumRow=ReadData.GetRowCount("ValidLogin");
        Object[][] Data=new Object[NumRow][2];
        for (int i=0; i<NumRow; i++)
        {
            Data[i][0]=ReadData.Getdata("ValidLogin", i, 0);
            Data[i][1]=ReadData.Getdata("ValidLogin", i, 1);

        }
        return Data;
    }

The base class:

public class BaseClass {
    public WebDriver driver;
    @BeforeMethod
    @Parameters("OBrowser")

    public void setup(String BrowserName) throws InterruptedException {
        System.out.println("Baseclass reached");
        ReadConficFile config = new ReadConficFile();
        //driver = BrowserFactory.startBrowser(config.GetBrowser(), config.GetURL());
        driver = BrowserFactory.startBrowser(BrowserName, config.GetURL());
        Thread.sleep(5000);
    }

    @AfterMethod
    public void TearDown() throws InterruptedException {
        if (driver == null)
            return;
        driver.quit();
    }

Page Class

public class WPLoginPage {
    WebDriver driver;

    public WPLoginPage(WebDriver ldriver) {
        this.driver = ldriver;

    }

    @FindBy(xpath="//*[@id='usernameOrEmail']")
    @CacheLookup
    WebElement EmailID;
    @FindBy(xpath="//*[@id='primary']/div/main/div/div[1]/div/form/div[1]/div[2]/button")
    @CacheLookup
    WebElement ContButton;
    @FindBy(xpath="//*[@id='password']")
    @CacheLookup
    WebElement Password;
    @FindBy(xpath="//*[@id='primary']/div/main/div/div[1]/div/form/div[1]/div[2]/button")
    @CacheLookup
    WebElement LoginButton;

    @Test
    public void VerifyLogin(String EMail, String PWord) throws InterruptedException {
        EmailID.sendKeys(EMail);
        ContButton.click();
        Thread.sleep(5000);
        Password.sendKeys(PWord);
        LoginButton.click();
        Thread.sleep(10000);
    }

XML (TestNG.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite"  parallel="tests">
    <listeners>
        <listener class-name="UtilityClasses.ListenerImp">
        </listener>
    </listeners>
    <test name = "Chrome">
    <parameter name = "OBrowser" value="chrome" />
    <classes>
        <class name="TestCaseClasses.VerifyValidLogin"></class>
    </classes>
    </test>
    <test name = "firefox">
        <parameter name = "OBrowser" value="firefox" />
        <classes>
            <class name="TestCaseClasses.VerifyValidLogin"></class>
        </classes>
    </test>
</suite>

Error message:

org.openqa.selenium.ElementNotInteractableException: element not interactable
  (Session info: chrome=79.0.3945.88)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-UHPGN6M', ip: '192.168.2.30', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.88, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: C:\Users\SIVASO~1\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:65377}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 06ec100712b5a7990572a49ab097ac2a

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
    at com.sun.proxy.$Proxy11.sendKeys(Unknown Source)
    at PageClasses.WPLoginPage.VerifyLogin(WPLoginPage.java:42)
    at TestCaseClasses.VerifyValidLogin.VLogin(VerifyValidLogin.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:597)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at org.testng.TestRunner.privateRun(TestRunner.java:766)
    at org.testng.TestRunner.run(TestRunner.java:587)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
    at org.testng.SuiteRunner.access$000(SuiteRunner.java:28)
    at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:425)
    at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:68)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
SQALeaders commented 4 years ago

Please dont close without resolved. I have to create new issue again and again

krmahadevan commented 4 years ago

@SQALeaders - We can either work on getting your issue resolved by you doing what I am requesting you to do viz., provide a simple standalone example that can reproduce the problem.

But if you aren't going to provide that, and still want to keep your issue open, there's not much that can be done, but just leave the issue as is.

Duplicates https://github.com/cbeust/testng/issues/2225

SQALeaders commented 4 years ago

One page class is missing please include this for first home page login button

public class WPHomePage {
    WebDriver driver;

    public WPHomePage(WebDriver ldriver) {
        this.driver = ldriver;

    }

    @FindBy(xpath="//*[@id='lpc-header-nav']/div/div/div[1]/header/nav/ul[2]/li[1]/a")
    @CacheLookup
    WebElement Login;

    public void ClickLogin()
    {
    Login.click();

    }
SQALeaders commented 4 years ago

Also utility classes

public class ListenerImp implements ITestListener {
    @Override
    public void onStart (ITestContext results){
        System.out.println("Starts test execution "+results.getName());

    }
    @Override
    public void onFinish (ITestContext results){
        System.out.println("Finish test execution "+results.getName());

    }
    @Override
    public void onTestStart(ITestResult results){
        System.out.println("Test Started "+results.getName());
    }
    @Override
    public void onTestSkipped(ITestResult results) {
        System.out.println("Test Started " + results.getName());
    }
    @Override
    public void onTestSuccess(ITestResult results) {
        System.out.println("Test Started " + results.getName());
    }
    @Override
    public void onTestFailure(ITestResult results) {
        System.out.println("Test Started " + results.getName());
    }
    @Override
    public void onTestFailedButWithinSuccessPercentage (ITestResult results) {
        System.out.println("Test Started " + results.getName());
    }
SQALeaders commented 4 years ago
public class ReadConficFile {
    Properties Pro;

    public ReadConficFile()  {
        try {
            File Src=new File("C:\\Users\\sivasothywaran\\IdeaProjects\\FullStackDT\\Config.property");
            FileInputStream fis=new FileInputStream(Src);
            Pro = new Properties();
            Pro.load(fis);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public String GetCromePath()
    {
        //String ChromePath = Pro.getProperty("ChromeDriver");
        //return ChromePath;
        return Pro.getProperty("ChromeDriver");
    }
    public String GetGeckoPath()
    {
        //String ChromePath = Pro.getProperty("FirefoxDriver");
        //return ChromePath;
        return Pro.getProperty("FirefoxDriver");
    }
    public String GetEdgePath()
    {
        //String EdgePath = Pro.getProperty("EdgeDriver");
        //return EdgePath;
        return Pro.getProperty("EdgeDriver");
    }
    public String GetIEPath()
    {
        System.out.println("Configread reached");
        //String EdgePath = Pro.getProperty("IE");
        //return EdgePath;
        return Pro.getProperty("IEDriver");
    }
    public String GetURL()
    {
        //String url = Pro.getProperty("URL");
        //return url;
        return Pro.getProperty("URL");
    }
    public String GetBrowser()
    {
        //String url = Pro.getProperty("Browser");
        //return url;
        return Pro.getProperty("Browser");
    }
    public String GetExcelData()
    {
        return Pro.getProperty("ExcelFile");
    }
}
SQALeaders commented 4 years ago
public class ReadExcelData {
    XSSFWorkbook wb;
    XSSFSheet Sheet;
    public ReadExcelData (String ExcelPath)
    {
        try
        {
            File SRC=new File(ExcelPath);
            FileInputStream FIS=new FileInputStream(SRC);
            wb=new XSSFWorkbook(FIS);
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public String Getdata(String SheetName, int Row, int Column){
        Sheet=wb.getSheet("ValidLogin");
        String data = Sheet.getRow(Row).getCell(Column).getStringCellValue();
        return data;

    }
    public int GetRowCount(String SheetName){
        int RowCount=wb.getSheet(SheetName).getLastRowNum();
        RowCount=RowCount+1;
        return RowCount;
    }
krmahadevan commented 4 years ago

@juherr - Do you want to help explain to @SQALeaders perhaps :) ? I am not sure if what I am asking for is being accepted here!

SQALeaders commented 4 years ago

ok wait i will create another project simple

SQALeaders commented 4 years ago

I created the below code. Now I get org.testng.internal.reflect.MethodMatcherException: I couldnt pass the browser parameter. Any suggestions

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.*;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.*;

import java.io.File;
import java.io.FileInputStream;

public class RIssueSimple {

     WebDriver driver;

    @Test (dataProvider = "WPData")
    @Parameters ("OBrowser")
    public void LoginWP(String browserName, String UserName, String PWord) throws Exception {
        if (browserName.equalsIgnoreCase("firefox"))
        {
            System.setProperty("webdriver.gecko.driver", "C:\\Users\\sivasothywaran\\Desktop\\SQA\\Selenium testing\\Driver\\geckodriver.exe");
            driver=new FirefoxDriver();
        }
        else if (browserName.equalsIgnoreCase("Chrome"))
        {
            System.setProperty("webdriver.chrome.driver", "C:\\Users\\sivasothywaran\\Desktop\\SQA\\Selenium testing\\Driver\\chromedriver.exe");
            WebDriver driver = new ChromeDriver();
        }
            driver.manage().window().maximize();
            Thread.sleep(5000);
            driver.get("https://wordpress.com");
            driver.findElement(By.xpath("//*[@id='lpc-header-nav']/div/div/div[1]/header/nav/ul[2]/li[1]/a")).click();
            Thread.sleep(2000);
            driver.findElement(By.xpath("//*[@id='usernameOrEmail']")).sendKeys(UserName);
            driver.findElement(By.xpath("//*[@id='primary']/div/main/div/div[1]/div/form/div[1]/div[2]/button")).click();
            Thread.sleep(2000);
            driver.findElement(By.xpath("//*[@id='password']")).sendKeys(PWord);
            driver.findElement(By.xpath("//*[@id='primary']/div/main/div/div[1]/div/form/div[1]/div[2]/button")).click();
    }

    @DataProvider(name ="WPData")

    public Object[][] PassData() throws Exception {
            File SRC = new File("C:\\Users\\sivasothywaran\\Desktop\\SQA\\Selenium testing\\DataDriven\\ExcelFiles\\WPLoginData.xlsx");
            FileInputStream FIS = new FileInputStream(SRC);
            XSSFWorkbook wb = new XSSFWorkbook(FIS);
            XSSFSheet Sheet = wb.getSheet("ValidLogin");
            int RowCount = wb.getSheet("ValidLogin").getLastRowNum();
            RowCount = RowCount + 1;
            Object[][] Data= new Object[RowCount][2];
            for (int i = 0; i < RowCount; i++) {
                Data[i][0] = Sheet.getRow(i).getCell(0).getStringCellValue();
                Data[i][1] = Sheet.getRow(i).getCell(1).getStringCellValue();
            }
        return Data;
                }
 @AfterMethod
 public void TearDown() throws InterruptedException {
     if (driver == null)
         return;
     driver.quit();
 }

    }

TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite" parallel="tests">
    <test name = "Chrome">
        <parameter name = "OBrowser" value="chrome" />
        <classes>
            <class name="RIssueSimple"></class>
        </classes>
    </test>
    <test name = "firefox">
        <parameter name = "OBrowser" value="firefox" />
        <classes>
            <class name="RIssueSimple"></class>
        </classes>
    </test>
</suite>
krmahadevan commented 4 years ago

@SQALeaders - AFAIK you cannot combine @Parameters and data provider. Both these mechanisms are meant to be to support data driven testing. You should use only one of them. This sample that you shared still depends on a whole bunch of external things

  1. There's an excel spreadsheet involved here, about which we dont know anything.
  2. We dont know what URL are you working with.
  3. We dont know the validity of the locators that you are using.

So unless and until you can help share a sample that we can use to recreate the issue, there's not much that can be done here!

SQALeaders commented 4 years ago

Thank you for your response and time. Yes, that's why I'm not able to give you a standalone one, I cant pass both parameters, if I don't pass browser as well as excel-sheet, I can't reproduce the same scenario. Because the issue is when we do a parallel cross-browser test for the class which use data provider. Regarding the excel sheet, it's just a 2-row excel sheet as below. The first column is a user name and the last column is a password. Regarding URL its a common blog website "https://wordpress.com"

vidawaran | Vagini_10 krishna4kidsbrain | Sivagi_10

Once again the issue I have is, I can't do a parallel cross-browser test using TestNG.xml when I use data provider in my test class.

krmahadevan commented 4 years ago

@SQALeaders

Please note that even @cbeust echoes the same ask as me.

We need a sample without selenium dependency to prove that this issue is indeed a TestNG problem.

Your stack trace shows no traces of TestNG but clearly shows it to be either a test case problem or a selenium problem.

krmahadevan commented 4 years ago

Closing this issue based on this and this comment.

SQALeaders commented 4 years ago

Thank you. The reason for the issue was my browser was static. public class BrowserFactory { static WebDriver driver; public static WebDriver startBrowser(String browserName, String url) throws InterruptedException

Solution and make the browser non-static