简体   繁体   中英

Selenide Test fails with org/openqa/selenium/NoSuchSessionException

I am trying to write a selenium E2E test case using Selenide and testng, in a mvn project. It is my first basic testcase, where i try to open a link. But, I see below error when i run the test with Idea intellij :

TestNG] Running:
/Users/Prajakta_Mahamuni/Library/Caches/IntelliJIdea2019.2/temp-testng-customsuite.xml
java.lang.NoClassDefFoundError: org/openqa/selenium/NoSuchSessionException
at com.codeborne.selenide.impl.WebDriverThreadLocalContainer.<init>(WebDriverThreadLocalContainer.java:39)

Here is my test case:

package com.symantec.epmp.scsem.web.management.controllers;

import org.testng.annotations.Test;
import static com.codeborne.selenide.Selenide.*;

public class ConsoleITTest {

    @Test
    public void mdrLogin() {

        open("https://www.google.com");

    }

}

And pom.xml:

<dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.141.59</version>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>xerces</groupId>
                        <artifactId>xercesImpl</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-api</artifactId>
                <version>2.42.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.webdriver</groupId>
                <artifactId>webdriver-selenium</artifactId>
                <version>0.9.7376</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-core</artifactId>
                <version>2.0.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-chrome-driver</artifactId>
                <version>2.42.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-firefox-driver</artifactId>
                <version>2.42.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-ie-driver</artifactId>
                <version>2.42.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-safari-driver</artifactId>
                <version>2.42.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.codeborne</groupId>
                <artifactId>selenide</artifactId>
                <version>5.10.0</version>
                <scope>test</scope>
            </dependency>

I see the reason for this error is dependency on selenium-java, however it is present in the project. What could be the reason that the Test fails to run.

I think this is due to selenium-api. It is still pointing to old version 2.42.0. Also check your other drivers too and if you faced same issue then please update them according to browser which you prefer for your execution

Please refer below POm file which I am using which is working fine for me.

<properties>
        <java.version>1.8</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <selenium.hub.url>http://local.example.com:4444/wd/hub</selenium.hub.url>
    <browser>firefox</browser>
    <holdBrowserOpen>false</holdBrowserOpen>
    <webdriver.gecko.driver>${user.home}/bin/geckodriver</webdriver.gecko.driver>
    <webdriver.chrome.driver>${user.home}/bin/chromedriver</webdriver.chrome.driver>
    <surefire.argLine></surefire.argLine>
    <selenium.version>3.0.1</selenium.version>
    <selenide.version>4.0</selenide.version>
</properties>

<prerequisites>
    <maven>3.3</maven>
</prerequisites>

<profiles>
    <profile>
        <id>firefox</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <browser>firefox</browser>
        </properties>
    </profile>
    <profile>
        <id>chrome</id>
        <properties>
            <browser>chrome</browser>
        </properties>
    </profile>
    <profile>
        <id>phantomjs</id>
        <properties>
            <browser>phantomjs</browser>
        </properties>
    </profile>
    <profile>
        <id>ie</id>
        <properties>
            <browser>ie</browser>
        </properties>
    </profile>
    <profile>
        <id>safari</id>
        <properties>
            <browser>safari</browser>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-safari-driver</artifactId>
                <version>${selenium.version}</version>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>htmlunit</id>
        <properties>
            <browser>htmlunit</browser>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-htmlunit-driver</artifactId>
                <version>LATEST</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>ci-server</id>
        <properties>
            <surefire.argLine>-Dremote=${selenium.hub.url}</surefire.argLine>
        </properties>
    </profile>
    <profile>
        <id>local</id>
        <properties>
            <holdBrowserOpen>true</holdBrowserOpen>
        </properties>
    </profile>
</profiles>

<build>
    <defaultGoal>clean test</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <detail>true</detail>
                <forkCount>1C</forkCount>
                <reuseForks>true</reuseForks>
                <systemPropertyVariables>
                    <browser>${browser}</browser>
                    <holdBrowserOpen>${holdBrowserOpen}</holdBrowserOpen>
                    <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                    <webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
                </systemPropertyVariables>
                <argLine>${surefire.argLine}</argLine>
            </configuration>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.13</version>
    </dependency>
    <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>selenide</artifactId>
        <version>${selenide.version}</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM