[英]Cucumber Scenario Outline with different buttons
我想創建一個場景大綱,在每次運行時單擊不同的按鈕。 我想這樣做的原因是因為按鈕產生相同的預期結果,所以我不能編寫多個場景。
我想不出一個邏輯來處理這個問題。 下面,請看我的代碼。
// --- feature file ---
Scenario Outline: click any button other than button1 and display label1
When i click "<buttontype>"
Then i am presented with label1
Examples:
| buttontype |
| button2 |
| button3 |
| button4 |
// --- Page Object ---
public class ButtonsObjects {
public ButtonsObjects(AppiumDriver driver) {
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
// ------------------ locators ------------------
@AndroidFindBy(id = "btn1")
public MobileElement button1;
@AndroidFindBy(id = "btn2")
public MobileElement button2;
@AndroidFindBy(id = "btn3")
public MobileElement button3;
@AndroidFindBy(id = "btn4")
public MobileElement button4;
// ------------------ actions ------------------
public void clickButton1() {
button1.click;
}
public void clickButton2() {
button2.click;
}
public void clickButton3() {
button3.click;
}
public void clickButton4() {
button4.click;
}
}
// --- step definition ---
@When("^i click \"([^\"]*)\"$")
public void i_click(String arg0) {
// How do I handle this here?
}
那么如何參數化這些按鈕並單擊它們呢? 可能嗎?
提前致謝。
使用將按鈕名稱作為輸入並單擊相應按鈕的方法來豐富您的 PageObject 怎么樣?
public void clickOnButton(String buttonName) {
// Implement as you wish (if/switch/reflection...)
}
然后在您的 Cucumber 步驟上,您可以僅依靠此方法:
@When("i click {string}")
public void i_click(String buttonName) {
pageObject.clickOnButton(buttonName);
}
注意:我使用Cucumber 表達式進行更簡單的步驟注釋(自 Cucumber 5.x 起可用)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.