Selenium:无法截取失败的登录页面
所以为了在Selenium中获取失败测试的截图,我使用了以下代码:
@AfterMethod
public void tearDown(ITestResult testResult) throws IOException{
if(ITestResult.FAILURE==testResult.getStatus()){
AppUtils.screenshotOnTestFailure();
}
那么,如果仅仅为了测试目的而发生了什么,我故意通过给用户名输入错误,然后如果我跑了,我得到了登录截图,故意失败了我的测试。 但是,如果我将用户名的凭据作为不正确传递,则测试通过,我无法获取屏幕截图。 但是登录屏幕会发生什么情况,如果填写用户名(这是不正确的),密码和点击登录按钮,然后显示错误消息“您必须指定一个有效的用户名和密码”。 现在我无法登录,但它显示为通过测试,请在此提出您的想法。 谢谢
**XML File:**
<suite name="vTigerAutomation" verbose="1">
<!-- ** These listeners are required for ReportNG report generation while
default report is turned off in TestNg prop** -->
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="testOnChrome" preserve-order="true">
<parameter name="BrowserName" value="ch" />
<parameter name="url" value="http://localhost:8888" />
<parameter name="username" value="admin" />
<parameter name="password" value="admi" />
<classes>
<class name="tiger.SampleProject.MyHomepageTestCases.HomeTestCases" />
<methods>
<include name="tc_loginIntoApp" />
<exclude name="tc_countOfElements" />
<exclude name="tc_enterDataIntoFindBox" />
</methods>
**HomeTestCases Class:**
@Parameters({"username","password"}) //passing Username n pass from xml to LoginPage class
@Test
public void tc_loginIntoApp(String username, String password) throws IOException {
homeObj=lpobj.appLogin(username,password,driver);
**LoginPage class:**
public Home appLogin(String username, String password, WebDriver driver)
throws IOException {
AppUtils.typeValue(username_WE, username);
AppUtils.typeValue(password_WE, password);
AppUtils.clickElement(clk_LoginButton);
Home hpObj = PageFactory.initElements(driver, Home.class);
return hpObj;
}
家庭类
公共类首页{
private static Logger log=Logger.getLogger(Home.class);
public static CalenderPage cpObj=null;
@FindBy(linkText="Calendar")
private static WebElement clk_Calender;
@FindBy(name="query_string")
private static WebElement enter_FindBox;
@FindBy(linkText="Home")
private static WebElement homeHeader;
public void enterDataIntoSearchBox(){
AppUtils.typeValue(enter_FindBox, "testdata");
String Text=enter_FindBox.getAttribute("name");
链接地址: http://www.djcxy.com/p/67399.html
上一篇: Selenium : Unable to take a screenshot of failed Login Page
下一篇: Take screenshot in selenium (java) only in after method