簡體   English   中英

硒黃瓜功能文件未在Eclipse中啟用

[英]Selenium Cucumber Feature File is Not Enabling in Eclipse

我已經嘗試用Testng maven運行Cucumber BDD Framework,並且我已經完成了安裝程序的所有配置,但是問題是Cucumber的功能文件未啟用。 下,我將發布我的代碼和pom.xml,請指導我在哪里錯過了什么。 :(

我的跑步課程代碼:

package org.cucumber.MRtests;

import io.github.bonigarcia.wdm.WebDriverManager;

import org.junit.BeforeClass;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.CucumberFeatureWrapper;
import cucumber.api.testng.TestNGCucumberRunner;


@CucumberOptions(features="src/test/resources/Features",glue={"org.cucumber.stepdefs"})
public class OpenMRTest 
{
    public static WebDriver driver;
    private TestNGCucumberRunner testRunner;


    @BeforeClass
    public void Setup()
    {
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
        testRunner = new TestNGCucumberRunner(OpenMRTest.class);
    }

    @Test(description="login",dataProvider="features")
    public void login(CucumberFeatureWrapper cFeature)
    {
        testRunner.runCucumber(cFeature.getCucumberFeature());
    }

    @DataProvider(name="features")
    public Object[][] getFeatures()
    {
        return testRunner.provideFeatures();
    }
    @AfterClass
    public void tearDown()
    {
        testRunner.finish();
    }

}

我的聲明代碼:

package org.cucumber.stepdefs;


import org.cucumber.MRtests.OpenMRTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Sleeper;
import org.testng.Assert;

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


public class LoginPage  
{
    @Given("^Open Application and Enter url$")
    public void open_Application_and_Enter_url() throws Throwable {
      OpenMRTest.driver.get("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");

    }

    @When("^enter username$")
    public void enter_username() throws Throwable {

        OpenMRTest.driver.findElement(By.xpath("//a[text()='Log In']")).click();
        Sleep(5000);
        OpenMRTest.driver.findElement(By.id("email")).sendKeys("xxxxxxxxxxxxxxx");
    }

    private void Sleep(int i) throws InterruptedException {
        Thread.sleep(i);

    }

    @When("^enter password$")
    public void enter_password() throws Throwable {
        OpenMRTest.driver.findElement(By.id("password")).sendKeys("xxxxxxxxxxxxxxxxxx");
        OpenMRTest.driver.findElement(By.xpath("//button[@id='submit-button']")).click();
    }

    @Then("^verify Msg$")
    public void verify_Msg() throws Throwable {
       boolean result =  OpenMRTest.driver.findElement(By.xpath("//div[@class='grid']/h1")).getText().contains("Top Questions");
       Assert.assertTrue(result);
    }
}

我的POM.XML文件:

<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>BDDFramework</groupId>
  <artifactId>BDDFramework</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>BDD</name>

<properties>
<suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
</properties>



<dependencies>

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.3</version>
    <scope>test</scope>
</dependency>

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

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>


<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>

</dependency>


<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>3.0.0</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>1.2.5</version>
</dependency>




</dependencies>

  <build>
    <defaultGoal>install</defaultGoal>
  <plugins>

  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    </plugin>

    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>

    <configuration>

    <suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
    </configuration>
      </plugin>

  </plugins>
  </build>
</project>

而且我還附上了功能文件的外觀。 請引導我解決此問題。

在此處輸入圖片說明

例外是::

[INFO] Running TestSuite
[Utils] [ERROR] [Error] java.lang.NullPointerException
    at org.cucumber.MRtests.OpenMRTest.getFeatures(OpenMRTest.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
    at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45)
    at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:131)
    at org.testng.internal.Parameters.handleParameters(Parameters.java:706)
    at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:49)
    at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:37)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:924)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:283)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:120)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
    at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)

[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 1, Time elapsed: 0.591 s <<< FAILURE! - in TestSuite
[ERROR] tearDown(org.cucumber.MRtests.OpenMRTest)  Time elapsed: 0.448 s  <<< FAILURE!
java.lang.NullPointerException
    at org.cucumber.MRtests.OpenMRTest.tearDown(OpenMRTest.java:46)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   OpenMRTest.tearDown:46 NullPointer
[INFO] 
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

@DataProvider方法是第一個運行的方法,位於@BeforeClass之前。 這意味着testRunner仍然為null 將初始化從Setup()移到getFeatures()

@DataProvider(name="features")
public Object[][] getFeatures()
{
    testRunner = new TestNGCucumberRunner(OpenMRTest.class);
    return testRunner.provideFeatures();
}

我認為您不是Eclipse中的插件黃瓜

請安裝Cucumber Eclipse插件

1)啟動Eclipse IDE,然后從“幫助”菜單中單擊“安裝新軟件”。

在此處輸入圖片說明

2)您將看到一個對話框窗口,單擊“添加”按鈕。

在此處輸入圖片說明

3)根據需要輸入名稱,讓我們以“ Cucumber”作為輸入,然后輸入“ http://cucumber.github.com/cucumber-eclipse/update-site ”。 單擊確定。

在此處輸入圖片說明

4)您返回上一個窗口,但是這次您必須在可用軟件列表中看到Cucumber Eclipse Plugin選項。 只需選中此框,然后按“下一步”按鈕即可。

在此處輸入圖片說明

5)單擊下一步。

在此處輸入圖片說明

6)單擊“我接受許可協議的條款”,然后單擊“完成”。

在此處輸入圖片說明

7)安裝完畢,將花費幾秒鍾的時間。

在此處輸入圖片說明

8)如果您確實單擊“確定”,則可能會遇到安全警告,也可能不會遇到。

在此處輸入圖片說明

9)現在就完成了,只需單擊“是”。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM