Giter Site home page Giter Site logo

devansh013 / nodejs-selenium-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lambdatest/nodejs-selenium-sample

0.0 0.0 0.0 399 KB

Sample NodeJS Automation Scripts For LambdaTest Selenium Grid

Home Page: https://www.lambdatest.com/

JavaScript 100.00%

nodejs-selenium-sample's Introduction

NodeJS Test Tutorial

NodeJS Framework 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.

Prerequisites for Node.js Tutorial

  1. Install npm.
sudo apt install npm
  1. Install NodeJS.
sudo apt install nodejs

Steps to Run your First Test

Step 1. Clone the NodeJs Selenium Repository.

git clone https://github.com/4msha/nodejs-selenium-sample.git

Step 2. Export the Lambda-test Credentials. You can get these from your automation dashboard.

For Linux/macOS::

export LT_USERNAME="YOUR_USERNAME"
export LT_ACCESS_KEY="YOUR ACCESS KEY"

For Windows:

set LT_USERNAME="YOUR_USERNAME"
set LT_ACCESS_KEY="YOUR ACCESS KEY"

Step 3. Inside nodejs.selenium repository install necessary packages.

cd nodejs-selenium-sample
npm i

Step 4. To run your First Test.

npm test
or node index.js

See the Results

You can check your test results on the Automation Dashboard. Automation Testing Logs

Understanding the Test.

  1. Importing Selenium Wedriver,setting up username, access-key, and grid-host.
const webdriver = require('selenium-webdriver');

// USERNAME & KEY can be found at automation dashboard
const USERNAME = 'shwetas';
const KEY = 'xhfQswR5454';

// gridUrl: gridUrl can be found at automation dashboard
const GRID_HOST = 'hub.lambdatest.com/wd/hub';

  1. Define the Test function and capabilities.
function searchTextOnGoogle() {

    // Setup Input capabilities
    const capabilities = {
        platform: 'windows 10',
        browserName: 'firefox',
        version: 'latest',
        resolution: '1280x800',
        geoLocation :'IT',
        network: false,
        visual: false,
        console: false,
        video: true,
        name: 'Test 1', // name of the test
        build: 'NodeJS build' // name of the build
    }

    // URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub
}
searchTextOnGoogle()
  1. Next, we create the grid url and create the selenium driver object.
    const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;

    // setup and build selenium driver object
    const driver = new webdriver.Builder()
        .usingServer(gridUrl)
        .withCapabilities(capabilities)
        .build();
  1. At last, we try to search LambdaTest on google.
 // navigate to a url, search for a text and get title of page
    driver.get('https://www.google.com/ncr').then(function() {
        driver.findElement(webdriver.By.name('q')).sendKeys('LambdaTest\n').then(function() {
            driver.getTitle().then(function(title) {
                setTimeout(function() {
                    console.log(title);
                    driver.executeScript('lambda-status=passed');
                    driver.quit();
                }, 5000);
            });
        });
    }).catch(function(err){
        console.log("test failed with reason "+err)
        driver.executeScript('lambda-status=failed');
        driver.quit();
    });

Want To Run Lambda Tunnel Without Using Command Line?

Download the Underpass app for your operating system. Refer to our support documentation for more information on Lambda Underpass-tunnel-app.

About LambdaTest

LambdaTest 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 test 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.

nodejs-selenium-sample's People

Contributors

4dvanceboy avatar 4msha avatar muditlambda avatar nikhil-lambda avatar swngarg-lt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.