简体   繁体   English

BDD Gherkin Selenium Java - 错误疑难解答

[英]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.当我尝试将它作为 maven 测试运行时出现以下提到的错误,请帮助这是我第一次尝试进入 BDD 的东西,代码中有什么问题。 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.以下是该项目的 POM - 非常感谢您的回复。 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.我被困住了:(请帮忙。我已经尝试了几乎所有似乎都无法解决的问题。我是 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>

I tried this and it's works:我试过这个,它的工作原理:

<?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>groupId</groupId>
    <artifactId>CucumberBasic</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.2.3</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.2.3</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>

it seems like some jar file is corrupted.似乎某些 jar 文件已损坏。 This is not the best solution but might work from you.这不是最好的解决方案,但可能对您有用。 Please delete all the files under following folder and re-download them using maven.请删除以下文件夹下的所有文件,然后使用maven重新下载。

For windows窗户用

C:\Users\<username>\.m2\repository folder

for linux用于 linux

/home/egnyte/.m2/repository

To download again you can right click on your project on your favourtie IDE and there you can find the option.要再次下载,您可以在您喜欢的 IDE 上右键单击您的项目,在那里您可以找到该选项。 you you can use command line and run你可以使用命令行并运行

mvn clean test

Use the same version for cucumber-junit and cucumber-java (1.2.5).对 Cucumber-junit 和 Cucumber-java (1.2.5) 使用相同的版本。 The version 1.1.2 is from 30-Jan-2013. 1.1.2 版本来自 2013 年 1 月 30 日。

Update: Your test.java class is located at src/main/java .更新:您的test.java类位于src/main/java However your dependencies are set to scope test .但是,您的依赖项设置为范围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.因此,当您的 Maven 项目尝试编译test.java类时,它的类路径中没有所需的类。

So move your test.java class into the src/test/java folder and try again.因此,将您的test.java类移动到src/test/java文件夹中,然后再试一次。 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您还可以查看我的示例项目,其中显示了使用大多数 BDD 框架来检查哪个文件或类所在的最小设置: https : //github.com/mszalbach/BDD/tree/master/cucumber

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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