gpt4 book ai didi

java - Selenium Cucumber 功能文件在 Eclipse 中未启用

转载 作者:行者123 更新时间:2023-12-02 01:35:21 24 4
gpt4 key购买 nike

我尝试使用 Testng maven 运行 Cucumber BDD 框架,并且已经完成了所有设置配置,但问题是 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>

而且我还附加了功能文件的外观。请指导我解决这个问题。

enter image description here

异常(exception)是::

[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

最佳答案

我认为你不是Eclipse中的插件cucumber

请安装 Cucumber Eclipse 插件

1) 启动 Eclipse IDE,然后从“帮助”菜单中单击“安装新软件”。

enter image description here

2)您将看到一个对话框窗口,单击“添加”按钮。

enter image description here

3) 输入您想要的名称,我们以“Cucumber”为例,并输入“http://cucumber.github.com/cucumber-eclipse/update-site”作为位置。单击“确定”。

enter image description here

4) 您返回到上一个窗口,但这次您必须在可用软件列表中看到 Cucumber Eclipse Plugin 选项。只需选中该框并按“下一步”按钮即可。

enter image description here

5) 单击“下一步”。

enter image description here

6) 单击“我接受许可协议(protocol)的条款”,然后单击“完成”。

enter image description here

7)让它安装,需要几秒钟才能完成。

enter image description here

8) 您可能会或可能不会遇到安全警告,如果确实如此,只需单击“确定”即可。

enter image description here

9) 现在一切都已完成,只需单击"is"即可。

enter image description here

关于java - Selenium Cucumber 功能文件在 Eclipse 中未启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55322532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com