kiran kumar


{ City } chennai
< Country > india
* Profession * software test engineer
User No # 114949
Total Questions Posted # 0
Total Answers Posted # 2

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 3
Users Marked my Answers as Wrong # 1
Questions / { kiran kumar }
Questions Answers Category Views Company eMail




Answers / { kiran kumar }

Question { CGI, 6583 }

How to capture the screenshot of failed testcase only among a set of testcases?


Answer

package TestNG;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class Screenshot {
WebDriver driver;
@BeforeClass
public void setup() {
driver = new FirefoxDriver();
driver.get("http://google.com");
}

@Test
public void tc01() {
driver.findElement(By.xpath("wrong xpath"));
}
@Test
public void tc02(){

System.out.println(driver.getTitle());

}

@AfterClass
public void browserKill() {
driver.close();
}
//screenshot method for failure test cases
@AfterMethod(alwaysRun=true)
public void takeScreenShot(ITestResult result) throws IOException{
if(result.getStatus()==2){
String testName = result.getMethod().getMethodName();
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("D://"+testName+".jpeg"));
}
}
}

Is This Answer Correct ?    2 Yes 1 No

Question { Value Labs, 5883 }

How can I click the div tag using xpath





.....suresh....




Answer

//input/ancestor::div

Is This Answer Correct ?    1 Yes 0 No