testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.99k 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 #2225

Closed SQALeaders closed 4 years ago

SQALeaders commented 4 years ago

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?

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

I didnt give the TestNG XML here you go

<?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>
krmahadevan commented 4 years ago

@SQALeaders - Please help create a simple standalone (which doesn't require selenium WebDriver) test that can be used to reproduce the problem. It's not clear as to what is the issue here. Its not going to be possible for us to debug your selenium issue (It looks like a genuine Selenium problem)

krmahadevan commented 4 years ago

Please comment once you have a simple standalone example. Closing this issue

SQALeaders commented 4 years ago

Please dont close any issues before getting clear detail

SQALeaders commented 4 years ago

This is not a selenium issue. Please note if I don't use DataProvider Parallel test works fine. The issue happens when I use data provider. I don't understand why you ask me to create simple standalone. Please keep it open so if some one knows they will answer. Dont close any issue without resolving I dont understand why you guys close in 20 minutes.

krmahadevan commented 4 years ago

@SQALeaders -

Please note if I don't use DataProvider Parallel test works fine. The issue happens when I use data provider.

There are a lot of tests within the TestNG codebase as unit tests that tests out various aspects of data provider and there have been no failures on any of them.

I don't understand why you ask me to create simple standalone.

How else do you expect someone to reproduce the problem ?

Please keep it open so if some one knows they will answer.

I am one of the committers of the codebase. Not sure who are you expecting here to answer.

Dont close any issue without resolving

There is nothing in this issue that can pinpoint the problem to TestNG.

I am re-iterating, please share a simple standalone test sample that can be used to reproduce the problem. Once that is done, I dont have any issues in re-opening the issue and fixing it if there is a problem with TestNG. I will be more than happy to do that. But without a sample, there's no point in keeping an issue open.

SQALeaders commented 4 years ago

I already gave a full code to reproduce

krmahadevan commented 4 years ago

@SQALeaders - Do you want to help me understand as to how do I execute that test ? The html page against which that selenium test is created is not available.

The code that you shared cannot be executed on its own. I am re-iterating once again.

Please provide a simple standalone example (That does not use anything apart from TestNG) to reproduce the problem.

cbeust commented 4 years ago

Echoing what @krmahadevan said: please provide a problem statement without Selenium.

Thanks.

SQALeaders commented 4 years ago

I don't understand what is the problem statement and how to give without selenium. If you need a concise description of a problem then go through the below What I am trying to achieve is a parallel cross-browser test using TestNG.xml file, when the class given in TestNG.xml file has DataProvider method. Expected behaviour: WHen dataprovider loop each data, each of them have to go to each browser. example if I have two data in my excell file both data should pass to each browser Actual behaviour is Both browser get launch same time which is right but first data goes to chrome browser and second data goes to Firefox browser. So chrome browser doest get second data to login second time. Other hand Fire browser get login with second set of login cresentail and doesnt use the first credentials from Excel sheet.

SQALeaders commented 4 years ago

Also please note if you are fixing, we need this behavior when we testing the login scenario for cross-browser testing. Because the same credentials can't be used for all the browsers, so the first browser should take the first set of data from the data provider and the second browser should get the second credential and so on. In that case, this behavior is expected behavior, I mean the right behavior. I dont know which gets priority.

SQALeaders commented 4 years ago

You can close this, I believe two sessions cant have one login credential, might be browser blocking this

krmahadevan commented 4 years ago

@SQALeaders - This issue was already closed. But you went ahead and opened another duplicate of the same thing, because

  1. You had concerns that the issue got closed within 20 mins (I had to do it, when I didn't see any sign of TestNG being the cause of the problem and the sample is not usable to reproduce)
  2. You felt that maybe opening up a new issue with the same problem will get the attention of someone else (I think what you are looking for is user support and not resolution of a bug, because we are yet to see a demonstration sample that can reproduce the issue). You should be posting this query on selenium-users@googlegroups.com

So please go ahead and close off https://github.com/cbeust/testng/issues/2226. You are free to create a new issue and comment and ask for either of these 2 issues re-opened, once you have a sample that can reproduce the problem using only TestNG and nothing else.

cbeust commented 4 years ago

You can close this, I believe two sessions cant have one login credential, might be browser blocking this

And this is exactly why we've been asking you to provide a reproducible test case without Selenium.

Because as long as your problem statement includes Selenium, we cannot be sure whether it's a TestNG or a Selenium bug.

And maybe it's not a bug at all.