Search code examples
javascriptangularjsprotractorangularjs-e2ee2e-testing

protractor checking value of a javascript global variable


I've got an angular 1 application where HTML has a little code snippet that declares global variable at the very beginning:

pathLanguage = "...";

The value of this variable depends on the URL given (parameters of the URL determine value of this variable). I would like to use protractor to check that value. Given the URL, how can I achieve that with protractor? Is it possible at all?

it("Open page", () => {
  browser.get(myURL);
  // ?
});

Solution

  • You could use executeScript to get the variable:

    it("Open page", () => {
      browser.get(myURL);
      expect(browser.executeScript("return window.pathLanguage;")).toEqual(...);
    });