2015-11-03 81 views
2

我是新来处理Angular JS应用程序测试的。我已经尝试过在线提供的示例Angular JS应用程序。无法使用量角器在角度JS应用程序中查找元素

链接:Angular JS application

探索在网量角器之后是测试AngularJS的最佳途径。我试着用后面的代码来查找上面链接中的元素。尝试了所有可能的定位器,但无法捕捉任何网页元素。

量角器版本:2.5.1

代码:

describe('angularjs homepage', function() { 

    it('should load the home page', function() { 
     browser.ignoreSynchronization = true 
     browser.get('http://themeforest.net/item/square-responsive-admin-app-with-angularjs/full_screen_preview/7511722'); 
     browser.driver.manage().window().maximize() 
     browser.sleep(6000); 
     element(by.xpath('.//*[@id="nav"]/li[2]/a')).click(); 
    }); 
}); 

配置文件::

exports.config = { 
    //The address of a running selenium server. 
    seleniumAddress: 'http://localhost:4444/wd/hub', 
//Here we specify the name of the specs files. 
    specs: ['testspec.js'] 
} 

错误:

1) angularjs homepage should load the home page 
    Message: 
    NoSuchElementError: No element found using locator: By.xpath(".//*[@id=\"na 
v\"]/li[2]/a") 
    Stacktrace: 
    NoSuchElementError: No element found using locator: By.xpath(".//*[@id=\"na 
v\"]/li[2]/a") 
    at new bot.Error (C:\Users\CP042756\AppData\Roaming\npm\node_modules\protrac 
tor\node_modules\selenium-webdriver\lib\atoms\error.js:108:18) 
    at C:\Users\CP042756\AppData\Roaming\npm\node_modules\protractor\lib\element 
.js:694:15 
    at Array.forEach (native) 
    at goog.async.run.processWorkQueue (C:\Users\CP042756\AppData\Roaming\npm\no 
de_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130: 
15) 
    at process._tickCallback (node.js:356:9) 
Error 

请帮助和感谢

回答

0

喜的元件位于iframe中之前ü尝试点击这个链接你必须使用browser.switchTo().frame(“你的IFRAME的名字”)切换到iframe;

欲了解更多有关Selenium Iframe

browser.switchTo().frame("preview-frame"); 
element(by.xpath('.//*[@id="nav"]/li[2]/a')).click(); 

希望这有助于

2

所需元件是内部的iframe - switch to it's context寻找一个元素之前:

browser.switchTo().frame("preview-frame"); 
element(by.xpath('.//*[@id="nav"]/li[2]/a')).click(); 

preview-frameiframe的名称。


正如你可能已经知道,你的AngularJS应用程序加载在这个iframe - 这可能是为什么你设置ignoreSynchronization标志。

我认为你可以不熄灭后,再同步和具有需要调整ignoreSynchronization标志在所有测试您的应用程序 - 在data-ng-app属性被设置在bodyiframe内。如果你直接去从那里iframe加载的URL,protractor会自动检测你的AngularJS应用程序,并会与它同步工作:

it('should load the home page', function() { 
    browser.get('http://iarouse.com/dist-square/v2.0.1/index.html'); 
    browser.driver.manage().window().maximize(); 

    element(by.xpath('.//*[@id="nav"]/li[2]/a')).click(); 
}); 
相关问题