当前位置: 首页>>代码示例>>Java>>正文


Java OutputType类代码示例

本文整理汇总了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());
  }
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:19,代码来源:SharedDriver.java

示例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;
	}
 
开发者ID:anilpandeykiet,项目名称:POM_HYBRID_FRAMEOWRK,代码行数:22,代码来源:ReportManager.java

示例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();
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:20,代码来源:JavaDriverTest.java

示例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) {
				;
			}
		}

	}
 
开发者ID:entelgy-brasil,项目名称:zucchini,代码行数:17,代码来源:ScreenshotHook.java

示例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());
        }
    }
}
 
开发者ID:usman-h,项目名称:Habanero,代码行数:24,代码来源:ScreenShotHook.java

示例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();
    }
  }
}
 
开发者ID:ViliamS,项目名称:XPathBuilder,代码行数:20,代码来源:TestBase.java

示例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();
}
 
开发者ID:HotwireDotCom,项目名称:bdd-test-automation-for-mobile,代码行数:19,代码来源:SetupTeardownSteps.java

示例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();
    }
}
 
开发者ID:hemano,项目名称:cucumber-framework-java,代码行数:33,代码来源:StartingSteps.java

示例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();
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:20,代码来源:SeleniumDemo.java

示例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();
        }
    };
}
 
开发者ID:Java-Publications,项目名称:vaadin-016-helloworld-14,代码行数:17,代码来源:WebDriverFunctions.java

示例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;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:21,代码来源:SeleniumDriver.java

示例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"));
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:13,代码来源:TAbstractSeleniumTest.java

示例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;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:20,代码来源:TAbstractSeleniumTest.java

示例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;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:22,代码来源:TAbstractParallelSeleniumTest.java

示例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;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:20,代码来源:TAbstractRepeatableSeleniumTest.java


注:本文中的org.openqa.selenium.OutputType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。