I am working on automation script for change password functionality. I am getting test data from excel file. I have created test csript for positive scenario but now I have to verify if I enter wrong input, system is displaying excepted error messages or not for example:
我正在研究更改密码功能的自动化脚本。我从excel文件中获取测试数据。我已经为正面场景创建了测试csript但现在我必须验证输入错误的输入,系统是否显示例外的错误消息,例如:
- Enter wrong old password
- New password must be 6 character long
- New password and confirm new password must be same.
输入错误的旧密码
新密码长度必须为6个字符
新密码和确认新密码必须相同。
How I can verify these error messages in selenium. Do I need to create separate test case for each rule and use separate excel spreadsheet for each test case.
我如何在selenium中验证这些错误消息。我是否需要为每个规则创建单独的测试用例,并为每个测试用例使用单独的Excel电子表格。
2 个解决方案
#1
1
Probably the easiest method to achieve your goal is to attempt the unsuccessful login and then use the .getText() method to store the labels string, then run an assert against your expected text to ensure that they are a match.
实现目标的最简单方法可能是尝试登录失败,然后使用.getText()方法存储标签字符串,然后针对预期文本运行断言以确保它们匹配。
Maybe a slight example to guide you on the correct path would be:
也许一个简单的例子来指导你正确的道路将是:
String actualIncorrectLogin = driver.findElement(By.id(YourIncorrectLoginLabel)).getText();
Assert.assertEquals(actualIncorrectLogin , expectedMessage);
You could also possibly use the .isDisplayed() method too, however the above is nice to ensure the text which is displayed is correct also
你也可以使用.isDisplayed()方法,但是上面很好,以确保显示的文本也是正确的
#2
0
On 'How I can verify these error messages in selenium.' There is something called getText() in selenium for elements.
关于'如何在selenium中验证这些错误消息'。在selenium中有一些叫做getText()的元素。
On 'Do I need to create separate test case for each rule and use separate excel spreadsheet for each test case.' It depends but ideally onle one negative scenario is sufficient to validate the rules. You can get the text from web page and fetch the data(rules) from excel and compare the text vs rule as per your inputs.
在“我是否需要为每个规则创建单独的测试用例,并为每个测试用例使用单独的Excel电子表格。”这取决于但理想情况下,一个负面情况足以验证规则。您可以从网页获取文本并从Excel中获取数据(规则),并根据您的输入比较文本与规则。
#1
1
Probably the easiest method to achieve your goal is to attempt the unsuccessful login and then use the .getText() method to store the labels string, then run an assert against your expected text to ensure that they are a match.
实现目标的最简单方法可能是尝试登录失败,然后使用.getText()方法存储标签字符串,然后针对预期文本运行断言以确保它们匹配。
Maybe a slight example to guide you on the correct path would be:
也许一个简单的例子来指导你正确的道路将是:
String actualIncorrectLogin = driver.findElement(By.id(YourIncorrectLoginLabel)).getText();
Assert.assertEquals(actualIncorrectLogin , expectedMessage);
You could also possibly use the .isDisplayed() method too, however the above is nice to ensure the text which is displayed is correct also
你也可以使用.isDisplayed()方法,但是上面很好,以确保显示的文本也是正确的
#2
0
On 'How I can verify these error messages in selenium.' There is something called getText() in selenium for elements.
关于'如何在selenium中验证这些错误消息'。在selenium中有一些叫做getText()的元素。
On 'Do I need to create separate test case for each rule and use separate excel spreadsheet for each test case.' It depends but ideally onle one negative scenario is sufficient to validate the rules. You can get the text from web page and fetch the data(rules) from excel and compare the text vs rule as per your inputs.
在“我是否需要为每个规则创建单独的测试用例,并为每个测试用例使用单独的Excel电子表格。”这取决于但理想情况下,一个负面情况足以验证规则。您可以从网页获取文本并从Excel中获取数据(规则),并根据您的输入比较文本与规则。