angularjasmineprotractorkarma-jasminejasmine-node

Local storage in Protractor?


I am writing automation test cases for the first time.I am trying to write e2e testcases using Jasmine/Protractor in Angular. So here I will give you a scenario. Like when I serve/build my project. The page which loads is "Terms and Conditions" and there are 2 buttons Accept and Decline.

When i click Accept it will be creating a local storage "isAccepted" with value true

Now my question here is

"How do I create a local storage or mimic the same kind of scenario using Protractor with Angular when I run the command Protractor?"

Our project is being built on Angular with Ionic framework.


Solution

  • You can execute a javascript snippet in browser via browser.executeScript() api.

    var script = "window.localStorage.setItem('isAccepted', 'true')";
    browser.executeScript(script);