当我在步骤定义文件中使用下面的注释时,我的Serenity BDD测试用例在firefox上正常运行:
@Managed
public WebDriver driver;
Run Code Online (Sandbox Code Playgroud)
我想在chrome浏览器上运行相同的测试用例.所以,修改如下:
@Managed(driver = "chrome")
WebDriver driver;
Run Code Online (Sandbox Code Playgroud)
还试过下面一个:
@Managed(driver = "chrome")
ChromeDriver driver;
Run Code Online (Sandbox Code Playgroud)
在上述两种情况下,我的测试用例仍然通过打开Firefox而不是Chrome运行.我按照Serenity BDD指南中提到的确切步骤进行操作.您能否通过打开Chrome来帮助我了解如何执行Serenity BDD测试脚本.在此先感谢您的帮助.
我有一个使用maven构建的java项目.
我有多个包,基于不同功能的功能文件.项目测试结构如下.
src
->test
->java
->com
->usercreation
TestStepDef.java
->uservalidation
TestStepDef.java
->resources
->usercreation
usercreation.feature
->uservaliation
uservalidatin.feature
Run Code Online (Sandbox Code Playgroud)
我只有一个RunCukesTest.java文件
@RunWith(Cucumber.class)
@CucumberOptions(format = { "html:target/cucumber-html-report",
"json:target/cucumber-json-report.json" },
features = "src/test/resources/",
glue = "??????",
tags = {"~@ignore"}
)
public class RunCukesTest {
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,它会运行我的所有功能文件.但它无法找到该功能的特定步骤定义.所以我必须将胶水选项作为"com.usercreation".但是,如果我在运行uservalidation功能文件时这样做,它将无法获取适当的步骤定义.在我的用例中,我不希望步骤def文件位于同一个包中,因为它们具有许多具有不同功能的步骤.
有没有可能的方法,我可以根据运行功能文件的包名称动态提供胶水选项.或者我错过了这个项目的任何其他方法.
我想使用 java 在 Cucumber 中的步骤定义中插入一个预定义的字符串。这是我所拥有的:
Java代码
public String temp = "hello";
//insert temp into my step:
@Then("^the "+temp+" should be empty$")
public void the_should_be_empty() throws Throwable {
//do things
}
Run Code Online (Sandbox Code Playgroud)
但我不断收到此错误:
“注解属性 Then.value 的值必须是常量表达式”
那么,如何在捕获步骤中插入字符串?
==============
我正在尝试在我的许多 BDD 步骤定义中使用一组“全局关键字”列表。所以当我添加一个新的“全局关键字”时,它会在我所有的 BDD 中改变。例如(red|yellow|green)可以在 10 个不同的 BDD 步骤中使用,我想在blue不更改所有 10 个步骤的情况下添加。相反,我想要一个包含列表的字符串变量,然后将此变量插入到我的 BDD 中。
Scenario1
When a new user clicks on sign up page
And provides login ID
Then user is signed up and can view profile page.
Scenario2
When user clicks on the edit profile page
And updates his address
Then updated profile should be visible to user
Run Code Online (Sandbox Code Playgroud)
这些场景以相同的顺序写入功能文件中。当为其编写黄瓜文件时,我在场景 1 中创建一个用户。在场景 2 中,正在更新同一用户。在某种程度上,场景 2 依赖于场景 1,因为它正在更新场景 1 中创建的同一用户。
我的问题是创建的场景是否应该依赖于其他场景。或者它们应该独立于彼此的执行。在这种情况下,我应该在场景2中创建一个新用户,然后对其执行和更新并断言它。
我已经从 Eclipse Marketplace 安装了 Natural 0.7.6 插件,并且拥有 Windows 10。 Eclipse 版本:Eclipse IDE for Java Developers 版本:2020-03 (4.15.0) 内部版本号:20200313-1211
与 Cucumber 相关的 Maven 依赖项:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
[1]: [https://i.stack.imgur.com/e22x3.png][1]
[2]: https://i.stack.imgur.com/cAfLY.png
Run Code Online (Sandbox Code Playgroud)
.feature 文件抱怨“未找到”的定义。CTRL+单击 .feature 文件步骤未导航到 stepDefinition 文件(附有屏幕截图)。我缺少任何插件吗?我使用的 Eclipse IDE 版本和 Cucumber 插件是否存在兼容性问题?我很感谢你们的帮助。
我正在使用 Cucumber 和 Spring Boot 进行测试
@CucumberContextConfiguration
@ActiveProfiles(profiles = { "cucumber" })
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ExtendWith(SpringExtension.class)
public class FooTest {
@Autowired
BatchService batchService;
@MockBean
S3ClientService s3ClientService;
@MockBean
HttpClientService httpClientService;
@SpyBean
UndueService undueService;
@Given("^foo cucumber test$")
public void foo_cucumber_test() {
System.out.println("Foo Test");
}
}
Run Code Online (Sandbox Code Playgroud)
当我在 @Given 方法上使用断点运行/调试测试时
我得到了这个奇怪的行为,@Mockbean/@SpyBean被正确注入,但在测试类中它的值是null!我无法运行 Mockito 函数verify或when
但是当我在没有黄瓜的情况下进行测试时
@Test
void fooTest() {
System.out.println("Foo Test");
}
Run Code Online (Sandbox Code Playgroud)
效果很好!这些值不是null
我有一个包含超过 66 个场景的 Cucumber 功能文件!功能文件的标题确实代表了场景的全部内容。
但 66(200 步)感觉是一个相当大的数字。这是否表明我的专题标题过于宽泛?
单个功能文件中的最大场景数是多少(从最佳实践的角度来看)?
提前致谢 :)
我试图找出如何在我的步骤定义中从黄瓜功能文件中解析日期字段。
class Person{
String name
LocalDate dob
}
scenario: do something with people
Given list of people:
|name|dob|
| john| 20-09-2001|
@Given("^list of people:")
public void doSomething(List<Person> people) {
}
Run Code Online (Sandbox Code Playgroud)
请注意,我无权访问Person类,我确定自己必须编写自己的转换器或注册某个库中某人编写的转换器,在搜索到的唯一选项后,我看到的是使用@Transform更改它们pojo在java.time.LocalDate字段上。
我目前收到以下异常
cucumber.runtime.CucumberException: cucumber.deps.com.thoughtworks.xstream.converters.ConversionException: Cannot deserialize object with new readObject()/writeObject() methods
---- Debugging information ----
class : java.time.LocalDate
required-type : java.time.LocalDate
converter-type : cucumber.deps.com.thoughtworks.xstream.converters.reflection.SerializableConverter
path : /list/com.pkg.Person/dob
Run Code Online (Sandbox Code Playgroud)
我尝试将dateformat更改为yyyy-MM-dd,通常可以,但在这种情况下不行。我将不胜感激关于如何设置和注册自定义转换器的任何指示
我的黄瓜依赖项如下,如果有任何区别,我可以将其替换为较新版本。
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>2.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我正在尝试在不同的浏览器下运行我的黄瓜测试,所以我有test.xml(是的,目前只有一种浏览器)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SelfCare" verbose="1" thread-count="1" parallel="tests" configfailurepolicy="continue">
<parameter name="environment" value="TEST" />
<test name="Chrome">
<parameter name="browser" value="chrome" />
<parameter name="width" value="1024" />
<parameter name="height" value="768" />
<classes>
<class name="TestNGRunner">
<methods>
<include name="scenario"/>
</methods>
</class>
</classes>
</test>
</suite>
Run Code Online (Sandbox Code Playgroud)
对于这个 TestNG 运行程序类,我可以browser从该运行程序类访问参数,但我需要将此变量传递给 Cucumber,其中根据传递的变量创建浏览器实例。到目前为止,我在没有 TestNG 的情况下使用它,并且通过环境变量传递这些变量,但是我认为如果我在不同的浏览器上并行运行测试,这将不起作用。
import cucumber.api.CucumberOptions;
import cucumber.api.testng.CucumberFeatureWrapper;
import cucumber.api.testng.PickleEventWrapper;
import cucumber.api.testng.TestNGCucumberRunner;
import org.testng.annotations.*;
@CucumberOptions(
plugin = {"html:target/cucumber-html-report",
"json:target/cucumber.json",
"pretty:target/cucumber-pretty.txt",
"junit:target/cucumber-results.xml"},
strict = true,
extraGlue = {"src/test/resources/Hooks.java"},
features = {"src/test/resources/Header.feature"}
) …Run Code Online (Sandbox Code Playgroud) 我更新了我的黄瓜版本之后它给出了以下异常:
WARNING: You are using deprecated Main class. Please use
io.cucumber.core.api.cli.Main
Exception in thread "main" cucumber.runtime.CucumberException: Failed to
instantiate public
cucumber.runtime.java.JavaBackend(cucumber.runtime.io.ResourceLoader,io.cucum
ber.stepexpression.TypeRegistry)
Run Code Online (Sandbox Code Playgroud)
我的跑步者班级:
package hgtest.runner;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@CucumberOptions(plugin = "json:target/cucumber-report.json",
features="classpath:features",
glue="hgtest.stepdefinitions"
)
public abstract class CustomCucumberAbstractTestng extends AbstractTestNGCucumberTests {
public CustomCucumberAbstractTestng() {
}
@Test(
groups = {"cucumber"},
description = "Runs Cucumber Feature",
dataProvider = "features"
)
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
Run Code Online (Sandbox Code Playgroud)
Pom.xml如下:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version> …Run Code Online (Sandbox Code Playgroud)