mercredi 25 février 2015

How do I change browser page when ATUreporter does not take screenshos on failed tests

I failed test intentionally just to see if it takes screenshot, the element password_field can't be located on the webpage,


because I gave it wrong xpath - passwordqqq(look up comment in the code below)


when test fails it must take screenshot, but it does not,


so I want to change browser page using setCaptureScreen method, how to call it?


I looked up the api here, but it s poorly documented.



package erjan.testNG.personal_cabinet_login;

//import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.firefox.FirefoxProfile;

import org.testng.Assert;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

import atu.testng.reports.ATUReports;
import atu.testng.reports.utils.Utils;
import atu.testng.reports.listeners.ATUReportsListener;
import atu.testng.reports.listeners.ConfigurationListener;
import atu.testng.reports.listeners.MethodListener;
import atu.testng.reports.logging.LogAs;
import atu.testng.selenium.reports.CaptureScreen;
import atu.testng.selenium.reports.CaptureScreen.ScreenshotOf;

@Listeners({ ATUReportsListener.class, ConfigurationListener.class,
MethodListener.class })

public class Login_test_no_user {

{
System.setProperty("atu.properties",
"C:\\Users\\www\\ERJAN_NAIMIKZ_ALL\\erjan_2_naimikz_test\\ATUReporter_Selenium_testNG_5.5 BETA");
}

WebDriver firefox ;
@Test
public void main() {
setAuthorInfoForReports();
setIndexPageDescription();

WebElement phone_field = null ;
WebElement password_field = null ;

//setCaptureScreenBrowserpage

ATUReports.add("checking phone, password fields are displayed", "--", "--", "--", LogAs.INFO,null);

try{
phone_field= firefox.findElement(By.xpath("//*[@id=\"login-form\"]/div[1]/span/input"));
//I FAILED THE TEST HERE, the element password_field can't be located on the webpage, because I gave it wrong xpath - passwordqqq
/when test fails it must take screenshot, but it does not
password_field= firefox.findElement(By.xpath("//*[@id=\"login-form\"]/div[2]/span/input[@name=\"passwordqqq\"]"));

Assert.assertNotNull(phone_field);
Assert.assertNotNull(password_field);

Assert.assertTrue(phone_field.isDisplayed());
Assert.assertTrue(password_field.isDisplayed());
}
catch(Exception e){
ATUReports.add("a field is invisible or not available", LogAs.FAILED, new CaptureScreen(
ScreenshotOf.BROWSER_PAGE));
}

ATUReports.add("phone, password are visible",LogAs.PASSED,null);


ATUReports.add("inputting number", "0009999999", "--", "--", LogAs.INFO,null);
phone_field.clear();
phone_field.sendKeys("0009999999");



ATUReports.add("inputting password", "bad_password!!!22222", "--", "--", LogAs.INFO,null);
password_field.clear();
password_field.sendKeys("bad_password!!!22222");

ATUReports.add("click LOGIN button", "--", "--", "--", LogAs.INFO,null);
firefox.findElement(By.cssSelector("input.button.blue")).click();

String newUrl = firefox.getCurrentUrl();

ATUReports.add("check URL", "astana/login", "astana/login", "--", LogAs.INFO,null);

/*
(java.lang.String stepDescription,
java.lang.String inputValue,
java.lang.String expectedValue,
java.lang.String actualValue,
LogAs logAs, CaptureScreen captureScreenshot)*/
try{
Assert.assertEquals("http://ift.tt/19BNkbL", newUrl);
}catch(Exception e ){
ATUReports.add("webpages are not same!", LogAs.FAILED, new CaptureScreen(
ScreenshotOf.BROWSER_PAGE));
}

ATUReports.add("page is same",LogAs.PASSED,null);

// WebDriverWait wait = new WebDriverWait(firefox,3);
// wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class='error-text']")));
// WebElement wrong_message = firefox.findElement(By.xpath("//div[@class='error-text']"));

}

private void setAuthorInfoForReports() {
ATUReports.setAuthorInfo("NAIMI.KZ AUTOTEST", Utils.getCurrentTime(),"1.0");
}

private void setIndexPageDescription() {
ATUReports.indexPageDescription = "erjan runs ATUreport";
}


@BeforeMethod
public void beforeMethod() throws IOException {

firefox = new FirefoxDriver();
ATUReports.setWebDriver(firefox);


firefox.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
firefox.get("http://ift.tt/19BNkbL");

}

@AfterMethod
public void afterMethod() {
firefox.quit();
}

}

Aucun commentaire:

Enregistrer un commentaire