Class1 -UIHandler1.java
public WebDriver Assettype_dropdown(WebDriver driver,WebElement dropdown,String name) throws InterruptedException {
wait_until_clickable(driver,dropdown,120);
dropdown.click();
search.click();
search.sendKeys(name);
insearchesult2.click();
view_btn.click();
return driver;
}
public WebDriver result_verification(WebDriver driver,String APIR,String msg) throws InterruptedException
{
Thread.sleep(5000);
search_view.sendKeys(APIR);
assertEquals(driver,table_data,APIR,msg);
return driver;
}
第2类测试类
public class cucumbermain extends AbstractTestNGCucumberTests {
public static WebDriver driver;
@AfterMethod() //AfterMethod annotation - This method executes after every test execution
public static void screenShot(ITestContext context){
//using ITestResult.FAILURE is equals to result.getStatus then it enter into if condition
if(ITestResult.SUCCESS==result.getStatus()){
try{
// To create reference of TakesScreenshot
TakesScreenshot screenshot=(TakesScreenshot)driver;
// Call method to capture screenshot
File src=screenshot.getScreenshotAs(OutputType.FILE);
// Copy files to specific location
// result.getName() will return name of test case so that screenshot name will be same as test case name
FileUtils.copyFile(src, new File("D:\\"+result.getName()+".png"));
System.out.println("Successfully captured a screenshot");
}catch (Exception e){
System.out.println("Exception while taking screenshot "+e.getMessage());
}
}
}
在这里,我必须将** UI Handler1.java 返回的驱动程序值传递给黄瓜主体中的 After方法 .UIHandler类中的驱动程序是从另一个驱动程序获得的包含测试类信息的测试类 我无法将驱动程序的值存储在另一个类的testng After方法中**
错误消息获取
截取屏幕快照时出现异常null 屏幕截图操作条目
答案 0 :(得分:0)
要报告结果并在Cucumber项目上截屏,您需要使用黄瓜钩子而不是testng批注,您使用的方式令人困惑。 Read more here about hooks.
如果您尝试在失败时采取措施,则可以创建实现某些testng侦听器的侦听器try this。