我如何使用selenium webdriver拍摄flash视频的屏幕截图?

时间:2013-09-20 05:46:43

标签: java selenium webdriver flash

为了自动化视频测试,我们决定在播放时捕捉视频的屏幕截图并比较这些屏幕截图,以确保视频播放。但是当我试图在播放视频时捕捉视频播放器的屏幕截图时,只会显示黑屏。

我们正在使用selenium web-driver和JAVA来开发自动化脚本。有没有其他方法可以确保视频播放与否。获取Flash视频的屏幕截图是否需要闪存支持?

请帮助我们。我们遵循正确的视频测试方法吗?

请查看我的以下selenium网络驱动程序代码

CODE

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Screenshot {

public static void main(String[] args) throws InterruptedException, IOException
{
    FirefoxDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    FlashObjectWebDriver flashapp=null;
    flashapp = new FlashObjectWebDriver(driver,"PlayerPlatformAPI");
    driver.get("Flash media player URL");
    Thread.sleep(1000L);
    WebElement streamurl = driver.findElement(By.name("Stream URL"));
    streamurl.clear();
    streamurl.sendKeys("video link");
    WebElement    tune=driver.findElement(By.xpath("//div[@id='outer']//input[@type='button']"));
    tune.click();
    Thread.sleep(1000L);
    driver.findElement(By.id("PlayerPlatformAPI"));
    screen.seekTo(50);
    flashapp.callFlashObject("SeekTo","50");
    int i;
    for(i=0;i<4;i++)
    {
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    // Now you can do whatever you need to do with it, for example copy somewhere
    File file1 = new File("c:\\tmp\\"+i+"_scrnshot.jpeg");
    FileUtils.copyFile(scrFile,file1);
    Thread.sleep(10000);
    }
    driver.close();
}
}

0 个答案:

没有答案