java 字段验证_Selenium-Gherkin-Java:验证必填字段上的文本

简短版:我有一个必填字段,显示“此字段是必需的”的元素可以包含多个消息。我正在努力设置我的BDD功能步骤、页面和步骤文件,以验证是否显示了正确的消息。

长版:

对Java/Selenium比较陌生,对这种BDD自动化测试的形式也比较陌生,但是我得到了这个框架,并且正在努力工作。我在一个场景中添加了一个步骤,因为有几个领域是威胁性的,但这没有被测试。

该网站这是为发展中,将有20多个地区版本为它,所以我尽量保持任何硬记录到最低限度/

情景

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命令执行某些操作,但是我要么在不应该的时候传递,要么由于断言错误而忽略了该步骤。

@FindBy(css = "#accountNumber-error")

private WebElement JECAccountNumberCharError;

//Methods

public boolean Try1() {

String m = JECAccountNumberCharError.getText();

return m.equals("This field is required");

} here

Step文件的相关部分

@And("^'Company Account Number' and 'Company Name' are mandatory fields$")

public void companyAccountNumberAndCompanyNameAreMandatoryFields() throws Throwable {

Assert.assertTrue(liteRegistration_page.Try1());

}

在上述情况下,将忽略测试,并在输出中出现断言错误

> 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 â½.And 'Company Account Number' and 'Company Name' are mandatory fields(Registration/LiteRegistration_FeildValidation.feature:78)

我是不是找错了我要找的解决方案?我真的很感激你的帮忙

Company account number

This field is required.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值