Testing AngularJS with Selenium

后端 未结 12 728
梦毁少年i
梦毁少年i 2020-11-27 04:56

I have a SPA application on stack ASP MVC + AngularJS and I\'d like to test the UI. For now I\'m trying Selenium with PhantomJS and WebKit drivers.

This is a sample

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 05:47

    For my particular problem with the HTML page containing iframes and developed with AnglularJS the following trick saved me a lot of time: In the DOM I clearly saw that there is an iframe which wraps all the content. So following code supposed to work:

    driver.switchTo().frame(0);
    waitUntilVisibleByXPath("//h2[contains(text(), 'Creative chooser')]");
    

    But it was not working and told me something like "Cannot switch to frame. Window was closed". Then I modified the code to:

    driver.switchTo().defaultContent();
    driver.switchTo().frame(0);
    waitUntilVisibleByXPath("//h2[contains(text(), 'Creative chooser')]");
    

    After this everything went smoothly. So evidently Angular was mangling something with iframes and just after loading the page when you expect that driver is focused on default content it was focused by some already removed by Angular frame. Hope this may help some of you.

提交回复
热议问题