Open NTHang opened 6 years ago
Hi all Em có tìm hiểu để chụp màn hình và so sánh ảnh chụp lần 1 với lần sau có giống nhau ko với selenium nhưng chưa hiểu rõ lắm. Mong anh chị giải thích giúp.
package testdemo;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver; //import org.testng.annotations.AfterClass; import org.testng.annotations.Test;
public class Test {
@Test public void testTakeScreenShot() throws Exception{ WebDriver driver ; //System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe"); driver = new FirefoxDriver(); //goto url driver.get("http://store.demoqa.com/products-page/your-account/"); //Call take screenshot function TestNG.takeSnapShot(driver, "./anh/test.png") ; driver.close(); } /** * This function will take screenshot * @param webdriver * @param fileWithPath * @throws Exception */ public static void takeSnapShot(WebDriver webdriver,String fileWithPath) throws Exception{ //Convert web driver object to TakeScreenshot TakesScreenshot scrShot =((TakesScreenshot)webdriver); //Call getScreenshotAs method to create image file File SrcFile=scrShot.getScreenshotAs(OutputType.FILE); //Move image file to new destination File DestFile=new File(fileWithPath); //Copy file at destination FileUtils.copyFile(SrcFile, DestFile); }
}
Hi all Em có tìm hiểu để chụp màn hình và so sánh ảnh chụp lần 1 với lần sau có giống nhau ko với selenium nhưng chưa hiểu rõ lắm. Mong anh chị giải thích giúp.
package testdemo;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver; //import org.testng.annotations.AfterClass; import org.testng.annotations.Test;
public class Test {
}