java 字段验证_Selenium-Gherkin-Java:验证必填字段上的文本
簡短版:我有一個必填字段,顯示“此字段是必需的”的元素可以包含多個消息。我正在努力設(shè)置我的BDD功能步驟、頁面和步驟文件,以驗證是否顯示了正確的消息。
長版:
對Java/Selenium比較陌生,對這種BDD自動化測試的形式也比較陌生,但是我得到了這個框架,并且正在努力工作。我在一個場景中添加了一個步驟,因為有幾個領(lǐng)域是威脅性的,但這沒有被測試。
該網(wǎng)站這是為發(fā)展中,將有20多個地區(qū)版本為它,所以我盡量保持任何硬記錄到最低限度/
情景
Scenario: 'Do you want to Join an Existing Company?' is an optional radio button selection field which displays 'Company Account Number' and 'Company Name' fields if the 'Yes' option is selected and is defaulted to option 'No'
Given The user is on the Lite Registration page
Than The 'Do you want to Join an Existing Company' radio button selection field is displayed
And the default selection is 'No'
And 'Company Account Number' and 'Company Name' fields are displayed for selection 'Yes'
And A 'Join request' message is displayed for a selection of 'Yes'
And 'Company Account Number' is a numeric field with max 30 char
And 'Company Name' is an alphanumeric filed with max 60 char
And 'Company Account Number' and 'Company Name' are mandatory fields
問題是包含錯誤消息的元素(即“This field is required.”)也會顯示其他消息,因此我無法確認顯示錯誤的元素。
我一直在嘗試對該元素的assert和.getText命令執(zhí)行某些操作,但是我要么在不應(yīng)該的時候傳遞,要么由于斷言錯誤而忽略了該步驟。
@FindBy(css = "#accountNumber-error")
private WebElement JECAccountNumberCharError;
//Methods
public boolean Try1() {
String m = JECAccountNumberCharError.getText();
return m.equals("This field is required");
} here
Step文件的相關(guān)部分
@And("^'Company Account Number' and 'Company Name' are mandatory fields$")
public void companyAccountNumberAndCompanyNameAreMandatoryFields() throws Throwable {
Assert.assertTrue(liteRegistration_page.Try1());
}
在上述情況下,將忽略測試,并在輸出中出現(xiàn)斷言錯誤
> java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:86)
at org.junit.Assert.assertTrue(Assert.java:41)
at org.junit.Assert.assertTrue(Assert.java:52)
at steps.registration.LiteRegistration_Steps.companyAccountNumberAndCompanyNameAreMandatoryFields(LiteRegistration_Steps.java:481)
at a?.And 'Company Account Number' and 'Company Name' are mandatory fields(Registration/LiteRegistration_FeildValidation.feature:78)
我是不是找錯了我要找的解決方案?我真的很感激你的幫忙
Company account number
This field is required.
總結(jié)
以上是生活随笔為你收集整理的java 字段验证_Selenium-Gherkin-Java:验证必填字段上的文本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 抛出java类型异常的方法_Java S
- 下一篇: Java中int和short的取值范围_