-1

谁能让我知道如何使用 TestNG 使用 selenium webdriver 验证电子邮件和日期格式?

4

1 回答 1

0

尝试这个

String REGEX = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; 

//You may find anyother pattern for a valid email. Choose the one which you feel better

然后在 Selenium 中,

WebElement element = driver.findElement(By.Id("yourId"));

像这样检查,

assertTrue(element.getText().matches(REGEX));

或者你可能在 testng.xml 中有这个正则表达式,并在你的测试类中由@Paramaters 使用它。选择是你的。对于这次访问,从 testng.xml 获取参数

于 2012-11-04T11:38:17.183 回答