gpt4 book ai didi

java - 如何将实例值从一个类传递到包含测试注释方法的另一个类

转载 作者:行者123 更新时间:2023-12-01 17:39:12 25 4
gpt4 key购买 nike

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返回的驱动值传递给cucumber main中的After方法。UIHandler类中的驱动是从另一个获取的保存测试类信息的测试类我无法将驱动程序值存储在另一个类的 testng After 方法中**

我得到错误

Exception while taking screenshot null Screenshot action entry

最佳答案

要报告结果并在 Cucumber 项目上截取屏幕截图,您需要使用 cucumber hooks 而不是 testng 注释,您使用的方式令人困惑。 Read more here about hooks.

如果您尝试在失败时执行某些操作,您可以创建实现一些 testng 监听器的监听器,try this .

关于java - 如何将实例值从一个类传递到包含测试注释方法的另一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60991144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com