2016-12-01 74 views
2
 //get count of checked checkboxes, 
//count must be 1 because it selected one product 
        var checkedCount = productPage.selectedProducts.count(); 
        expect(checkedCount).toBe(1).then(function() { 
         browser.sleep(2222); 
         productDialogPage. createTaskButton.click(); 
        }); 

這是我的代碼。當用戶選擇時,createtaskbutton被激活。失敗:無法讀取未定義的屬性(量角器)

通常它被禁用。

誤差

Failed: Cannot read property 'then' of undefined Stack: TypeError: Cannot read property 'then' of undefined

當我改變這個

//get count of checked checkboxes, count must 1 be because it selected one product 
       var checkedCount = productPage.selectedProducts.count(); 
       expect(checkedCount).toBe(1); 
       browser.sleep(4222); 


       //click task create and expect confirm dialog to be displyed 
       productDialogPage.createTaskButton.click(); 



same 

Message: Failed: Cannot read property 'click' of undefined Stack: TypeError: Cannot read property 'click' of undefined

它亙古不變的閱讀我的規範類,它一旦進入去另一個規範。

也出於同樣

  //get count of checked checkboxes, count must 1 be because it selected one product 
      var checkedCount = productPage.selectedProducts.count(); 
      expect(checkedCount).toBe(1); 
      browser.sleep(4222); 



      browser.wait(function() { 
       return productDialogPage.createTaskButton.isPresent(); 
      }) 
+0

如何獲取元素createTaskButton? – gyc

回答

2
  1. expect(actual).toBe(expected)不是thenable,因爲它不返回的承諾。
  2. 看來,你應該嘗試ExpectedConditions

var EC = ExpectedConditions; 

//get count of checked checkboxes, 
//count must be 1 because it selected one product 
var checkedCount = productPage.selectedProducts.count(); 
expect(checkedCount).toBe(1); 

browser.wait(EC.elementToBeClickable(productDialogPage.createTaskButton, 4222)); 

//click task create and expect confirm dialog to be displyed 
productDialogPage.createTaskButton.click(); 
+0

但是當我在這裏選擇產品 'var checkedCount = productPage.selectedProducts.count();期望(checkedCount).toBe(1);' 它被啓用。不需要點擊? – pronto

+1

從你的帖子你說,createTaskButton被禁用,所以你應該等待createTaskButton是可點擊的。要麼你的createTaskButton不是一個實際的元素。 – cnishina

+0

我改變了你的,因爲它給了錯誤 protractor.ExpectedConditions; 但仍然有錯誤 : '失敗:無法讀取未定義 堆棧的特性「isPresent」: 類型錯誤:無法讀取屬性「isPresent」未定義' 儘管我沒有ispresent。錯誤行是 'browser.wait(EC.elementToBeClickable(productDialogPage.createTaskButton,4222));' – pronto

0

對我來說ExpectedConditions(http://www.protractortest.org/#/api?view=ProtractorExpectedConditions.prototype.elementToBeClickable)的幫助下,之前看到答案。你必須解決承諾。希望能幫助到你! :-)

productPage.selectedProducts.count().then(function(countOfSelectedProducts) { 
      expect(countOfSelectedProducts).toBe(1); 
      }); 
     }); 

// and then wait till your TaskButton is enabled via ExpectedConditions.elementToBeClickable 

var EC = protractor.ExpectedConditions; 

browser.wait(EC.elementToBeClickable(productDialogPage.element.createTaskButton()), 10000).then(function() { 
     productDialogPage.element.createTaskButton.click(); 
}); 
相關問題