2017-05-08 116 views
1

我已經更新了我的node.js版本7.6以上,我使用ES6.I也附加了錯誤消息。我使用茉莉花和JavaScript寫測試。沒有aysnc - 等待其工作正常..我不是能夠找出爲什麼下面的錯誤來了。任何幫助將非常apppreciated如何在量角器中使用異步等待?

My code is :- 
    SELENIUM_PROMISE_MANAGER: false, 
    describe("testing login functionalties", function() { 

    it("entering the text", async function() { 

    browser.get("https://weather.com/en-IN"); 
    //console.log('ddd') 
    browser.ignoreSynchronization= true; 
    element(by.xpath("//button[@class='user-login']")).click() 
    //browser.ignoreSynchronization= true; 
    console.log('ddd') 
    element(by.xpath("//input[@type='email']")).sendKeys("[email protected]"); 
    element(by.xpath("//input[@type='password']")).sendKeys("xxxxx"); 
    var a= element(by.xpath("//button[@class='btn btn-disabled sign-button login-button']")); 
    await a.getText(); 
    console.log(a); 
    a.click(); 


}); 

});

And the error i am getting is:- 
    /usr/local/Cellar/node/7.9.0/bin/node /usr/local/lib/node_modules/protractor/built/cli.js /Users/amrit/WebstormProjects/E2E/conf.js 
    (node:13230) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead. 
    (node:13230) DeprecationWarning: `DEBUG_FD` is deprecated. Override `debug.log` if you want to use a different log function (https://git.io/vMUyr) 
    [16:03:41] I/local - Starting selenium standalone server... 
    [16:03:41] I/launcher - Running 1 instances of WebDriver 
    [16:03:42] I/local - Selenium standalone server started at http://10.101.23.28:60360/wd/hub 
    Started 
    F 

    Failures: 
    1) testing login functionalties encountered a declaration exception 
     Message: 
     Error: async function() { 

       browser.get("https://weather.com/en-IN"); 
       //console.log('ddd') 
       browser.ignoreSynchronization= true; 
       element(by.xpath("//button[@class='user-login']")).click() 
       //browser.ignoreSynchronization= true; 
       console.log('ddd') 
       element(by.xpath("//input[@type='email']")).sendKeys("[email protected]"); 
       element(by.xpath("//input[@type='password']")).sendKeys("xxxxx"); 
       var a= element(by.xpath("//button[@class='btn btn-disabled sign-button login-button']")); 
       await a.getText(); 
       console.log(a); 
       a.click(); 


      } is not a function 
     Stack: 
     Error: async function() { 

       browser.get("https://weather.com/en-IN"); 
       //console.log('ddd') 
       browser.ignoreSynchronization= true; 
       element(by.xpath("//button[@class='user-login']")).click() 
       //browser.ignoreSynchronization= true; 
       console.log('ddd') 
       element(by.xpath("//input[@type='email']")).sendKeys("[email protected]"); 
       element(by.xpath("//input[@type='password']")).sendKeys("xxxxx"); 
       var a= element(by.xpath("//button[@class='btn btn-disabled sign-button login-button']")); 
       await a.getText(); 
       console.log(a); 
       a.click(); 


      } is not a function 
      at validateFunction (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:30:11) 
      at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:116:16 
      at Suite.<anonymous> (/Users/amrit/WebstormProjects/E2E/Describe.js:8:5) 
      at Object.<anonymous> (/Users/amrit/WebstormProjects/E2E/Describe.js:6:1) 
      at Module._compile (module.js:571:32) 
      at Object.Module._extensions..js (module.js:580:10) 
      at Module.load (module.js:488:32) 

    1 spec, 1 failure 
    Finished in 0.011 seconds 
    [16:03:44] I/local - Shutting down selenium standalone server. 
    [16:03:44] I/launcher - 0 instance(s) of WebDriver still running 
    [16:03:44] I/launcher - chrome #01 failed 1 test(s) 
    [16:03:44] I/launcher - overall: 1 failed spec(s) 
    [16:03:44] E/launcher - Process exited with error code 1 

    Process finished with exit code 1 
+0

在'it'裏面刪除'async'這個詞。 –

+0

那麼如何使用async-await? –

+0

對於非角度頁面'browser.ignoreSynchronization = true;'會有效。如果你需要等待一個元素。您需要使用'browser.sleep(1000)' –

回答

-1

正如我在評論中提及的刪除詞async
browser.ignoreSynchronization設置爲true將爲非角度頁面設置技巧。

也更新您的代碼,它可能會在getText上失敗。 另外,我不是xpath的粉絲,我建議使用by.css來代替。

describe('testing login functionalties', function() { 
    it("entering the text", function() { 
     browser.get("https://weather.com/en-IN"); 

     browser.ignoreSynchronization= true; 
      element(by.css('[@class="user-login"]')).click() 

      console.log('ddd') 
      element(by.css('[type="email"]')).sendKeys('[email protected]'); 
      element(by.css('[type="password"]')).sendKeys('xxxxx'); 
      var a = element(by.css('.btn.btn-disabled.sign-button.login-button')); 
      a.getText().then(function(tmpText) { 
      console.log(tmpText); 
     }); 
      a.click(); 
    }); 
}); 
+0

Downvoted答案。他沒有要求一個非Angular頁面。問題是關於如何使用[async-await](http://rossboucher.com/await/#/)與量角器 – wswebcreation

+0

組合我正在給出一個不同的解決方案,我認爲不適合downvote所有答案不符合你的喜好。這是他們的選擇,如果他們會使用它或不。 –

+0

你應該閱讀這個問題,問題是'..沒有aysnc-正在等待它的工作正常......「,所以你的回答與問題無關 – wswebcreation

1

只是跑了一個快速測試,並能夠重現您的錯誤。通過一些調試,似乎問題在於Jasmine(至少是配備了Protractor 5.1.1的那個)。通過安裝Mocha,我可以得到async-await,並在配置中將其選爲framework