简体   繁体   中英

Getting the session values from the browser in test case writing protractor spec.js file

I've tried:

browser.executeScript("return window.sessionStorage.getItem('UserDataSession');");

browser.driver.executeScript('sessionStorage.getItem("UserDataSession");');

browser.sleep(2000);
browser.driver.executeScript('sessionStorage.getItem("UserDataSession");')
  .then(function(retValue) {

  });

but neither are working for me.

I am trying use these codes in protractor e2e testing for angularjs spec.js file.

You should be taking the promise that executeScript() returns and then use it to do your actions. Here's how -

browser.executeScript("return window.sessionStorage.getItem('UserDataSession');")
.then(function(sess){
    console.‌​log(sess);
});

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM