GithubHelp home page GithubHelp logo

gauravsh25 / nightwatch-selenium-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lambdatest/nightwatch-selenium-sample

0.0 0.0 0.0 147 KB

Running NightWatch and Selenium On LambdaTest

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

JavaScript 100.00%

nightwatch-selenium-sample's Introduction

Nightwatch Tutorial

LAMBDATEST Logo This tutorial will help you to automate your Nightwatch tests on LambdaTest online Selenium cloud grid.

Prerequisites

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

Steps to Run your First Test

Step 1. Clone the Nightwatch Selenium Repository.

git clone https://github.com/LambdaTest/nightwatch-selenium-sample.git

Step 2. Inside mightwatch-selenium-sample, 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 nightwatch-selenium-sample folder install necessary packages.

cd nightwatch-selenium-sample
npm i

Step 4. To run your First Test.

npm run single

See the Results

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

Executing Nightwatch test Parallely.

  1. Will use the same test script over different configration to demonstarte parallel testing. Parallel testing with Mocha will help you to run multiple test cases simultaneously.
npm run parallel

Understanding googleTest.js

  1. Importing necessary packages, and cofiguring Lambdatest credentials.
var https = require("https");
var lambdaRestClient = require("@lambdatest/node-rest-client");
var lambdaCredentials = {
  username: process.env.LT_USERNAME,
  accessKey: process.env.LT_ACCESS_KEY
};
var lambdaAutomationClient = lambdaRestClient.AutomationClient(
  lambdaCredentials
);
  1. Next, we write our test to open Todo app, and add a task in the list.
module.exports = {
  "@tags": ["test"],
  TodoTest: function(client) {    
    client
      .url("https://lambdatest.github.io/sample-todo-app/")
      .waitForElementPresent("body", 1000)
      .setValue("input[id=sampletodotext]", "Complete LambdaTest tutorial.")
      .click("input[id=addbutton]")
      .pause(1000)
      .end();  
 
  },
  after: function(browser) {
    console.log("Closing down...");
  },
  afterEach: function(client, done) {
    if (
      process.env.LT_USERNAME &&
      process.env.LT_ACCESS_KEY &&
      client.capabilities &&
      client.capabilities["webdriver.remote.sessionid"]
    ) {
      
      lambdaAutomationClient.updateSessionById(
        client.capabilities["webdriver.remote.sessionid"],
        { status_ind: client.currentTest.results.failed ? "failed" : "passed" },
        function(error, session) {
          console.log(error)
          if (!error) {
            client.pause(1000)
            done();
          }
        }
      );
    } else {
      console.log("Test Run Successfully!");
      client.pause(1000)
      done();
    }
  }
};

LambdaTest Selenium Desired Capabilities

Since, now we have a first script ready. Let us specify the selenium capabilities to run the script on LambdaTest cloud-based Selenium Grid. LambdaTest provides a capability generator to the capabilities in all the major languages. All you need to do is to select the OS, Resolution, Browser, Version and the code will be generated. You can just copy it and paste it in your code. In the above example, we have used the following Selenium capabilities which are mentioned in "nightwatch.json" file inside the repo.

 "desiredCapabilities": {
        "build": "Nightwatch-Selenium-Sample",
        "visual": true,
        "video": true,
        "console": true,
        "network": true
      }
    },
    "chrome": {
      "desiredCapabilities": {
        "platform": "Windows 8",
        "browserName": "chrome",
        "version": "71.0"
      }
    },
    "safari": {
      "desiredCapabilities": {
        "platform": "macos 10.13",
        "browserName": "safari",
        "version": "11.0"
      }
    },
    "firefox": {
      "desiredCapabilities": {
        "platform": "win10",
        "browserName": "firefox",
        "version": "60"
      }
    },
    "edge": {
      "desiredCapabilities": {
        "platform": "Windows 10",
        "browserName": "MicrosoftEdge",
        "version": "17.0"
      }
    }

Note: Don't forget to change your location as Javascript in the Selenium capability generator.

Output command terminal

Performing an automation test on your local hosted application| Local Testing

To perform an automation test on a file or application hosted on your local environment or behind firewall, follow the given steps:

  • Set tunnel value to True in test capabilities So for example, if I have to run the above script for a locally hosted web-application then my capabilities class would be :

"tunnel" : true;

OS specific instructions to download and setup tunnel binary can be found at the following links.

Important Note:


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 automation testing 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.

Resources

nightwatch-selenium-sample's People

Contributors

4dvanceboy avatar deeksha-agarwal1995 avatar 4msha avatar koshindergurjar avatar muditlambda avatar sushobhit-lt avatar kanhaiya15 avatar nikhil-lambda avatar prateeklambda 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.