我创建了一个宁静测试。它的作用是打开Google,然后搜索online calculator
。然后应该:
我的代码是:
givenThat(gdguradio).wasAbleTo(openTheApplication);
when(gdguradio).attemptsTo(Search.forTheTerm("online calculator"));
when(gdguradio).attemptsTo(EnterInFormula.forEnteringinFormula());
//guradio.AddingTwoNumbers();
guradio.shouldSeeSumEquals("3");
然后我的EnterInFormula.forEnteringinFormula()
@Step("{0} clears all the completed items")
public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(Click.on(SearchBox.NumberOne));
actor.attemptsTo(Click.on(SearchBox.NumberPlus));
actor.attemptsTo(Click.on(SearchBox.NumberTwo));
actor.attemptsTo(Click.on(SearchBox.NumberEquals));
}
public static EnterInFormula forEnteringinFormula() {
return instrumented(EnterInFormula.class);
}
我的搜索框:
public class SearchBox {
public static Target SEARCH_FIELD = Target.the("search field").located(By.name("q"));
public static Target CalculatorFormula = Target.the("Calculator Formula").located(By.id("cwos"));
public static Target NumberOne = Target.the("1").located(By.id("cwbt33"));
public static Target NumberTwo = Target.the("2").located(By.id("cwbt34"));
public static Target NumberPlus = Target.the("+").located(By.id("cwbt46"));
public static Target NumberEquals = Target.the("=").located(By.id("cwbt45"));
}
在按任意键之前看起来都不错。它只按数字2,所以测试失败。
如何正确编写按钮的单击?
答案 0 :(得分:1)
代码看起来不错。这看起来像是正常的Selenium自动化问题-Selenium表示未启用该元素,因此对于Selenium来说可能未启用。您可能需要等待某种事件或状态,才能准备好单击按钮。