What is a browser variable in nightwatchjs

I just found out about nighwatchjs and try to understand the structure to write my tests. In the examples, I can notice the api using a variable browser - for which I could not find more information about the API Reference or any external documents.

I think I understood the concept of the page object design pattern, and I have experience using selectors, etc.

But I would like to know more about the browser object that is used as it confuses me what really happens:

Consider the following example:

this.demoTestGoogle = function (browser) { browser .url('http://www.google.com') .waitForElementVisible('body', 1000) .setValue('input[type=text]', 'nightwatch') .waitForElementVisible('button[name=btnG]', 1000) .click('button[name=btnG]') .pause(1000) .assert.containsText('#main', 'The Night Watch') .end(); }; 

I can understand that it uses google url and will wait 1000 ms to see the body tag, enter the night vision value, wait, button press, pause to do something and make some statements. But still the browser variable is pretty anonymous to me - what can I do more with it?

+5
source share
2 answers

I know that Teams registered with nightwatchjs.org describe what a browser object can do.

Let me know if this helps. I just study myself, but I will try to share what I know about these teams.

+3
source

The browser object is an important basis for all tests because it is, literally, a browser (or session) environment. I am writing an environment , in fact, as it is misleading to say that the browser in this context is equal to the current window, since you can, for example, run tests using PhantomJS without problems.

You can do some interesting things using the browser object. In my Nightwatch configuration, I set the user globals_path file to globals_path , which allows me to access global variables as follows:

browser.globals.someFunction(browser.globals.someVariable);

All Nightwatch API commands are also used here. Thus, to maximize the window of the current working environment, you can use:

browser.maximizeWindow();

before, say, pointing the browser to the URL you want to check:

browser.url(www.example.com);

The reason why the browser object may look a little strange in the above example is because Nightwatch supports and allows all of its commands to be clained (link to an example sequence of commands using jQuery - the same principles apply).

It looks awfully beautiful when riveted, right ?? But you do not need to bind your tests. You can just write browser. before each command that you want to send to the session.

The browser, by the way, is not a reserved word here. You can call it what you want. I really use the word โ€œclientโ€ since I thought the word โ€œbrowserโ€ was misleading since I also run tests on PhantomJS along with Chrome and Firefox.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1235214/


All Articles