You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node.js is an efficient, light weight and cross platform runtime environment for executing JavaScript code. npm(node package manager) is the largest ecosystem of open source libraries. LambdaTest enables node.js scripts to run on the Selenium automation grid. This tutorial will help you run Nodejs automation scripts over LambdaTest Selenium Grid.
6
5
7
-
Node.js is an efficient, light weight and cross platform runtime environment for executing JavaScript code. npm(node package manager) is the largest ecosystem of open source libraries. LambdaTest enables node.js scripts to run on the Selenium automation grid.
8
-
9
-
This tutorial will help you run Nodejs automation scripts over LambdaTest Selenium Grid.
10
-
11
-
## Prerequisites for Node.js Tutorial
6
+
## Prerequisites for Node.js Tutorial
12
7
13
-
1.[Download Visual Studio](https://visualstudio.microsoft.com/downloads/) (IDE) for your operating system.
14
-
2.**Node.js and Package Manager (npm)** : Install Node.js from their [official website](https://nodejs.org/en/download/) Or Install Node.js using command line. Go to the terminal or command prompt & run the below command.
8
+
1. Install npm.
15
9
16
10
```
17
-
$ install node
11
+
sudo apt install npm
18
12
```
19
13
20
-
To verify the node version
14
+
2. Install NodeJS.
21
15
22
16
```
23
-
$ node -v
17
+
sudo apt install nodejs
24
18
```
25
19
26
-
If node isn’t of the latest version then you can update it using the below command.
4.**LambdaTest Authentication Credentials**: Make sure you have your LambdaTest credentials with you to run test automation scripts with Jest on LambdaTest Selenium Grid. You can obtain these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/) or through [LambdaTest Profile](https://accounts.lambdatest.com/detail/profile).
39
-
40
-
Set LambdaTest Username and Access Key in environment variables.
28
+
Step 2. Export the Lambda-test Credentials. You can get these from your automation dashboard.
41
29
42
30
<palign="center">
43
31
<b>For Linux/macOS:</b>:
@@ -46,7 +34,6 @@ Set LambdaTest Username and Access Key in environment variables.
46
34
export LT_USERNAME="YOUR_USERNAME"
47
35
export LT_ACCESS_KEY="YOUR ACCESS KEY"
48
36
```
49
-
50
37
<palign="center">
51
38
<b>For Windows:</b>
52
39
@@ -55,60 +42,46 @@ set LT_USERNAME="YOUR_USERNAME"
55
42
set LT_ACCESS_KEY="YOUR ACCESS KEY"
56
43
```
57
44
58
-
## Setting Up The Project In Visual Studio IDE
59
-
60
-
***Step 1** : After installation of the Visual Studio IDE, create a folder in your local system to save all the projects.
61
-
62
-
***Step 2** : Install the below extensions for JavaScript from ‘Extensions’ in VScode Editor.
***Step 3** : Press ‘Ctrl+Shift+P’ and search for git:clone. Paste the URL of this repository([https://github.com/LambdaTest/nodejs-selenium-sample](https://github.com/LambdaTest/nodejs-selenium-sample)) to clone.
69
-
70
-
***Step 4** : Press ENTER and save the TestCafe project in the above created folder.
71
-
72
-
***Step 5**: Create a project directory named *nodejs-selenium-sample*.
73
-
74
-
**Step 6**: Create a file named **index.js** inside the project **nodejs-selenium-sample**. This index.js will be used to specify the nodejs test script that will be executed over the LambdTest Selenium Grid on cloud.
75
-
76
-
## Executing First node.js Testing Script
77
-
78
-
### Test Scenario
79
-
80
-
The test script will do the following actions:
81
-
82
-
1. Invoke the browser launch.
83
-
2. Go to [www.google.com](http://www.google.com).
84
-
3. Type LambdaTest in the search box.
85
-
4. Fetch the title of the web page.
86
-
5. Close the browser and display the fetched title in the console.
47
+
```
48
+
cd nodejs-selenium-sample
49
+
npm i
50
+
```
87
51
88
-
That’s it. Before we deep dive into the test script, we need to declare our desired capabilities. These desired capabilities will help us define the testing environment such as browser version, operating system, and more. You can leverage [LambdaTest Desired Capabilities Generator](https://www.lambdatest.com/capabilities-generator/) to specify the desired capabilities class.
Let us fetch the desired capabilities class from the LambdaTest Desired Capabilities Generator to run the script on LambdaTest cloud-based Selenium Grid.
@@ -149,51 +133,7 @@ function searchTextOnGoogle() {
149
133
driver.executeScript('lambda-status=failed');
150
134
driver.quit();
151
135
});
152
-
}
153
-
searchTextOnGoogle()
154
-
```
155
-
156
-
## Running The Test
157
-
158
-
Open the command line in the same directory where the GitHub repository for nodejs tutorial is cloned & run the below command.
159
-
160
-
```
161
-
node index.js
162
-
```
163
-
164
-
Once the test case is executed, you can assess its status over the LambdaTest Automation Dashboard. You can figure out whether the test has passed or failed. You can also review various kinds of test logs such as network logs, command logs, raw Selenium logs, and even video recording of the entire test execution.
You can also perform cross browser testing of your web application which is locally hosted using Lambda Tunnel. Lambda Tunnel establishes a secure shell connection between your localhost and our cloud servers to help you execute Selenium test automation for privately hosted projects. All you need to do is set the tunnel variable as true in your desired capabilities for running your Selenium script with Lambda Tunnel.
175
-
176
-
* Set **tunnel = true**
177
-
* Set **truetunnelName = 'Identifier name'** (recommended in case of more than 1 tunnels are connected)
178
-
179
-
For example, to run the above test script through your localhost, your desired capabilities will be:
180
-
181
136
```
182
-
const capabilities = {
183
-
platform: 'windows 10',
184
-
browserName: 'firefox',
185
-
version: 'latest',
186
-
resolution: '1280x800',
187
-
network: false,
188
-
visual: false,
189
-
console: false,
190
-
video: true,
191
-
tunnel: true, // flag to run Selenium script on Lambda Tunnel
192
-
name: 'Test 1',
193
-
build: 'NodeJS build'
194
-
```
195
-
196
-
It is important to note that you would need to download the Lambda Tunnel binary file for your operating system. Refer to our support documentation for more information on [Lambda Tunnel](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/).
197
137
198
138
### Want To Run Lambda Tunnel Without Using Command Line?
0 commit comments