2016-12-27 72 views
2

我是量角器中的新手。我已經寫了一個角度測試,首先用戶登錄到應用程序,然後點擊特定的按鈕來計算一個數字。有時它起作用,有時不起作用!量角器點擊功能並不總是起作用

這是代碼:

describe('Protractor Demo App', function() { 

    it('should login to app', function() { 
     browser.get('http://localhost:8080/main'); 
     var userName = element(by.id('username')); 
     var passWord = element(by.id('pwd')); 
     var loginBtn = element(by.id('loginBtn')); 
     userName.sendKeys('user'); 
     passWord.sendKeys('1'); 
     loginBtn.click(); 
     expect(browser.getCurrentUrl()).toEqual('http://localhost:8080/main/#/intro'); 
    }); 


    it('should calculate something', function() { 
     browser.get('http://localhost:8080/main/#/something'); 
     var next = element(by.css('[ng-click="calculate()"]')); 
     element(by.model('accountNo')).sendKeys('0293949223008'); 
     next.click(); 
     expect(element(by.binding('result')).getText()).toEqual('55017000000029'); 
    }); 

    it('should show error for invalid input no', function() { 
     browser.get('http://localhost:8080/main/#/something'); 
     var next = element(by.css('[ng-click="calculate()"]')); 
     element(by.model('accountNo')).sendKeys('9999456123789'); 
     next.click(); 
     expect(element(by.css('[class="messageObject warning"]')).getText()).toEqual('message for invalid input'); 
    }); 
}); 

第一「它」一直工作正確的,但第二個和第三個,有時工作。發生的事情只有其中一人沒有工作;

這是錯誤:

message: Failed: unknown error: Element ... is not clickable at point (1214, 275). Other element would receive the click: ... (Session info: chrome=55.0.2883.87) (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.10240 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 78 milliseconds Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03' System info: host: 'user', ip: 'ip', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30), userDataDir='add'}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}] Session ID: 45d78fbebf15daa1dde971f5f7470551

我不知道是什麼問題。誰能幫我? 在此先感謝。

回答

7

只是進行點擊操作前實現與ExpectedConditions.isElementToBeClickable()方法browser.wait()。您遵循如下:

var EC = protractor.ExpectedConditions; 

it('should show error for invalid input no', function(){ 
    browser.get('http://localhost:8080/main/#/something'); 
    var next = element(by.css('[ng-click="calculate()"]')); 
    element(by.model('accountNo')).sendKeys('9999456123789'); 

    browser.wait(EC.elementToBeClickable(next), 10000,'Element not 
                clickable'); 
    next.click(); 
    expect(element(by.css('[class="messageObject 
    warning"]')).getText()).toEqual('message for invalid input'); 
    }); 
+0

太感謝你了。它工作完美。 – navid

+0

@歡迎您的光臨 –