如何使用 jbehave 在 eclipse 上 运行 sikuli 脚本?
How to run sikuli scripts on eclipse using jbehave?
我刚刚发现了 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");
}
}
我刚刚发现了 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");
}
}