简体   繁体   English

硒黄瓜功能文件未在Eclipse中启用

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

i Have Try to run the Cucumber BDD Framework with Testng maven and i have done all the configurations to the setup but the problem is the feature file of Cucumber is not enabling. 我已经尝试用Testng maven运行Cucumber BDD Framework,并且我已经完成了安装程序的所有配置,但是问题是Cucumber的功能文件未启用。 down i will post my code and pom.xml please guide me where and what i missed. 下,我将发布我的代码和pom.xml,请指导我在哪里错过了什么。 :( :(

My Code for the runner class: 我的跑步课程代码:

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();
    }

}

My Code for the Declaring part: 我的声明代码:

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);
    }
}

My POM.XML File : 我的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>

and Also i have attached the feature file how it is Looking. 而且我还附上了功能文件的外观。 please guide me through this issue. 请引导我解决此问题。

在此处输入图片说明

Exception is :: 例外是::

[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 method is the first to run, before @BeforeClass . @DataProvider方法是第一个运行的方法,位于@BeforeClass之前。 That means testRunner is still null . 这意味着testRunner仍然为null Move the initialization from Setup() to getFeatures() 将初始化从Setup()移到getFeatures()

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

I think you are not plugin cucumber in Eclipse 我认为您不是Eclipse中的插件黄瓜

Please Install Cucumber Eclipse plugin 请安装Cucumber Eclipse插件

1) Launch the Eclipse IDE and from Help menu, click "Install New Software". 1)启动Eclipse IDE,然后从“帮助”菜单中单击“安装新软件”。

在此处输入图片说明

2) You will see a dialog window, click "Add" button. 2)您将看到一个对话框窗口,单击“添加”按钮。

在此处输入图片说明

3) Type name as you wish, let's take "Cucumber" and type " http://cucumber.github.com/cucumber-eclipse/update-site " as location. 3)根据需要输入名称,让我们以“ Cucumber”作为输入,然后输入“ http://cucumber.github.com/cucumber-eclipse/update-site ”。 Click OK. 单击确定。

在此处输入图片说明

4) You come back to the previous window but this time you must see Cucumber Eclipse Plugin option in the available software list. 4)您返回上一个窗口,但是这次您必须在可用软件列表中看到Cucumber Eclipse Plugin选项。 Just Check the box and press "Next button. 只需选中此框,然后按“下一步”按钮即可。

在此处输入图片说明

5) Click on Next. 5)单击下一步。

在此处输入图片说明

6) Click "I accept the terms of the license agreement" then click Finish. 6)单击“我接受许可协议的条款”,然后单击“完成”。

在此处输入图片说明

7) Let it install, it will take few seconds to complete. 7)安装完毕,将花费几秒钟的时间。

在此处输入图片说明

8) You may or may not encounter a Security warning, if in case you do just click OK. 8)如果您确实单击“确定”,则可能会遇到安全警告,也可能不会遇到。

在此处输入图片说明

9) You are all done now, just Click Yes. 9)现在就完成了,只需单击“是”。

在此处输入图片说明

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

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