Selenium Chromedriver:Android

时间:2017-04-25 12:33:59

标签: java selenium selenium-webdriver selenium-chromedriver

我是appium框架的新手。

    @Test
@Parameters("fileName_attachment_TC1")
public void TC001_verifyNavSyncfromContinousToDynamic(String 
 fileName_TC1) throws InterruptedException, IOException
{
   homeUtils.openFileViaFABInRecents(fileName_TC1, 
    HomeConst.txt_saf_sideMenu_internalStorage);
    //homeUtils.openFileFromRecentByInstance(2);
    Thread.sleep(4000);
    viewerUtilsInst.dismissDynamicViewCoachmark();
    viewerUtils.selectViewMode("Continuous Scroll");
    viewerUtils.dismissScrubberFirstTimeExperience();
    driver.swipe(440, 1000, 440, 5, 3000);
    driver.swipe(440, 1150, 440, 5, 3000);
    viewerUtils.selectViewMode("Dynamic View");
    try{
        commonUtils.switchContextToWebView();
        String awe1=driver.getWindowHandle();
        String java = "return 
        window.document.getElementById('adbe_id_46')";
        String rect = java+".getBoundingClientRect().top";
        JavascriptExecutor js = (JavascriptExecutor) driver; 
        Double distFrmTop = (Double) js.executeScript(rect);
        System.out.println("distFrmTop:"+distFrmTop);
        Assert.assertTrue( distFrmTop < 0.8);
    }
    catch(Exception e)
    {
        System.out.println("Exception in 
                 TC001_verifyNavSyncfromContinousToDynamic");
    }
    commonUtils.switchContextToNativeApp();
    commonUtils.pressHBB();

}

@Test
@Parameters("fileName_attachment_TC2")
public void TC002_verifyNavSyncfromDynamicToContinous(String fileName_TC1) throws InterruptedException, IOException
{
    commonUtils.switchContextToNativeApp();
    homeUtils.openFileViaFABInRecents(fileName_TC1, HomeConst.txt_saf_sideMenu_internalStorage);
    //homeUtils.openFileFromRecentByInstance(2);
    Thread.sleep(4000);
    viewerUtilsInst.dismissDynamicViewCoachmark();
    try{
        commonUtils.switchContextToWebView();
        Thread.sleep(4000);
        String awe=driver.getWindowHandle();
        WebElement ele = driver.findElement(By.xpath("//*[(@id='adbe_id_112')]"));
        commonUtils.scrollinDynamicView(ele);
        commonUtils.switchContextToNativeApp();
        viewerUtils.selectViewMode("Continuous Scroll");
        viewerUtils.dismissScrubberFirstTimeExperience();
        commonUtils.tapOnScreen(200, 200);
        Assert.assertTrue(commonUtils.compareScreenshot());
    }
    catch(Exception e)
    {
        System.out.println("Exception in TC002_verifyNavSyncfromDynamicToContinous");
    }
    finally{
        commonUtils.pressHBB();     
    }
}

我在类中的第一个测试用例中将我的应用程序的上下文从native更改为Webview,然后再次更改为native。在下一个测试用例中,我将从native更改为Webview,然后访问提供的驱动程序内容我例外:

no such window: window was already closed
  (Session info: chrome=57.0.2987.132)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.2 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 42 milliseconds

你如何实际关闭新窗口并切换回原来的窗口并与之交互?

0 个答案:

没有答案