【发布时间】:2017-06-27 06:41:26
【问题描述】:
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();
}
}
当我尝试将它作为 maven 测试运行时遇到以下提到的错误,请帮助这是我第一次尝试进入 BDD 内容,代码有什么问题。请建议我能做些什么来解决这个问题,它一直困扰着我!
[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
以下是该项目的 POM - 非常感谢您的回复。我被困住了:(请帮忙。我已经尝试了几乎所有方法似乎都无法弄清楚。我是 Selenium 和 bdd 的新手,所以想学习。非常感谢您的回复。
<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>
【问题讨论】:
-
你能把maven依赖部分也贴在这里
-
添加了兄弟,非常感谢您的帮助,非常感谢
-
嗨,谁能帮我解决这个问题。如果需要更多信息,请告诉我。
-
有人可以调查一下吗?
-
请大家帮忙。
标签: java maven selenium bdd gherkin