I am trying to write a test case that simulates a GMail Login. I'm receiving the following error when trying to take a screenshot of the failed test case: Appended whole code snippet , Unable to take screenshot & save the screenshot.
Error shown:
FAILED CONFIGURATION: @AfterTest Fail_Test || java.lang.IllegalArgumentException: wrong number of arguments`
Code snippet:
@Test
public void login_gmail() throws IOException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:/Users/neha.sharma/Downloads/chromedriver.exe");
WebDriver drv=new ChromeDriver();
drv.get("http://www.gmail.com");
drv.findElement(By.id("identifierId")).sendKeys("nehasharma@gmail.com"); //USERNAME ENTRY
Thread.sleep(6000);
WebElement eleme = drv.findElement(By.xpath("html/body/div[1]/div[1]/div[2]/div[2]/form/div[2]/div/div[2]/div[1]/div[2]")); //NEXT BUTTON CLICK
JavascriptExecutor executor = (JavascriptExecutor)drv;
executor.executeScript("arguments[0].click();", eleme);
Thread.sleep(2000);
drv.findElement(By.xpath(".//*[@id='password']/div[1]/div/div[1]/input")).sendKeys("abcd234"); // PASSWORD ENTRY
Thread.sleep(5000);
//drv.findElement(By.xpath("html/body/div[1]/div[1]/div[2]/div[2]/form/div[2]/div/div/div[2]/div[1]/div[2]")).click();
WebElement eleme2 = drv.findElement(By.xpath(".//*[@id='passwordNext']/content/span")); // NEXT BUTTON CLICK AFTER ENTERING PASSWORD
JavascriptExecutor executor1 = (JavascriptExecutor)drv;
executor1.executeScript("arguments[0].click();", eleme2);
String Pass_Result= eleme2.getText();
AssertJUnit.assertEquals(Pass_Result, "NEXT");
Thread.sleep(2000);
}
@AfterTest
void Fail_Test(ITestResult Result) throws IOException
{
if (ITestResult.FAILURE==Result.getStatus())
{
TakesScreenshot ts= (TakesScreenshot)drv;
File Source=ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(Source, new File("D:\\TestScreen.png"));
System.out.print("Screenshot taken");
}
}
Please help me out in rectifying this code snippet.
I don't know if I am right or not, but I think you need to pass the value
void fail_test(String name,int name){
}
and I think you should keep data type not the name ie, String ITestResult
ITestResult
is not allowed on @AfterTest
methods. But it is possible on @AfterMethod
(which is, I think, the annotation you wanted to use).
So, just replace @AfterTest
by @AfterMethod
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.