2014-11-20 41 views
1

我是一個新手,試圖不使用這麼多或所有使用ptor.sleep()來電,特別是在點擊下面。下面的行永遠不會得到這個值(他們都返回Nan),除非我在下面的click()之後包含ptor.sleep(1000);調用。量角器單擊操作依賴於ptor.sleep()。我如何正確解析?

我已經做了各種嘗試,以使數組ELEM列表的點擊後的結果之前解決,包裹在功能等方面的點擊,但沒有我試過沒有睡眠通話作品。已閱讀量角器控制流程。

devCountString = parseInt(arr[i]); 

感謝您的任何見解,或許真的很明顯我已經錯過了,這樣我可以刪除ptor.sleep()電話。

我的規格:

describe('\n == patch List suite results == \n', function() { 

// login already was done in config files, onPrepare function. 
var ptor, noFilterCount; 

// needed here if we turn ptor.ignoreSynchronization = false; 

beforeEach(function() { 
    ptor = protractor.getInstance(); 
    ptor.ignoreSynchronization = true; 
    browser.get('https://my.abc.com:3000/fixes'); 
    ptor.sleep(1200); 
}); //end beforeEach() 

it('11 - verify filter fewer', function() { 

    var sevStringElm, sevString; 
    var applicableCount; 

    ptor.ignoreSynchronization = false; 
     ptor.sleep(500); 

    sevStringElm = element(by.css("input.form-control.bf-spinner")); 
     sevStringElm.clear(); 
     ptor.sleep(500); 

    sevStringElm.sendKeys('8'); 
     ptor.sleep(500); 

// click on the "fewer" spinner, wrap the click to wrap the . 
    var fewerPromise = element(by.css("span.bf-spinner-toggle:nth-child(2)")).click(); 
     ptor.sleep(1000); 

// now get the list of clickable elements in each device card. by title 
    var applicableDevicesElm = element.all(by.css("[title$='Applicable\ Devices']")); 
     applicableDevicesElm.getText().then(function(arr) { 
      console.log("arr.length= "+arr.length); 
      for (var i = 0; i < arr.length; i++) { 
       devCountString = parseInt(arr[i]); 
       expect(devCountString).toBeLessThan(9); 
      }; 
     }); 
    }); 

回答

0

每次動作轉到webdriver的,量角器將它放入流隊列如圖所示in the documentation。因此,當你點擊後檢查你的元素時,隊列應該已經解決了依賴關係,並讓你的狀態爲查找器做好準備。無論如何,即使你不想讓Protractor對其動作(總是asyc)所做的隱式包裝,你可以在點擊後放置一個.then(function(){}),並將該後置單擊邏輯放入該匿名回調函數中。 在附註中,您不得不再使用ptor。使用browser代替混合量角器實例功能。示例:browser.sleep(1000)