2017-07-04 83 views
0

在Angular JS單頁應用程序中,ui路由器配置爲根據應用程序的狀態更改視圖內容(<ui-view></ui-view>)。量角器單頁應用程序測試

我們如何測量量角器中已更改的視圖內容(頁面)?在執行頁面源視圖時不會顯示視圖內容。頁面正確加載,但量角器無法找到頁面元素。

裏面 <ui-view></ui-view>

<div class="form-group"> 
<label for="firstName" class="ng-scope">First Name</label> 
<input type="text" id="firstName" name="firstName" ng-model="customer.firstName"> 
</div> 

量角器去

<head> 
    <title> Test Application</title> 
</head> 
<body> 
    <div class="wrapper"> 
     <div class="container"> 
      <ui-view></ui-view> 
     </div> 
    <div> 
<body> 

代碼片段無法找到的元素by.model

describe('Protractor Demo App', function() { 
     browser.get('http://example.com');//url 
     it("Test..", function() { 
     element(by.model('customer.firstName')).sendKeys('FIRSTNAME'); 
     element(by.model('customer.lastName')).sendKeys('LASTNAME'); 
     }); 
    }); 
+0

當您在例如Chrome中使用開發工具時,您應該看到插入在''中的html,您還可以在這裏從開發工具粘貼一段代碼,以便我們可以進一步幫助您你的問題? – wswebcreation

+0

你能否請包括量角器測試的代碼 – Acid

回答

0

可能是因爲它在元素被加載之前正在查找元素,因此錯過了它們。嘗試使用protractor.ExpectedConditions。例如:

describe('Protractor Demo App', function() { 
    browser.get('http://example.com'); 
    it("Test..", function() { 
     var el = element(by.css('.form-group')); 
     var EC = protractor.ExpectedConditions; 
     browser.wait(EC.presenceOf(el), 10000).then(function(){ 
      element(by.model('customer.firstName')).sendKeys('FIRSTNAME'); 
      element(by.model('customer.lastName')).sendKeys('LASTNAME'); 
     }); 
    }); 
}); 

這將等待最多10秒鐘.form-group DIV試圖填補輸入之前出現在頁面上。

+0

Stack: ElementNotVisibleError:元素不可見 – user2263197

+0

這些元素頁面有多大?當量角器正在尋找它時,元素是否在視口中足夠大? –