如何解决如何在testng中将值传递给@test
在执行testng的第一种方法期间,URL发生了更改,我希望以后在多个@test中使用该url。但是我无法将该URL以字符串形式传递给@beforetest。这就是它的样子。
public class basefile {
public string tempURL;
@BeforeClass
public static void firstest() throws InterruptedException,IOException {
String url = contr0l.getCurrentUrl();
}
@Test
public static void firstest(String url) throws InterruptedException,IOException {
System.out.println("Parameter value: "+url);
..
}
下面可以使用相同的方法完成的其他操作。 它创建一个带有当前测试执行时间戳的文件夹。然后将所有屏幕截图存储在该文件夹中。我只能传递“字符串文件名”,但是如何传递file.getAbsolutePath()或仅字符串保存路径传递给screenshotmethod()
public class Maintest {
public string tempURL;
@BeforeClass
public static void firstest() throws InterruptedException,IOException {
//create folder to save screenshots.
String stamp = new SimpleDateFormat("yyyy MM dd hh mm ss").format(new Date());
File file = new File("c:\\tmp\\"+stamp);
file.mkdir();
SavePath = file.getAbsolutePath();
System.out.println("Created folder"+file.getAbsolutePath());
}
@Test
public static void firstest(String url) throws InterruptedException,IOException {
dosomething();
screenshotmethod("didsomething"); //string filename
..
}
public static void screenshotmethod(String filename) throws InterruptedException,IOException {
// I need 2 values to gets passed here,filename and directory path.
Screenshot screenshot = new
AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(contr0l);
String filename = new SimpleDateFormat("yyyy MM dd hh mm ss'.png'").format(new Date());
ImageIO.write(screenshot.getImage(),"jpg",new File("c:\\tmp\\" + string + filename));
System.out.println("savepathis:::::::"+SavePath);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。