diff --git a/docs/api/index.md b/docs/api/index.md index 7f6beb7..a816e1d 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -4,42 +4,111 @@ This is so that everything is ready to get started with writing the actual test ### The "browser" object We are referring to the main API object as `browser` – for consistency with other Selenium related JS test frameworks and also because since v2, it is also available as a `global`: -
module.exports = {
- demoTest: function (browser) {
- browser.init();
+
+
+ module.exports = {
+ demoTest: function (browser) {
+ browser.init();
+ }
+ };
+
+
+
+
+
+
+
+
+
+
+
+
+You might also see examples from previous versions of Nightwatch, using `client`. It is of course perfectly fine, although it might be confusing to users who are new to JavaScript syntax.
+
+
+ module.exports = {
+ demoTest: function (browser) {
+ browser.init();
+ }
+ };
+
+
+
+
#### Using as Global
From Nightwatch 2, `browser` is available as a global, so this is also valid:
-module.exports = {
- demoTest: function () {
- browser.init();
- }
-};
-
+
+
+ module.exports = {
+ demoTest: function () {
+ browser.init();
+ }
+ };
+
+
+
As well as this:
-describe('Nightwatch APIs', function() {
+describe('Nightwatch APIs', function() {
it('demoTest', function () {
browser.init();
})
};
-
+
+
-### API Contents
+### API Content
Below is a list of all public properties and methods that are made available on the `browser` object.
@@ -120,7 +189,7 @@ Below is a list of all public properties and methods that are made available on
More on [WebDriver Capabilities](https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities).
###### Example:
-
+
{
acceptInsecureCerts: false,
browserName: 'chrome',
@@ -128,7 +197,8 @@ Below is a list of all public properties and methods that are made available on
'goog:chromeOptions': { debuggerAddress: 'localhost:50427' },
// ... continued
}
-
+
+
- #### currentTest
@@ -138,7 +208,7 @@ Below is a list of all public properties and methods that are made available on
###### Available properties:
-
+
{
// name of the current running testcase
name: ' ... ',
@@ -164,7 +234,9 @@ Below is a list of all public properties and methods that are made available on
// the current timestamp, in the format: Wed, 01 Dec 2021 08:34:00 GMT
timestamp: ''
}
-
+
+
+
- #### desiredCapabilities
@@ -174,13 +246,15 @@ Below is a list of all public properties and methods that are made available on
###### Example:
-
+
{
browserName: 'chrome',
'goog:chromeOptions': {},
name: 'Example Test'
}
-
+
+
+
- #### driver
@@ -193,7 +267,7 @@ Below is a list of all public properties and methods that are made available on
In the below example we will retrieve the [WebDriver Session](https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/session_exports_Session.html) instance.
-
+
describe('Nightwatch APIs', function() {
it('driver demoTest', async function () {
const session = await browser
@@ -203,7 +277,8 @@ Below is a list of all public properties and methods that are made available on
});
})
};
-
+
+
- #### sessionId
@@ -213,9 +288,10 @@ Below is a list of all public properties and methods that are made available on
###### Example
-
+
console.log(browser.sessionId); // e0b40362dcec8ec501ac2b42b62bdce2
-
+
+
- #### globals