eclipse - 如何使用 jbehave 在 Eclipse 上运行 sikuli 脚本?
问题描述
我刚刚发现了 Sikuli 并设法让它在 eclipse 上运行。现在我试图弄清楚是否可以将 BDD 与它一起使用,但我似乎无法让它们一起工作。
我正在使用 JBehave 来运行测试。这是我到目前为止所拥有的:
故事档案
Scenario: Opening the orders list
Given i am in the main menu
When i click the orders button
Then the orders list should be opened
步骤文件
package com.test;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.steps.Steps;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
public class AbrirListagemPedidosSteps extends Steps {
Screen s;
public AbrirListagemPedidosSteps() {
s = new Screen();
}
@Given("i'm in the main menu")
public void theSystemIsOpened() throws FindFailed {
s.click("/com/test/images/editSenha.jpg");
s.type("1");
s.click("/com/test/images/btnEntrar.jpg");
}
@When("i click the orders button")
public void iClickTheOrdersButton() throws FindFailed {
s.click("/com/test/images/btnPedido.jpg");
}
@Then("the orders list should be opened")
public void ordersListShouldBeOpened() throws FindFailed {
s.find("/com/test/images/listagemPedidos");
}
}
配置文件
package com.test;
import java.util.Arrays;
import java.util.List;
import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.reporters.Format;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Sikulix;
public class AbrirListagemPedidos extends Sikulix {
public static void main(String[] args) throws FindFailed {
AbrirListagemPedidos test = new AbrirListagemPedidos();
test.configuration();
test.stepsFactory();
test.storyPaths();
}
public Configuration configuration() {
return new MostUsefulConfiguration()
.useStoryLoader(new LoadFromClasspath(this.getClass()))
.useStoryReporterBuilder(
new StoryReporterBuilder().withDefaultFormats().withFormats(Format.CONSOLE));
}
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), new AbrirListagemPedidosSteps());
}
protected List<String> storyPaths() {
return Arrays.asList("/com/test/AbrirListagemPedidos.story");
}
}
据我所知,Sikuli 需要一个 main[] 方法来执行,所以我尝试了这种方法。
我进行了很多搜索,但找不到有关如何使此设置正常工作的教程或其他内容。运行这个不会出错,它只是不做任何事情。
解决方案
经过几次尝试,我终于做到了,但使用 Cucumber 而不是 JBehave。
下面是最终代码。
配置文件 - AbrirListagemPedidos.java
package com.test;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = "path_to_project_folder\\com\\test", tags = "@ListaPedidosTeste",
glue = "path_to_project_folder\\com\\test\\stepdefinitions", monochrome = true, dryRun = false)*
public class AbrirListagemPedidos {
}
功能文件 - AbrirListagemPedidos.feature
@ListaPedidosTeste
Feature: Opening the orders list
Scenario: Opening the orders list
Given i am in the main menu
When i click the orders button
Then the orders list should be opened
步骤文件 - AbrirListagemPedidosSteps.java
package com.test.stepdefinitions;
import org.sikuli.script.Screen;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class AbrirListagemPedidosSteps {
Screen s;
public AbrirListagemPedidosSteps() {
s = new Screen();
}
@Given("^i am in the main menu$")
public void i_am_in_the_main_menu() throws Throwable {
s.click("/com/test/images/editSenha.jpg");
s.type("1");
s.click("/com/test/images/btnEntrar.jpg");
}
@When("^i click the orders button$")
public void i_click_the_orders_button() throws Throwable {
s.click("/com/test/images/btnPedido.jpg");
}
@Then("^the orders list should be opened$")
public void the_orders_list_should_be_opened() throws Throwable {
s.find("/com/test/images/listagemPedidos.jpg");
}
}
推荐阅读
- python - 在python中以给定的安排方式打印您的生日月份
- java - 只能与 Theme.AppCompat 主题(或后代)一起使用的 AppCompat 小部件
- windows - 如何显示来自远程 Docker 的容器日志?
- python - Intersection between 2d image point and 3d mesh
- javascript - How do you hide the cursor prior to touching or clicking anywhere within the window?
- reactjs - 反应键如何工作
- html - Why is placing an html5 canvas over a video not covering the video, instead the canvas shows no colored background, video freezes to a single frame
- node.js - 我在 app.use 语句中放置 app.use(helmet... 的位置是否重要?
- sql - 同一张大表的高效连接
- mysql - 如何在 mysql 列中搜索字典列表(数据类型为 JSON)