普通脚本可以在终端上轻松运行。但是,当我运行带有网页截图的脚本时,Chrome浏览器无法通过终端打开,并且测试用例失败。
注意:我已在libs文件夹中添加了一个test = df.repartition(2001, "key")
test.persist(StorageLevel.DISK_ONLY)
test.count()
的jar文件,用于截屏。
shot()
端子输出:
System.setProperty("webdriver.chrome.driver", "/home/dev2/Downloads/newchromedriver/chromedriver");
WebDriver m = new ChromeDriver();
m.get("");
m.manage().window().maximize();
m.findElement(By.xpath(".//input[@id='user']")).sendKeys("");
m.findElement(By.xpath(".//input[@id='pass']")).sendKeys("");
m.findElement(By.xpath(".//button[@id='login_submit']")).click();
m.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// m.manage().timeouts().implicitlyWait(2,TimeUnit.MINUTES);
m.switchTo().frame("mailFrame");
Thread.sleep(9000);
String row=m.findElement(By.xpath(".//tr[contains(@id, 'rcmrow')]")).getText();
System.out.println(row +"\t");
if(row.contains("ADC: Reminder 3. GENERAL ENQUIRY REQUEST - Qa Hemant Three") && row.contains("Tue")) {
System.out.println("mail recieved");
}
else {
System.out.println("mail not received");
}
String timestamp = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss").format(new Date());
String imgname = "mapscreenshot " + timestamp + ".png";
String fileWithPath = "//home/dev2/Desktop/" + imgname;
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(m);
ImageIO.write(fpScreenshot.getImage(),"PNG",new File(fileWithPath));
System.out.println("your screenshot is saved at location: " + fileWithPath);
:~/eclipse-workspace/seffcon$ java -cp /home/dev2/eclipse-workspace/seffcon/bin:/home/dev2/eclipse-workspace/seffcon/libs/* org.testng.TestNG testng.xml
[TestNG] Running:
/home/dev2/eclipse-workspace/seffcon/testng.xml
===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
文件夹屏幕截图: