ScreenDhot在AndroidDriver selenium中

时间:2016-07-14 10:52:27

标签: selenium appium

我正在使用appium和selenium进行测试。我正在GenyMotion虚拟设备中测试我的应用程序。我想拍摄我的登录页面的screenShot,但我面临一些问题。请帮帮我。

这是我的appium服务器控制台快照: -

enter image description here

这是我的应用测试配置代码: -

public static AndroidDriver<WebElement> driver;

    public static DesiredCapabilities cap = new DesiredCapabilities();

    @BeforeTest
    public void startAppium() throws MalformedURLException,
            InterruptedException {
        System.out.println("setUP() :: driver.AndroidDriver() executed");
        cap.setCapability("platformVersion", "6.0");

        cap.setCapability("platformName", "Android");
        cap.setCapability("deviceName", "Nexus");
        cap.setCapability("nativeWebScreenshot", "true");

        cap.setCapability("locationServicesAuthorized", true);// this method
                                                                // check once..
        try {

            driver = new AndroidDriver<WebElement>(new URL(
                    "http://127.0.0.1:4723/wd/hub"), cap);
        } catch (Exception e) {
            e.printStackTrace();

        }

    }
WebElement loginElement = driver.findElement(By
                    .xpath("//*[@id='loginButton']"));
            driver.findElement(By.xpath("//*[@id='email']")).sendKeys(
                    "maddy@ymail.com");
            driver.findElement(By.xpath("//*[@id='password']")).sendKeys(
                    "Test_36");
            CaptureScreenShot.getSnap(driver);

            js.executeScript("arguments[0].click();", loginElement);

这是我的Snap Class: -

public class CaptureScreenShot {

          public static void getSnap(AndroidDriver<WebElement> driver){

              System.out.println("Taking Snaps");
                 File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                 System.out.println("srcFile" + scrFile);
                 try {
                    FileUtils.copyFile(scrFile, new File("./snapshots"));
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

          }


}

0 个答案:

没有答案