本文整理汇总了Java中org.openqa.selenium.OutputType类的典型用法代码示例。如果您正苦于以下问题:Java OutputType类的具体用法?Java OutputType怎么用?Java OutputType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OutputType类属于org.openqa.selenium包,在下文中一共展示了OutputType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: embedScreenshot
import org.openqa.selenium.OutputType; //导入依赖的package包/类
@After
public void embedScreenshot(Scenario scenario) {
try {
if (!scenario.isFailed()) {
// Take a screenshot only in the failure case
return;
}
String webDriverType = System.getProperty("WebDriverType");
if (!webDriverType.equals("HtmlUnit")) {
// HtmlUnit does not support screenshots
byte[] screenshot = getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
} catch (WebDriverException somePlatformsDontSupportScreenshots) {
scenario.write(somePlatformsDontSupportScreenshots.getMessage());
}
}
示例2: captureScreenshot
import org.openqa.selenium.OutputType; //导入依赖的package包/类
private static String captureScreenshot(WebDriver driver, String screenshotPath, String ScreenshotName) {
String destinationPath = null;
try {
File destFolder = new File(screenshotPath);
destinationPath = destFolder.getCanonicalPath() + "/" + ScreenshotName + ".png";
// Cast webdriver to Screenshot
TakesScreenshot screenshot = (TakesScreenshot) driver;
File sourceFile = screenshot.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(sourceFile, new File(destinationPath));
} catch (Exception e) {
System.out.println("Error capturing screenshot...\n" + e.getMessage());
e.printStackTrace();
}
return destinationPath;
}
示例3: screenshot
import org.openqa.selenium.OutputType; //导入依赖的package包/类
public void screenshot() throws Throwable {
try {
driver = new JavaDriver();
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
if (driver instanceof TakesScreenshot) {
Thread.sleep(1000);
File screenshotAs = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
System.out.println(screenshotAs.getAbsolutePath());
Thread.sleep(20000);
}
} finally {
JavaElementFactory.reset();
}
}
示例4: createScreenshot
import org.openqa.selenium.OutputType; //导入依赖的package包/类
public static void createScreenshot(String fileName) {
if (SeleniumDriver.getInstance() instanceof TakesScreenshot) {
File fileSrc = ((TakesScreenshot) SeleniumDriver.getInstance()).getScreenshotAs(OutputType.FILE);
try {
File destFile = new File(String.format(SCREENSHOTS_FORMAT, fileName));
FileUtils.copyFile(fileSrc, destFile);
LOG.info("[Screenshot] " + destFile.getAbsolutePath());
} catch (IOException e) {
;
}
}
}
示例5: afterTest
import org.openqa.selenium.OutputType; //导入依赖的package包/类
/**
* <p>
* Takes screen-shot if the scenario fails
* </p>
*
* @param scenario will be the individual scenario's within the Feature files
* @throws InterruptedException Exception thrown if there is an interuption within the JVM
*/
@After()
public void afterTest(Scenario scenario) throws InterruptedException {
LOG.info("Taking screenshot IF Test Failed");
System.out.println("Taking screenshot IF Test Failed (sysOut)");
if (scenario.isFailed()) {
try {
System.out.println("Scenario FAILED... screen shot taken");
scenario.write(getDriver().getCurrentUrl());
byte[] screenShot = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenShot, "image/png");
} catch (WebDriverException e) {
LOG.error(e.getMessage());
}
}
}
示例6: setScreenshot
import org.openqa.selenium.OutputType; //导入依赖的package包/类
@AfterMethod
public void setScreenshot(ITestResult result) {
if (!result.isSuccess()) {
try {
WebDriver returned = new Augmenter().augment(webDriver);
if (returned != null) {
File f = ((TakesScreenshot) returned).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(f,
new File(SCREENSHOT_FOLDER + result.getName() + SCREENSHOT_FORMAT));
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (ScreenshotException se) {
se.printStackTrace();
}
}
}
示例7: tearDown
import org.openqa.selenium.OutputType; //导入依赖的package包/类
@After
public void tearDown(Scenario scenario) {
if (scenario.isFailed()) {
try {
logger.info("Test failed, taking screenshot");
byte[] screenshot = ((TakesScreenshot) new Augmenter().augment(getAppiumDriver()))
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
catch (WebDriverException wde) {
System.err.println(wde.getMessage());
}
catch (ClassCastException cce) {
cce.printStackTrace();
}
}
application.tearDown();
}
示例8: afterScenario
import org.openqa.selenium.OutputType; //导入依赖的package包/类
@After
public void afterScenario( Scenario scenario ) throws Exception
{
try
{
attachLog();
if( scenario.isFailed() )
{
try
{
scenario.write( "Current Page URL is " + getDriver().getCurrentUrl() );
byte[] screenshot;
try
{
screenshot = ( ( TakesScreenshot ) getDriver() ).getScreenshotAs( OutputType.BYTES );
} catch( ClassCastException weNeedToAugmentOurDriverObject )
{
screenshot = ( ( TakesScreenshot ) new Augmenter().augment( getDriver() ) ).getScreenshotAs( OutputType.BYTES );
}
String relativeScrnShotPath = takeScreenshot().substring(takeScreenshot().indexOf("screenshots"));
Reporter.addScreenCaptureFromPath(relativeScrnShotPath, getDriver().getCurrentUrl());
} catch( WebDriverException somePlatformsDontSupportScreenshots )
{
System.err.println( somePlatformsDontSupportScreenshots.getMessage() );
}
}
} finally
{
closeDriverObjects();
}
}
示例9: main
import org.openqa.selenium.OutputType; //导入依赖的package包/类
public static void main(String[] args) {
String phantomJsPath = "D:/Program Files/PhantomJS/phantomjs-2.1.1-windows/bin/phantomjs.exe";
String savePath = "D:/screenshot.png";
Gospy.custom()
.setScheduler(Schedulers.VerifiableScheduler.custom()
.setPendingTimeInSeconds(60).build())
.addFetcher(Fetchers.TransparentFetcher.getDefault())
.addProcessor(Processors.PhantomJSProcessor.custom()
.setPhantomJsBinaryPath(phantomJsPath)
.setWebDriverExecutor((page, webDriver) -> {
TakesScreenshot screenshot = (TakesScreenshot) webDriver;
File src = screenshot.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File(savePath));
System.out.println("screenshot has been saved to " + savePath);
return new Result<>();
})
.build())
.build().addTask("phantomjs://http://www.zhihu.com").start();
}
示例10: takeScreenShot
import org.openqa.selenium.OutputType; //导入依赖的package包/类
static Consumer<WebDriver> takeScreenShot() {
return (webDriver) -> {
//take Screenshot
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
outputStream.write(((TakesScreenshot) webDriver).getScreenshotAs(OutputType.BYTES));
//write to target/screenshot-[timestamp].jpg
final FileOutputStream out = new FileOutputStream("target/screenshot-" + LocalDateTime.now() + ".png");
out.write(outputStream.toByteArray());
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
};
}
示例11: createScreenShot
import org.openqa.selenium.OutputType; //导入依赖的package包/类
public File createScreenShot() {
try {
if (driver == null) {
System.err.println("Report Driver[" + runContext.BrowserName + "] is not initialized");
} else if (isAlive()) {
if (alertPresent()) {
System.err.println("Couldn't take ScreenShot Alert Present in the page");
return ((TakesScreenshot) (new EmptyDriver())).getScreenshotAs(OutputType.FILE);
} else if (driver instanceof MobileDriver || driver instanceof ExtendedHtmlUnitDriver
|| driver instanceof EmptyDriver) {
return ((TakesScreenshot) (driver)).getScreenshotAs(OutputType.FILE);
} else {
return createNewScreenshot();
}
}
} catch (DriverClosedException ex) {
System.err.println("Couldn't take ScreenShot Driver is closed or connection is lost with driver");
}
return null;
}
示例12: testScreenShotIOE
import org.openqa.selenium.OutputType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testScreenShotIOE() throws URISyntaxException, IOException {
try {
Mockito.when(mockDriver.getScreenshotAs(ArgumentMatchers.any(OutputType.class)))
.thenReturn(new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()).getParentFile());
screenshot("test.png");
Assert.assertFalse(new File(baseDir, "sc/test.png").exists());
} finally {
FileUtils.deleteDirectory(new File(baseDir, "sc"));
}
}
示例13: prepareDriver
import org.openqa.selenium.OutputType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
System.clearProperty("test.selenium.remote");
localDriverClass = WebDriverMock.class.getName();
remoteDriverClass = WebDriverMock.class.getName();
scenario = "sc";
super.prepareDriver();
mockDriver = Mockito.mock(WebDriverMock.class);
Mockito.when(mockDriver.getScreenshotAs(ArgumentMatchers.any(OutputType.class)))
.thenReturn(new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
final Options options = Mockito.mock(Options.class);
Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
Mockito.when(mockDriver.manage()).thenReturn(options);
final WebElement webElement = Mockito.mock(WebElement.class);
Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
Mockito.when(webElement.isDisplayed()).thenReturn(true);
this.driver = mockDriver;
}
示例14: prepareDriver
import org.openqa.selenium.OutputType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
testName = Mockito.mock(TestName.class);
Mockito.when(testName.getMethodName()).thenReturn("mockTest");
System.clearProperty("test.selenium.remote");
localDriverClass = WebDriverMock.class.getName();
remoteDriverClass = WebDriverMock.class.getName();
scenario = "sc";
super.prepareDriver();
mockDriver = Mockito.mock(WebDriverMock.class);
Mockito.when(((WebDriverMock) mockDriver).getScreenshotAs(ArgumentMatchers.any(OutputType.class))).thenReturn(
new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
final Options options = Mockito.mock(Options.class);
Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
Mockito.when(mockDriver.manage()).thenReturn(options);
final WebElement webElement = Mockito.mock(WebElement.class);
Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
Mockito.when(webElement.isDisplayed()).thenReturn(true);
this.driver = mockDriver;
}
示例15: prepareDriver
import org.openqa.selenium.OutputType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void prepareDriver() throws Exception {
System.clearProperty("test.selenium.remote");
localDriverClass = WebDriverMock.class.getName();
remoteDriverClass = WebDriverMock.class.getName();
scenario = "sc";
super.prepareDriver();
mockDriver = Mockito.mock(WebDriverMock.class);
Mockito.when(mockDriver.getScreenshotAs(ArgumentMatchers.any(OutputType.class))).thenReturn(
new File(Thread.currentThread().getContextClassLoader().getResource("log4j2.json").toURI()));
final Options options = Mockito.mock(Options.class);
Mockito.when(options.window()).thenReturn(Mockito.mock(Window.class));
Mockito.when(mockDriver.manage()).thenReturn(options);
final WebElement webElement = Mockito.mock(WebElement.class);
Mockito.when(mockDriver.findElement(ArgumentMatchers.any(By.class))).thenReturn(webElement);
Mockito.when(webElement.isDisplayed()).thenReturn(true);
this.driver = mockDriver;
}