2

I have tried to code cucumber parallel execution of feature file, but there is an error printed out on console like this:

[TestNG-PoolService-0] ERROR com.nicholas.StepsDef.ExportProduct - java.lang.NullPointerException

Element info: {Using=xpath, value=//a[@class='log-wrapper']/child::img}
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    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.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
    at com.nicholas.StepsDef.AddProduct.navigateToManageProduct(AddProduct.java:65)
    at ✽.navigate to manage product(file:///C:/Users/nicholaswkc/IdeaProjects/cucumber-java-skeleton/src/test/resources/Features/AddProduct.feature:7)

05:38:22.730 [TestNG-PoolService-0] ERROR com.nicholas.StepsDef.ExportProduct - java.lang.NullPointerException
05:38:22.780 [TestNG-PoolService-0] ERROR com.nicholas.StepsDef.AddProduct - org.openqa.selenium.NoSuchSessionException: invalid session id

AddProductPageObject.java

public By lazadaLogo = By.xpath("//a[@class='log-wrapper']/child::img");

AddProduct.java

public class AddProduct {

    private AddProductPageObject page;
    private ChromeDriver driver;
    private Logger log = LogManager.getLogger(AddProduct.class);
    // ======================================================================
    public AddProduct() {
    }

    @Given("Launch the homepage and login")
    public void launchTheHomepageAndLogin() {
        log.info("Start Login");
        try {
            WebDriverManager.chromedriver().setup();
            driver =  new ChromeDriver();
            WebDriverWait timeWait = new WebDriverWait(driver, 30);
            page = PageFactory.initElements(driver, AddProductPageObject.class);
            driver.navigate().to("https://sellercenter.lazada.com.my/apps/seller/login");
            timeWait.until(ExpectedConditions.visibilityOfElementLocated(page.getLazadaSellerLogo()));

            // Input username
            driver.findElement(page.getUsername()).click();
            driver.findElement(page.getUsername()).clear();
            driver.findElement(page.getUsername()).sendKeys("nicholaswkc34@gmail.com");

            // Input password
            driver.findElement(page.getPassword()).click();
            driver.findElement(page.getPassword()).clear();
            driver.findElement(page.getPassword()).sendKeys("wlx_+279295");

            // Click submit btn
            driver.findElement(page.getSignInButton()).click();

            //assertThat(page.getPageTitle()).isEqualto("");

            Wait wait = new Wait();
            wait.implicitWait(driver, 5);

        } catch (Exception e) {
            log.error(e);
        }
    }

    @Given("navigate to manage product")
    public void navigateToManageProduct() {
        WebDriverWait waitProductLink = new WebDriverWait(driver, 30);
        waitProductLink.until(ExpectedConditions.visibilityOfElementLocated(page.getLazadaLogo()));
        driver.findElement(page.getProductLink()).click();

        WebDriverWait waitManagedProductLink = new WebDriverWait(driver, 30);
        waitManagedProductLink.until(ExpectedConditions.visibilityOfElementLocated(page.getManageProductLink()));
        driver.findElement(page.getManageProductLink()).click();
    }

Moreover, when I run using mvn command it pops out org.testng.xml.XmlSuite.setParallel(Ljava/lang/String;)which is highlighted on this group

Questions:

  1. What is causing the error?
  2. When maven surefire plugin error should fix?
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
nicholas
  • 2,581
  • 14
  • 66
  • 104
  • WHy vote close? This is a real error that i encounter. – nicholas Jul 10 '21 at 20:45
  • I really need help. Please help me on this software bug. – nicholas Jul 12 '21 at 08:54
  • your output also shows "org.openqa.selenium.NoSuchSessionException: invalid session id". This may be an indicator that your chrome driver version is not compatible with the version of your chrome browser. The following link may help to verify compatiblity: https://sites.google.com/a/chromium.org/chromedriver/downloads/version-selection – rmunge Jul 12 '21 at 15:24

2 Answers2

2

I have seen an error occurred at "at com.nicholas.StepsDef.AddProduct.navigateToManageProduct(AddProduct.java:65)", method- page.getLazadaLogo().

I assume a driver object holds null while creating WebDriverWait waitProductLink = new WebDriverWait(driver, 30); object. Generally, WebDriverWait accepts null in its constructor parameter, but it throws error at run time when we tried to use that wait object created using null.

Solutions:

  1. Check what driver holds in step 'navigate to manage product' implementation. Scope of "Launch the homepage and login" driver assignment specific to that particular block. To overcome this issue, make driver variable as static and assign driver object reference to it in step- "Launch the homepage and login" implementation.

  2. In case these two steps run in parallel, then you need to create driver object inside step "navigate to manage product" implementation also.

Sreenivasulu
  • 494
  • 2
  • 7
  • It is this line of code that cause an error waitProductLink.until(ExpectedConditions.visibilityOfElementLocated(page.getLazadaLogo()));. I had debug it but the driver is not null. How come this statement throw NotSuchExceptionFound. I have declare the the ChromeDriver as static as well. – nicholas Jul 12 '21 at 20:11
  • All my another method throw NoSuchSessionException. Why is like that. I had declare the driver as private in class scope? The driver session should be accessible for any methods in the class. Why need to create another driver object in another method in the class? – nicholas Jul 12 '21 at 20:18
  • I tried to add another driver1 in navigatetToManageProduct but it still failed. Please help me. Thanks. – nicholas Jul 12 '21 at 20:31
  • I found out that it is the expected wait condition that throw exception and not the driver is null. – nicholas Jul 12 '21 at 20:31
  • That's grat @nicholas – Sreenivasulu Jul 13 '21 at 09:00
  • I still unable to solve it. Don't know why wait condition throw exception. – nicholas Jul 13 '21 at 20:27
  • It throws NoSuchSessionException. – nicholas Jul 13 '21 at 22:17
0

Solve it by moving the init code to @Before method.

nicholas
  • 2,581
  • 14
  • 66
  • 104