并行执行功能文件会导致控制台上打印机出现空指针异常

1cklez4t  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(247)

我曾尝试过为功能文件的并行执行编写代码,但控制台上出现如下错误:

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

此外,当我使用mvn命令运行时,它会弹出 org.testng.xml.XmlSuite.setParallel(Ljava/lang/String;)V 该组中突出显示了哪一项
问题:
错误的原因是什么?
maven surefire插件错误应该何时修复?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题