java web截屏_如何使用Selenium WebDriver截屏

有谁知道是否可以使用Selenium WebDriver截屏? (注:不是硒RC)

#1楼

吉顿

import org.openqa.selenium.OutputType as OutputType

import org.apache.commons.io.FileUtils as FileUtils

import java.io.File as File

import org.openqa.selenium.firefox.FirefoxDriver as FirefoxDriver

self.driver = FirefoxDriver()

tempfile = self.driver.getScreenshotAs(OutputType.FILE)

FileUtils.copyFile(tempfile, File("C:\\screenshot.png"))

#2楼

爪哇

public String captureScreen() {

String path;

try {

WebDriver augmentedDriver = new Augmenter().augment(driver);

File source = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);

path = "./target/screenshots/" + source.getName();

FileUtils.copyFile(source, new File(path));

}

catch(IOException e) {

path = "Failed to capture screenshot: " + e.getMessage();

}

return path;

}

#3楼

PHP(PHPUnit)

使用PHPUnit_Selenium扩展版本1.2.7:

class MyTestClass extends PHPUnit_Extensions_Selenium2TestCase {

...

public function screenshot($filepath) {

$filedata = $this->currentScreenshot();

file_put_contents($filepath, $filedata);

}

public function testSomething() {

$this->screenshot('/path/to/screenshot.png');

}

...

}

#4楼

蟒蛇

您可以使用python网络驱动程序从Windows捕获图像。 使用以下页面需要捕获屏幕截图的代码

driver.save_screenshot('c:\foldername\filename.extension(png,jpeg)')

#5楼

红宝石(黄瓜)

After do |scenario|

if(scenario.failed?)

puts "after step is executed"

end

time = Time.now.strftime('%a_%e_%Y_%l_%m_%p_%M')

file_path = File.expand_path(File.dirname(__FILE__) + '/../../../../../mlife_screens_shot')+'/'+time +'.png'

page.driver.browser.save_screenshot file_path

end

Given /^snapshot$/ do

time = Time.now.strftime('%a_%e_%Y_%l_%m_%p_%M')

file_path = File.expand_path(File.dirname(__FILE__) + '/../../../../../mlife_screens_shot')+'/'+time +'.png'

page.driver.browser.save_screenshot file_path

end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值