vendredi 17 juillet 2020

TestNg Selenide. No webdriver is bound to current thread

I am setting up a project for spasuk in parallel. For more flexibility, I decided to use testng. Faced the problem that the tests do not see the web driver. Have the following error

java.lang.IllegalStateException: No webdriver is bound to current thread: 14. You need to call open(url) first.

Below are the pom file one of the test classes so that it would be clear how it is called, the method that initializes the browser and one of the suites (they are the same in structure, they just refer to different packages)

Although browser was opened.

POM.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.app</groupId>
    <artifactId>e2e-ui-cashier</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
        <junit-platform-surefire-provider.version>1.3.1</junit-platform-surefire-provider.version>
        <aspectj.version>1.8.10</aspectj.version>

        <junit.jupiter.version>5.6.2</junit.jupiter.version>
        <junit.jupiter.engine.version>5.3.1</junit.jupiter.engine.version>
        <junit.jupiter.api.version>5.4.2</junit.jupiter.api.version>

        <selenide.version>5.2.7</selenide.version>

    </properties>

    <dependencies>
        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>selenide</artifactId>
            <version>${selenide.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-selenide</artifactId>
            <version>2.12.1</version>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-path</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>xml-path</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>3.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>3.1.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.20</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.github.artsok</groupId>
            <artifactId>rerunner-jupiter</artifactId>
            <version>LATEST</version>
        </dependency>
        <dependency>
            <groupId>org.aeonbits.owner</groupId>
            <artifactId>owner</artifactId>
            <version>1.0.10</version>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.8.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.1.0</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.13.3</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                    <useSystemClassLoader>false</useSystemClassLoader>
                    <testFailureIgnore>false</testFailureIgnore>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <systemProperties>
                        <property>
                            <name>junit.jupiter.extensions.autodetection.enabled</name>
                            <value>true</value>
                        </property>
                    </systemProperties>
                    <systemPropertyVariables>
                        <propertyName>allure-results</propertyName>
                        <allure.results.directory>target/allure-results</allure.results.directory>
                        <allure.link.issue.pattern>https://arammeem.atlassian.net/browse/{}</allure.link.issue.pattern>
                    </systemPropertyVariables>
                    <properties>
                        <property>
                            <name>suitethreadpoolsize</name>
                            <value>2</value>
                        </property>
                        <property>
                            <name>parallel</name>
                            <value>suites</value>
                        </property>
                        <property>
                            <name>dataproviderthreadcount</name>
                            <value>2</value>
                        </property>

                    </properties>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/suite1.xml</suiteXmlFile>
                        <suiteXmlFile>src/test/resources/suite2.xml</suiteXmlFile>
<!--                        <suiteXmlFile>src/test/resources/suite3.xml</suiteXmlFile>-->
<!--                        <suiteXmlFile>src/test/resources/suite4.xml</suiteXmlFile>-->
                    </suiteXmlFiles>

                </configuration>
                <dependencies>
                    <!--                    <dependency>-->
                    <!--                        <groupId>org.junit.platform</groupId>-->
                    <!--                        <artifactId>junit-platform-surefire-provider</artifactId>-->
                    <!--                        <version>${junit-platform-surefire-provider.version}</version>-->
                    <!--                    </dependency>-->
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

        </plugins>
    </build>
</project>

Test class example:

// ~ Copyright © 2019 Aram Meem Company Limited. All Rights Reserved.

package pages.thread_1;

import io.qameta.allure.Description;
import io.qameta.allure.Issue;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import steps.*;
import steps.modalPagesSteps.*;
import utils.BaseTest;
import utils.annotations.Bug;
import utils.enums.OrderStatus;
import utils.enums.Settlement;

import static com.codeborne.selenide.Selenide.sleep;
import static core.TestStepLogger.logPreconditionStep;
import static core.TestStepLogger.logStep;
import static steps.HelperSteps.openSecondTab;
import static steps.HelperSteps.resizeBrowserWindow;
import static utils.enums.Locale.AR;
import static utils.enums.Locale.EN;
import static utils.enums.Localization.VALID_NUMBER;
import static utils.enums.NotificationMessages.MERCHANT_ORDER_REFERENCE_ALREADY_IN_USE;
import static utils.enums.PageTitles.*;


public class BookADeliveryOrdersTest extends BaseTest {

    @BeforeMethod(alwaysRun=true)
    public void goToLoginPage() {
        logPreconditionStep(1, "Open 'Login' page");
        configure();

        logPreconditionStep(2, "Check that 'email' and 'password' placeholders are displayed");
        loginPageSteps.checkThatEmailAndPasswordPlaceholdersAreDisplayed();

        logPreconditionStep(3, "Enter valid credentials");
        loginPageSteps.enterValidCredentials(merUser2);

        logPreconditionStep(4, "Press 'OK' on the Warning notification");
        warningModalPageSteps.checkThatSoundNotificationWarningIsDisplayedAndClickOk();

        logPreconditionStep(5, "Check that 'NEW ORDERS' title appears");
        titlePageSteps.pageTitleShouldHaveText(MAIN);
    }

    @Test
    @Description("Orders creation functionality verification")
    public void ordersCreationFunctionalityVerification() {
        logStep(1, "Switch POS to " + pos1.getName());
        headerPageSteps.setAndCheckPOS(pos1);

        logStep(2, "Go to 'BOOK A DELIVERY' page");
        mainPageSteps.clickBookADeliveryButton();
        titlePageSteps.pageTitleShouldHaveText(BOOK_A_DELIVERY);

        logStep(3, "Fill all mandatory fields");
        bookADeliveryPageSteps.fillAllMandatoryFields();

        logStep(4, "Press 'Book order' button");
        bookADeliveryPageSteps.clickBtnDeliveryOrder();

        logStep(5, "Click 'Confirm order' button");
        confirmOrderModalPageStep.clickConfirmOrderBtn();

        logStep(6, "Check confirmation message");
        notificationModalPageSteps.createOrderMessageShouldBeEnglishDisplayed();
    }
}

Configuration:


        public void configure() {
        System.setProperty("selenide.browser", "chrome");

        ChromeDriverManager.chromedriver().version(testProp.chromeDriverVersion()).setup();

        SelenideLogger.addListener(testProp.selenideListener(), new AllureSelenide().screenshots(true).savePageSource(false));

        System.out.println("DDDDDDDDDDDDDDDDDDDDDDDD");

        Configuration.browserSize = testProp.browserSize();

        Configuration.timeout = testProp.timeout();

        Configuration.headless = testProp.headless();

        clearBrowserCache();

        BASE_LOCALE = Locale.EN;

        Selenide.open(testCred.BASE_URL());
    }

One of the suites:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<!--        verbose="1" parallel="false"-->
<suite name="Suite1" parallel="tests" verbose="2">
<test name="Regression1" >
<packages>
<package name="pages.thread_1"></package>
 </packages>
</test>
</suite>

Aucun commentaire:

Enregistrer un commentaire