2017-05-08 118 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