Avinash Pandey Avinash Pandey - 29 days ago 13
Java Question

BDD Gherkin Selenium Java - Error Trouble shooting

package cucumberselelniumgherkin;


import java.util.concurrent.TimeUnit;

import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class test {


public WebDriver driver;

@Before
public void setup() {
driver = new FirefoxDriver();
}

@Given("^I open google$")
public void I_open_google() {
//Set implicit wait of 10 seconds and launch google
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://www.google.co.in");
}

@When("^I enter \"([^\"]*)\" in search textbox$")
public void I_enter_in_search_textbox(String additionTerms) {
//Write term in google textbox
WebElement googleTextBox = driver.findElement(By.id("gbqfq"));
googleTextBox.sendKeys(additionTerms);

//Click on searchButton
WebElement searchButton = driver.findElement(By.id("gbqfb"));
searchButton.click();
}

@Then("^I should get result as \"([^\"]*)\"$")
public void I_should_get_correct_result(String expectedResult) {
//Get result from calculator
WebElement calculatorTextBox = driver.findElement(By.id("cwos"));
String result = calculatorTextBox.getText();

//Verify that result of 2+2 is 4
Assert.assertEquals(result, expectedResult);

driver.close();
}

@After
public void closeBrowser() {
driver.quit();
}

}


When I am trying to run it as maven test getting the below mentioned error, please help this is my first attempt in getting into BDD stuff, whats wrong in the code. Please suggest what can i do to fix this its been bothering my mind so much !

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building bddSel 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-api/maven-metadata.xml
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-api/maven-metadata.xml (3 KB at 1.3 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-support/maven-metadata.xml
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-support/maven-metadata.xml (4 KB at 6.7 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/info/cukes/cucumber-junit/1.2.5/cucumber-junit-1.2.5.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/info/cukes/cucumber-junit/1.2.5/cucumber-junit-1.2.5.pom (3 KB at 5.3 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/info/cukes/cucumber-junit/1.2.5/cucumber-junit-1.2.5.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/info/cukes/cucumber-junit/1.2.5/cucumber-junit-1.2.5.jar (22 KB at 27.4 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ bddSel ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\workspace\bddSel\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ bddSel ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to E:\workspace\bddSel\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error reading C:\Users\Avinash\.m2\repository\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar; invalid LOC header (bad signature)
[ERROR] error reading C:\Users\Avinash\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.22\cssparser-0.9.22.jar; invalid LOC header (bad signature)
[ERROR] error reading C:\Users\Avinash\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.26\htmlunit-2.26.jar; invalid CEN header (bad signature)
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[6,17] package org.junit does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[12,25] package cucumber.api.java does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[13,25] package cucumber.api.java does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[14,28] package cucumber.api.java.en does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[15,28] package cucumber.api.java.en does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[16,28] package cucumber.api.java.en does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[23,11] cannot find symbol
symbol: class Before
location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[28,10] cannot find symbol
symbol: class Given
location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[35,10] cannot find symbol
symbol: class When
location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[46,10] cannot find symbol
symbol: class Then
location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[58,11] cannot find symbol
symbol: class After
location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[53,17] cannot find symbol
symbol: variable Assert
location: class cucumberselelniumgherkin.test
[INFO] 15 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.233 s
[INFO] Finished at: 2017-07-05T09:45:37+10:00
[INFO] Final Memory: 19M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project bddSel: Compilation failure: Compilation failure:
[ERROR] error reading C:\Users\Avinash\.m2\repository\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar; invalid LOC header (bad signature)
[ERROR] error reading C:\Users\Avinash\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.22\cssparser-0.9.22.jar; invalid LOC header (bad signature)
[ERROR] error reading C:\Users\Avinash\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.26\htmlunit-2.26.jar; invalid CEN header (bad signature)
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[6,17] package org.junit does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[12,25] package cucumber.api.java does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[13,25] package cucumber.api.java does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[14,28] package cucumber.api.java.en does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[15,28] package cucumber.api.java.en does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[16,28] package cucumber.api.java.en does not exist
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[23,11] cannot find symbol
[ERROR] symbol: class Before
[ERROR] location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[28,10] cannot find symbol
[ERROR] symbol: class Given
[ERROR] location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[35,10] cannot find symbol
[ERROR] symbol: class When
[ERROR] location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[46,10] cannot find symbol
[ERROR] symbol: class Then
[ERROR] location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[58,11] cannot find symbol
[ERROR] symbol: class After
[ERROR] location: class cucumberselelniumgherkin.test
[ERROR] /E:/workspace/bddSel/src/main/java/cucumberselelniumgherkin/test.java:[53,17] cannot find symbol
[ERROR] symbol: variable Assert
[ERROR] location: class cucumberselelniumgherkin.test
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException


Below is the POM from the project - Thank you so much for your reply. I am so stuck :( help please. I have tried almost everything cant seem to figure it out. I am new to Selenium and bdd so trying to learn. So grateful for your response.

<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>CucumberJavaProject</groupId>
<artifactId>bddSel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<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>3.4.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Answer Source

Use the same version for cucumber-junit and cucumber-java (1.2.5). The version 1.1.2 is from 30-Jan-2013.

Update: Your test.java class is located at src/main/java. However your dependencies are set to scope test. This means they are only used for test compilation and execution. So when your maven project tries to compile the test.java class it did not have the needed classes in the classpath.

So move your test.java class into the src/test/java folder and try again. You can also check my example project which shows the minimal setup to use most BDD frameworks to check where which file or class is located: https://github.com/mszalbach/BDD/tree/master/cucumber