|
1 | | -# Jest Selenium Tutorial |
2 | | - |
3 | | - |
4 | | - |
5 | | -## Prerequisites |
6 | | - |
7 | | -1. Install npm. |
| 1 | +# Run Selenium Tests With Jest On LambdaTest |
| 2 | + |
8 | 3 |
|
| 4 | +<p align="center"> |
| 5 | + <a href="https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample" target="_bank">Blog</a> |
| 6 | + ⋅ |
| 7 | + <a href="https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample" target="_bank">Docs</a> |
| 8 | + ⋅ |
| 9 | + <a href="https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample" target="_bank">Learning Hub</a> |
| 10 | + ⋅ |
| 11 | + <a href="https://www.lambdatest.com/newsletter/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample" target="_bank">Newsletter</a> |
| 12 | + ⋅ |
| 13 | + <a href="https://www.lambdatest.com/certifications/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample" target="_bank">Certifications</a> |
| 14 | + ⋅ |
| 15 | + <a href="https://www.youtube.com/c/LambdaTest" target="_bank">YouTube</a> |
| 16 | +</p> |
| 17 | +  |
| 18 | +  |
| 19 | +  |
| 20 | + |
| 21 | +*Learn how to use Jest framework to configure and run your JavaScript automation testing scripts on the LambdaTest platform* |
| 22 | + |
| 23 | +[<img height="58" width="200" src="https://user-images.githubusercontent.com/70570645/171866795-52c11b49-0728-4229-b073-4b704209ddde.png">](https://accounts.lambdatest.com/register) |
| 24 | + |
| 25 | +## Table Of Contents |
| 26 | + |
| 27 | +* [Pre-requisites](#pre-requisites) |
| 28 | +* [Run Your First Test](#run-your-first-test) |
| 29 | +* [Executing The Test](#executing-the-test) |
| 30 | +* [Local Testing With TestNG](#testing-locally-hosted-or-privately-hosted-projects) |
| 31 | + |
| 32 | +## Pre-requisites |
| 33 | + |
| 34 | +Before getting started with Selenium automation testing on LambdaTest, you need to: |
| 35 | + |
| 36 | +* Download and install **NodeJS**. You should be having **NodeJS v6** or newer. Click [here](https://nodejs.org/en/) to download. |
| 37 | +* Make sure you are using the latest version of **JavaScript**. |
| 38 | +* Install **npm** from the official website by clicking [here](https://www.npmjs.com/). |
| 39 | +* Download [Selenium JavaScript bindings](https://www.selenium.dev/downloads/) from the official website. Latest versions of **Selenium Client** and **WebDriver** are ideal for running your JavaScript automation testing script on LambdaTest’s Selenium Grid. |
| 40 | + |
| 41 | +### Installing Selenium Dependencies and tutorial repo |
| 42 | + |
| 43 | +Clone the LambdaTest’s [jest-selenium-webdriver-sample repository](https://github.com/LambdaTest/jest-selenium-webdriver-sample) and navigate to the code directory as shown below: |
| 44 | +```bash |
| 45 | +git clone https://github.com/LambdaTest/jest-selenium-webdriver-sample |
| 46 | +cd jest-selenium-webdriver-sample |
9 | 47 | ``` |
10 | | -sudo apt install npm |
| 48 | +Next, you need to install **Jest**. Run the below command to install Jest: |
| 49 | +```bash |
| 50 | +npm install --save-dev jest --force |
11 | 51 | ``` |
12 | 52 |
|
13 | | -2. Install NodeJS. |
| 53 | +### Setting up Your Authentication |
| 54 | +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). |
14 | 55 |
|
15 | | -``` |
16 | | -sudo apt install nodejs |
17 | | -``` |
| 56 | +Set LambdaTest `Username` and `Access Key` in environment variables. |
| 57 | + * For **Linux/macOS**: |
| 58 | + ```bash |
| 59 | + export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY" |
| 60 | + ``` |
| 61 | + * For **Windows**: |
| 62 | + ```bash |
| 63 | + set LT_USERNAME="YOUR_USERNAME" set LT_ACCESS_KEY="YOUR ACCESS KEY" |
| 64 | + ``` |
18 | 65 |
|
19 | | -## Steps to Run your First Test |
| 66 | +## Run Your First Test |
20 | 67 |
|
21 | | -Step 1. Clone the Jest-Selenium-Webdriver-Sample Repository. |
| 68 | +### Sample Test with Jest |
| 69 | +**Test Scenario:** Let’s check a sample **Jest** Selenium code running on LambdaTest Selenium Grid. This is a simple Jest test automation script that tests a sample to-do list app. Check out this [single.test.js](https://github.com/LambdaTest/jest-selenium-webdriver-sample/blob/master/test/single.test.js) file to run your first sample test. |
22 | 70 |
|
| 71 | +### Configuration of Your Test Capabilities |
| 72 | +In this code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. The capabilities object in the above code are defined as: |
| 73 | +```js |
| 74 | + const capabilities = { |
| 75 | + build: 'jest-LambdaTest-Single', |
| 76 | + browserName: 'chrome', |
| 77 | + version: 'latest', |
| 78 | + platform: 'Windows 10', |
| 79 | +}; |
23 | 80 | ``` |
24 | | -git clone https://github.com/LambdaTest/jest-selenium-webdriver-sample |
| 81 | +> You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/)**. |
| 82 | +
|
| 83 | +## Executing the Test |
| 84 | + |
| 85 | +The tests can be executed in the terminal using the following command |
| 86 | +```bash |
| 87 | +npm test single.test.js |
25 | 88 | ``` |
| 89 | +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. |
26 | 90 |
|
27 | | -Step 2. Inside Jest-Selenium-Webdriver-Sample folder, export the Lambda-test Credentials. You can get these from your automation dashboard. |
| 91 | +## Testing Locally Hosted or Privately Hosted Projects |
28 | 92 |
|
29 | | -<p align="center"> |
30 | | - <b>For Linux/macOS:</b> |
| 93 | +You can test your locally hosted or privately hosted projects with [LambdaTest Selenium grid cloud](https://www.lambdatest.com/selenium-automation) using LambdaTest Tunnel app. All you would have to do is set up an SSH tunnel using LambdaTest Tunnel app and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are made live. |
31 | 94 |
|
32 | | -``` |
33 | | -export LT_USERNAME="YOUR_USERNAME" |
34 | | -export LT_ACCESS_KEY="YOUR ACCESS KEY" |
35 | | -``` |
| 95 | +>Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information. |
36 | 96 |
|
37 | | -<p align="center"> |
38 | | - <b>For Windows:</b> |
| 97 | +Here’s how you can establish LambdaTest Tunnel. |
39 | 98 |
|
40 | | -``` |
41 | | -set LT_USERNAME="YOUR_USERNAME" |
42 | | -set LT_ACCESS_KEY="YOUR ACCESS KEY" |
43 | | -``` |
| 99 | +>Download the binary file of: |
| 100 | +* [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip) |
| 101 | +* [LambdaTest Tunnel for Mac](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip) |
| 102 | +* [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip) |
44 | 103 |
|
45 | | -Step 3. Inside Jest-Selenium-Webdriver-Sample folder install necessary packages. |
| 104 | +Open command prompt and navigate to the binary folder. |
46 | 105 |
|
| 106 | +Run the following command: |
| 107 | +```bash |
| 108 | +LT -user {user’s login email} -key {user’s access key} |
47 | 109 | ``` |
48 | | -cd jest-webdriver-sample |
49 | | -npm i |
| 110 | +So if your user name is [email protected] and key is 123456, the command would be: |
| 111 | +```bash |
| 112 | +LT -user [email protected] -key 123456 |
50 | 113 | ``` |
| 114 | +Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below : |
51 | 115 |
|
52 | | -Step 4. To run your First Test. |
53 | | - |
| 116 | +**Tunnel Capability** |
| 117 | +```js |
| 118 | +const capabilities = { |
| 119 | + tunnel: true, |
| 120 | +} |
54 | 121 | ``` |
55 | | -npm test single.test.js |
| 122 | +### Executing Local Tests with Jest |
| 123 | + |
| 124 | +To run parallel tests using **Jest**, we would have to execute the below command in the terminal: |
| 125 | +```bash |
| 126 | +npm test local.test.js |
56 | 127 | ``` |
| 128 | +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). |
57 | 129 |
|
58 | | -## See the Results |
| 130 | +## Additional Links |
59 | 131 |
|
60 | | -You can check your test results on the [Automation Dashboard](https://automation.lambdatest.com/build). |
61 | | - |
| 132 | +* [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/selenium-automation-capabilities/) |
| 133 | +* [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) |
| 134 | +* [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/) |
62 | 135 |
|
63 | | -If you notice your console output in the command line or terminal. You will find the below output. |
64 | | - |
| 136 | +## Tutorials 📙 |
65 | 137 |
|
| 138 | +Check out our latest tutorials on TestNG automation testing 👇 |
66 | 139 |
|
67 | | - ### Routing traffic through your local machine |
68 | | - - Set tunnel value to `true` in test capabilities |
69 | | - > OS specific instructions to download and setup tunnel binary can be found at the following links. |
70 | | - > - [Windows](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+Windows) |
71 | | - > - [Mac](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+MacOS) |
72 | | - > - [Linux](https://www.lambdatest.com/support/docs/display/TD/Local+Testing+For+Linux) |
| 140 | +* [Jest Tutorial For Selenium JavaScript Testing With Examples](https://www.lambdatest.com/blog/jest-tutorial-for-selenium-javascript-testing-with-examples/) |
| 141 | +* [Jest vs Mocha vs Jasmine: Comparing The Top 3 JavaScript Testing Frameworks](https://www.lambdatest.com/blog/jest-vs-mocha-vs-jasmine/) |
73 | 142 |
|
74 | | -### Run test locally |
75 | | -Navigate to the test folder and run the below command: |
76 | | -``` |
77 | | -npm test local.test.js |
78 | | -``` |
79 | | - ### Important Note: |
80 | | - Some Safari & IE browsers, doesn't support automatic resolution of the URL string "localhost". Therefore if you test on URLs like "http://localhost/" or "http://localhost:8080" etc, you would get an error in these browsers. A possible solution is to use "localhost.lambdatest.com" or replace the string "localhost" with machine IP address. For example if you wanted to test "http://localhost/dashboard" or, and your machine IP is 192.168.2.6 you can instead test on "http://192.168.2.6/dashboard" or "http://localhost.lambdatest.com/dashboard". |
| 143 | +## Documentation & Resources :books: |
| 144 | + |
| 145 | +Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. |
81 | 146 |
|
82 | | -## Notes |
83 | | -* You can view your test results on the [LambdaTest Automation Dashboard](https://www.automation.lambdatest.com) |
84 | | -* To test on a different set of browsers, check out our [capabilities generator](https://www.lambdatest.com/capabilities-generator) |
| 147 | +* [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample) |
| 148 | +* [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample) |
| 149 | +* [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample) |
85 | 150 |
|
86 | | -## About LambdaTest |
87 | | -[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel. |
| 151 | +## LambdaTest Community :busts_in_silhouette: |
88 | 152 |
|
89 | | -### Resources |
| 153 | +The [LambdaTest Community](https://community.lambdatest.com/) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 |
90 | 154 |
|
91 | | -##### [SeleniumHQ Documentation](http://www.seleniumhq.org/docs/) |
92 | | -##### [Jest Documentation](https://jestjs.io/en/) |
| 155 | +## What's New At LambdaTest ❓ |
93 | 156 |
|
| 157 | +To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) |
| 158 | + |
| 159 | +## About LambdaTest |
94 | 160 |
|
| 161 | +[LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. |
| 162 | + |
| 163 | +### Features |
| 164 | + |
| 165 | +* Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. |
| 166 | +* Real-time cross browser testing on 3000+ environments. |
| 167 | +* Test on Real device cloud |
| 168 | +* Blazing fast test automation with HyperExecute |
| 169 | +* Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. |
| 170 | +* Smart Visual Regression Testing on cloud |
| 171 | +* 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. |
| 172 | +* Automated Screenshot testing across multiple browsers in a single click. |
| 173 | +* Local testing of web and mobile apps. |
| 174 | +* Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. |
| 175 | +* Geolocation testing of web and mobile apps across 53+ countries. |
| 176 | +* LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports |
| 177 | + |
| 178 | + |
| 179 | +[<img height="58" width="200" src="https://user-images.githubusercontent.com/70570645/171866795-52c11b49-0728-4229-b073-4b704209ddde.png">](https://accounts.lambdatest.com/register) |
| 180 | + |
| 181 | +## We are here to help you :headphones: |
| 182 | + |
| 183 | +* Got a query? we are available 24x7 to help. [Contact Us ]([email protected]) |
| 184 | +* For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=jest-selenium-webdriver-sample) |
0 commit comments