I've just discovered Sikuli and managed to get it running on eclipse. Now I'm trying to figure out if I can use BDD alongside with it, but I can't seem to get them to work together.
I'm using JBehave to run the tests. Here's what I have so far:
The story file
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
The steps file
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");
}
}
The configuration file
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");
}
}
As far as I know Sikuli needs a main[] method to execute, so I tried this approach.
I've searched a lot and couldn't find a tutorial or something on how to make this setup works. Running this thows no error, it just doesn't do anything.
After a few tries I finally did it, but using Cucumber instead of JBehave.
Below is the final code.
The configuration file - 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 {
}
The feature file - 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
The steps file - 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");
}
}