Search code examples
eclipseselenium-webdrivercucumber

New to Cucumber - Problem trying to get simple setup working


I have worked with Cucumber previously, but in an environment that was already setup, at work.

I am now trying to get an Eclipse/Maven/Cucumber/Junit environment setup on my own computer.

So I created a Maven project and used one of the archetypes that were listed, "cucumber-java-junit-archetype", just to get something simple working, and I eventually got it working earlier.

So next I wanted to try to add some steps that use WebDriver, and I found this:

https://www.browserstack.com/guide/automation-using-cucumber-selenium

So I added a new class for that example, and then in the pom.xml I added:

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

but, when I try to build the project, I am getting:

[ERROR] Failed to execute goal [32morg.apache.maven.plugins:maven-compiler-plugin:3.5.1:testCompile[m [1m(default-testCompile)[m on project [36mCucumberProject[m: [1;31mCompilation failure[m
[ERROR] [1;31m/E:/Eclipse-Cucumber-workspace/CucumberProject/src/test/java/FirstCucumber/CucumberProject/Steps.java:[5,27] cannot access org.openqa.selenium.By[m
[ERROR] [1;31m  bad class file: C:\Users\jl1\.m2\repository\org\seleniumhq\selenium\selenium-api\4.22.0\selenium-api-4.22.0.jar(org/openqa/selenium/By.class)[m
[ERROR] [1;31m    class file has wrong version 55.0, should be 52.0[m
[ERROR] [1;31m    Please remove or make sure it appears in the correct subdirectory of the classpath.

Also, FYI, here is my current pom.xml:

<?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>FirstCucumber</groupId>
<artifactId>CucumberProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Cucumber-Java-JUnit Project</name>

<properties>
    <cucumber.version>1.2.4</cucumber.version>
    <java.version>1.8</java.version>
    <selenium.version>4.22.0</selenium.version>
</properties>

<dependencies>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>


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



</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <compilerArgument>-Werror</compilerArgument>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

I think that maybe the cucumber version that I am using is not compatible with the selenium version? I haven't been able to find any specific version recommendation, but I don't think just trying every combination seems like a good idea :( !!

Can someone help and tell me how I can get past that build error?

Thanks!!

Jim

EDIT 1: I found this page and it shows:

    <!-- Dependency versions -->
<cucumber.version>1.2.4</cucumber.version>
<selenium.version>2.48.0</selenium.version>
</properties>

So I tried that, but now I am getting a different error:

Caused by: org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: XP
Build info: version: '2.48.0', revision: 'b7b081a4f1289f17e8ecd38bc67e137c2a12e34a', time: '2015-10-07 09:50:14'
 System info: host: 'VOS', ip: '10.0.0.51', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:75)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at FirstCucumber.CucumberProject.Steps.<init>(Steps.java:19)
... 38 more

EDIT 2: I made some progress - I added path for the firefox.exe to the Windows PATH and then bounced Eclipse, and when I test after that I am getting a different error:

Build info: version: '2.48.0', revision: 'b7b081a4f1289f17e8ecd38bc67e137c2a12e34a', time: '2015-10-07 09:50:14'
System info: host: 'VOS', ip: '10.0.0.51', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_202'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:135)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:117)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at FirstCucumber.CucumberProject.Steps.<init>(Steps.java:19)
... 36 more
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:

at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:123)
... 43 more

It seems like cucumber/selenium is trying to connect to the firefox.exe on port 7055 on localhost but it isn't able to connect?

I tried opening up the port 7055 in the Windows firewall but the same thing happened.

I am not sure what to do now :( ....


Solution

  • You took a wrong turn solving your problem after you got the error about class file has wrong version 55.0, should be 52.0.

    This means that you are currently using Java 8 which supports up to class file version 52.0. Selenium expects that you use at least Java 11 (class file version 55.0). So you should ensure that the version of Java you use to run and compile your project is at least 11.

    Additionally, you are using Cucumber v1. Cucumber v1 does not work with any version above Java 8. The latest version of Cucumber is v7 and works with Java 8 and any higher version.

    To get started, try getting the latest version of Cucumber to work by following the 10-minute tutorial or by copying the skeleton project. Then afterwards you can try to add Selenium into the project. Remember to use at least Java 11 when you do.

    You will then still have to fix the connection problem between Selenium and your Firefox driver, but that will be easier to solve if you use the latest version of Selenium and the Firefox driver.