Tag: 黄瓜

Selenium Java Webdriver:将字符串添加到Xpath

我有一段Java,我想在一个语句中添加一个String: @and (“^I want to change fieldnumber \”([^\”]*)\” , remove whats inside and add the following text: \”([^\”]*)\”$”) public void testscenario12345(String number, String text) throws Throwable { driver.findElement(By.xpath(“//*[contains(@name,’template:view::item:view:1:item:’)]”)).clear(); driver.findElement(By.xpath(“//*[contains(@name,’template:view::item:view:1:item:’)]”)).sendKeys(text); 如何在上面的代码中添加数字字符串? 为了澄清,如果我在黄瓜中插入“4”,我希望驱动程序通过Xpath找到元素,其中@name包含模板:view:4:item:view:1:item:

Cucumber Java – 如何在下一步中使用返回的String?

我需要自动化一些web服务,我为此创建一些方法,我想使用Cucumber,但我无法计算如何在下一步使用返回值。 所以,我有这个function: Feature: Create Client and place order Scenario: Syntax Given I create client type: “66” And I create for client: “OUTPUTVALUEfromGiven” an account type “123” And I create for client: “OUTPUTVALUEfromGiven” an account type “321” And I want to place order for: “outputvalueFromAnd1” 我有这个步骤: public class CreateClientSteps { @Given(“^I create client type: \”([^\”]*)\”$”) public […]

AfterAll全球钩黄瓜-jvm

我在集成测试中使用了cucumber-jvm ,我需要在所有场景完成后执行一些代码,只需执行一次。 在仔细阅读了这样的post并回顾了这个报道的问题之后 ,我完成了这样的事情: public class ContextSteps { private static boolean initialized = false; @cucumber.api.java.Before public void setUp() throws Exception { if (!initialized) { // Init context. Run just once before first scenario starts Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { // End context. Run just once after all scenarios are finished } }); […]

在junit中运行黄瓜时出错

嗨,我是黄瓜java新手。 我正在尝试运行一个简单的黄瓜function测试。 下面是我的function文件,步骤定义文件和junit runner文件。 但我无法在cucumber-java,cucumber-junit 1.1.6版本中成功运行测试。 function文件 Feature: Test if f1 feature is working Scenario: valid scenario Given input1 is “t” When input2 is also “t” Then result should be “pass” Stepdefinition文件 package cucumberFrameworkPractise; import org.junit.Assert; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; public class CucumberStepDefinitionTest { String input1,input2,result; @Given(“input1 is \”([^\”]*)\”$”) public void input1(String input1) […]

仅执行场景大纲中的特定示例

我们希望在Java测试自动化框架中使用Cucumber更好地管理测试数据。 对于Scenario Outline ,我们希望将按其运行的适用环境分类的测试参数列表。 例如, Scenario Outline: Login into application Given I am on the homepage in the When I enter my And I enter my Then I am taken to the homepage Examples: |user |pass |environment| |test |test1 |local | |retest |retest1 |sit | |prodtest|prodtest1|production | 因此,当上述场景在例如SIT环境中执行时,将仅拾取第二个示例,而不是第一个和第三个示例。 这个执行级别可以完成吗?

黄瓜exception:java.lang.ClassNotFoundException:cucumber.io.ResourceLoader

每当我通过Junit进行黄瓜测试时,我都会遇到错误。 以下是以下例外情况。 任何帮助都会很棒 注意: 项目中没有错误 java.lang.NoClassDefFoundError: cucumber/io/ResourceLoader at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2398) at java.lang.Class.getConstructor0(Class.java:2708) at java.lang.Class.getConstructor(Class.java:1659) at cucumber.runtime.Reflections.hasConstructor(Reflections.java:53) at cucumber.runtime.Reflections.instantiateSubclasses(Reflections.java:29) at cucumber.runtime.Runtime.loadBackends(Runtime.java:96) at cucumber.runtime.Runtime.(Runtime.java:63) at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:74) at cucumber.api.junit.Cucumber.(Cucumber.java:61) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.(JUnit4TestReference.java:33) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.(JUnit4TestClassReference.java:25) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48) […]

如何在使用JAVA和Cucumber的测试中的每个步骤后捕获屏幕截图?

在运行集成测试时, 在每个步骤之后捕获屏幕截图的最佳方法是什么? 测试使用Selenium(3.0.1)和Cucumber(1.2.4)用Java编写。 测试后截取屏幕截图的代码如下,但我需要在每个使用@Given,@ When,@Then注释的方法后截屏。 @After public void after(Scenario scenario){ final byte[] screenshot = driver.getScreenshotAs(OutputType.BYTES); scenario.embed(screenshot, “image/png”); } 谢谢你的任何提示。

黄瓜JVM未定义步骤

我不能用黄瓜为项目执行简单的测试。 我在Intellij 13社区,有黄瓜插件。 我在我的function目录中编写了我的function文件,我还实现了我的步骤,在插件的帮助下创建它们。 我在intellij中识别我在function文件中的步骤,它可以导航并转到步骤实现。 但是当我尝试运行我的场景时,它总是会失败,因为对于每一步,它都会显示“Undefined step:”。 以下是我的项目的组织方式: 正如我之前所说,你可以看到我的步骤被Intellij识别: 这怎么可能,我该如何纠正? 任何帮助都会很棒! 编辑 现在我为跑步者添加了选项: @CucumberOptions( monochrome = true, features = “src/test/resources/features/”, format = { “pretty”,”html: cucumber-html-reports”, “json: cucumber-html-reports/cucumber.json” }, dryRun = false, glue = “fr.tlasnier.cucumber” ) 有用! 然而,我注意到在那之前,我有两个场景轮廓。 一个工作完美,另一个找不到步骤定义! 真的很奇怪,因为这两种情况都有一些步骤。

在特定function之前/之后执行Cucumber步骤

我想为每个特定的function文件指定某些设置和拆除步骤。 我已经看过允许代码在每个场景之前执行的钩子,并在每个function之前挂钩执行代码,但我想指定在一个特定function运行所有场景之前和之后运行一次的代码。 这可能吗?

如何使用cucumber-junit设置我的Cucumberfunction的路径?

我尝试使用Java和Maven构建我的第一个可执行规范。 我用这个结构创建了一个简单的项目: specification |-src |-test |-java |-mypackage |-MyFeatureTest.java |-resources |-MyFeature.feature 在junit测试MyFeatureTest.java我有这个: import org.junit.runner.RunWith; import cucumber.junit.Cucumber; @RunWith(Cucumber.class) public class HomepageTest { } 现在https://github.com/cucumber/cucumber-jvm/wiki/IDE-support说我应该添加以下行: @Cucumber.Options(paths={“my/super.feature:34”}) 我试着修改它 @Cucumber.Options(paths={“src/test/resources/”}) 但注释@Cucumber.Options根本不可用。 我的pom.xml有这种依赖关系: junit junit 4.10 test info.cukes cucumber-java 1.0.0.RC20 test info.cukes cucumber-junit 1.0.0.RC20 test 我错过了什么吗? 更新我遗漏了一些东西:黄瓜特征文件必须位于子目录src/test/resources/mypackage/ 。 否则,junit测试不会接收它。 当我将它们放在同一个目录src/main/test/ ,我可以运行我的function测试,因此它对我来说不是一个阻止程序。 但我想了解整个设置。