Skip to content

Commit d4a6900

Browse files
Merge pull request LambdaTest#2108 from amanchopra1905/stage
nightwatch docs updated
2 parents 3254c11 + 82798ab commit d4a6900

File tree

3 files changed

+33
-81
lines changed

3 files changed

+33
-81
lines changed
102 KB
Loading
104 KB
Loading

docs/run-nightwatch-tests-on-lambdatest-selenium-grid.md

Lines changed: 33 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ slug: nightwatch-with-selenium-running-nightwatch-automation-scripts-on-lambdate
2121

2222
import CodeBlock from '@theme/CodeBlock';
2323
import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys";
24+
import Tabs from '@theme/Tabs';
25+
import TabItem from '@theme/TabItem';
2426

2527
<script type="application/ld+json"
2628
dangerouslySetInnerHTML={{ __html: JSON.stringify({
@@ -88,95 +90,39 @@ npm i
8890
Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest Selenium Grid. You can obtain these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build) or through [LambdaTest Profile](https://accounts.lambdatest.com/login).
8991

9092
**Step 3:** Set LambdaTest `Username` and `Access Key` in environment variables.
91-
* For **Linux/macOS**:
92-
```bash
93-
export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY"
94-
```
95-
* For **Windows**:
96-
```bash
97-
set LT_USERNAME="YOUR_USERNAME" set LT_ACCESS_KEY="YOUR ACCESS KEY"
98-
```
93+
<Tabs className="docs__val">
94+
<TabItem value="bash" label="Linux / MacOS" default>
95+
<div className="lambdatest__codeblock">
96+
<CodeBlock className="language-bash">
97+
{`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
98+
export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`}
99+
</CodeBlock>
100+
</div>
101+
</TabItem>
102+
103+
<TabItem value="powershell" label="Windows" default>
104+
<div className="lambdatest__codeblock">
105+
<CodeBlock className="language-powershell">
106+
{`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}"
107+
set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`}
108+
</CodeBlock>
109+
</div>
110+
</TabItem>
111+
</Tabs>
99112

100113
## Run Your First Test
101114
***
102115
### Sample Test with NightwatchJS
103116
Let’s check out a sample **Nightwatch** framework code running on LambdaTest Selenium Grid. This is a simple Nightwatch automation script that tests a sample to-do list app. The code marks two list items as done, adds a list item and then finally gives the total number of pending items as output.
104-
```js
105-
//googleTest.js
106-
107-
var https = require("https");
108-
var lambdaRestClient = require("@lambdatest/node-rest-client");
109-
var lambdaCredentials = {
110-
username: process.env.LT_USERNAME,
111-
accessKey: process.env.LT_ACCESS_KEY
112-
};
113-
var lambdaAutomationClient = lambdaRestClient.AutomationClient(
114-
lambdaCredentials
115-
);
116-
module.exports = {
117-
"@tags": ["test"],
118-
TodoTest: function(client) {
119-
client
120-
.url("https://lambdatest.github.io/sample-todo-app/")
121-
.waitForElementPresent("body", 1000)
122-
.setValue("input[id=sampletodotext]", "Complete LambdaTest tutorial.")
123-
.click("input[id=addbutton]")
124-
.pause(1000)
125-
.end();
126-
127-
},
128-
after: function(browser) {
129-
console.log("Closing down...");
130-
},
131-
afterEach: function(client, done) {
132-
if (
133-
process.env.LT_USERNAME &&
134-
process.env.LT_ACCESS_KEY &&
135-
client.capabilities &&
136-
client.capabilities["webdriver.remote.sessionid"]
137-
) {
138-
139-
lambdaAutomationClient.updateSessionById(
140-
client.capabilities["webdriver.remote.sessionid"],
141-
{ status_ind: client.currentTest.results.failed ? "failed" : "passed" },
142-
function(error, session) {
143-
console.log(error)
144-
if (!error) {
145-
client.pause(1000)
146-
done();
147-
}
148-
}
149-
);
150-
} else {
151-
console.log("Test Run Successfully!");
152-
client.pause(1000)
153-
done();
154-
}
155-
}
156-
};
117+
118+
```javascript title="googleTest.js" reference
119+
https://github.com/LambdaTest/nightwatch-selenium-sample/blob/master/tests/googleTest.js
157120
```
158121
### Configuration of Your Test Capabilities
159122
**Step 4:** Below is the `nightwatch.conf.js` file where we will be declaring the desired capabilities. Since we are using remote webdriver, we have to define which browser environment we want to run the test. We do that by passing browser environment details to LambdaTest Selenium Grid via desired capabilities class.
160123

161-
```js
162-
//nightwatch.conf.js
163-
164-
module.exports = (function(settings) {
165-
console.log(settings["test_settings"]["default"]["username"])
166-
if (process.env.LT_USERNAME) {
167-
settings["test_settings"]["default"]["username"] = process.env.LT_USERNAME;
168-
}
169-
if (process.env.LT_ACCESS_KEY) {
170-
settings["test_settings"]["default"]["access_key"] = process.env.LT_ACCESS_KEY;
171-
}
172-
if (process.env.SELENIUM_HOST) {
173-
settings.selenium.host = process.env.SELENIUM_HOST;
174-
}
175-
if (process.env.SELENIUM_PORT) {
176-
settings.selenium.host = process.env.SELENIUM_PORT;
177-
}
178-
return settings;
179-
})(require('./nightwatch.json'));
124+
```javascript title="nightwatch.conf.js" reference
125+
https://github.com/LambdaTest/nightwatch-selenium-sample/blob/master/nightwatch.conf.js
180126
```
181127
> You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/)**.
182128
@@ -186,7 +132,13 @@ module.exports = (function(settings) {
186132
```bash
187133
npm run single
188134
```
189-
Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on [LambdaTest automation dashboard](https://automation.lambdatest.com/build). LambdaTest Automation Dashboard will help you view all your text logs, screenshots and video recording for your entire automation tests.
135+
Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on [LambdaTest automation dashboard](https://automation.lambdatest.com/build).
136+
137+
<img loading="lazy" src={require('../assets/images/automation/nightwatch/nightwatch-2.png').default} alt="Image" className="doc_img"/> <br />
138+
139+
LambdaTest Automation Dashboard will help you view all your text logs, screenshots and video recording for your entire automation tests.
140+
141+
<img loading="lazy" src={require('../assets/images/automation/nightwatch/nightwatch-1.png').default} alt="Image" className="doc_img"/> <br />
190142

191143
## Running Your Parallel Tests Using Nightwatch Framework
192144
***

0 commit comments

Comments
 (0)