Giter Site home page Giter Site logo

cv_debug's Introduction

Logo

BrowserStack Examples TestNG

Introduction

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful.

This BrowserStack Example repository demonstrates a Selenium test framework written in TestNG with parallel testing capabilities. The Selenium test scripts are written for the open source BrowserStack Demo web application (Github). This BrowserStack Demo App is an e-commerce web application which showcases multiple real-world user scenarios. The app is bundled with offers data, orders data and products data that contains everything you need to start using the app and run tests out-of-the-box.

The Selenium tests are run on different platforms like on-prem, docker and BrowserStack using various run configurations and test capabilities.


Repository setup

  • Clone the repository

  • Ensure you have the following dependencies installed on the machine

    • Java >= 8
    • Maven >= 3.1+

    Maven:

     mvn install -DskipTests

    Gradle:

     gradle clean build

About the tests in this repository

This repository contains the following Selenium tests:

Module Test name Description
E2E OrderTest This test scenario verifies successful product purchase lifecycle end-to-end. It demonstrates the Page Object Model design pattern and is also the default test executed in all the single test run profiles.
Login LoginTest This test verifies the login workflow with different types of valid login users.
Login LoginFailTest This test verifies the login workflow error.
Login LoginDataDrivenTest This test verifies the login for all error cases in a datadriven way
Login LoginDataDrivenReadFromCSVTest This test verifies the login for all error cases in a datadriven way with CSV-file
Login LoginRequestedTest This test verifies that the login page is shown when you access the favourites page with being logged in
Offers OfferTest This test mocks the GPS location for Singapore and verifies that the product offers applicable for the Singapore location are shown.
Product FilterTest This test verifies that both filter options are working
User UserTest The first test verifies that the product images load for user: "image_not_loading_user" on the e-commerce application. Since the images do not load, the test case assertion fails. The second test verifies that existing orders are shown for user: "existing_orders_user"

Test infrastructure environments

Configuring the maximum parallel test threads for this repository

For all the parallel run configuration profiles, you can configure the maximum parallel test threads by changing the settings below.

  • Docker

    [File name / path] [Configuration attribute] = [Configuration value]

  • BrowserStack

    Maven:

    pom.xml

    <testng.parallel>classes</testng.parallel>
    <testng.threadCount>5</testng.threadCount>

    Gradle:

    gradle.properties

    testngParallel=classes
    testngThreadCount=5

Test Reporting


On Premise / Self Hosted

This infrastructure points to running the tests on your own machine using a browser (e.g. Chrome) using the browser's driver executables (e.g. ChromeDriver for Chrome). Selenium enables this functionality using WebDriver for many popular browsers.

Prerequisites

  • For this infrastructure configuration (i.e on-premise), ensure that the ChromeDriver executable is placed in the /src/test/resources/drivers folder.

Note: The ChromeDriver version must match the Chrome browser version on your machine.

Running Your Tests

Run a specific test on your own machine

  • How to run the test?

    To run the default test scenario (e.g. End to End Scenario) on your own machine, use the following command:

    Maven:

    mvn clean test -P on-prem

    Gradle:

    gradle clean on-prem

    To run a specific test scenario, use the following command with the additional 'test' argument:

    Maven:

    mvn clean test -P on-prem -Dtest=LoginDataDrivenTest
    

    Gradle:

    gradle clean on-prem -Ptest-name=LoginDataDrivenTest

    where, the argument test or test-name can be any testclass implemented this repository.

  • Output

    This run profile executes a specific test scenario on a single browser instance on your own machine.

Run the entire test suite on your own machine

  • How to run the test?

    To run the entire test suite on your own machine, use the following command:

    Maven:

    mvn clean test -P on-prem-suite

    Gradle:

    gradle clean on-prem-suite
  • Output

    This run profile executes the entire test suite sequentially on a single browser, on your own machine.


Docker

Docker is an open source platform that provides the ability to package and test applications in an isolated environment called containers.

Prerequisites

  • Install and start Docker.

  • Note: Docker should be running on the test machine. Ensure Docker Compose is installed as well.

  • Run docker-compose pull from the docker directory of the repository.

Running Your Tests

Run a specific test on the docker infrastructure

  • How to run the test?

    • Start the Docker by running the following command:
    docker-compose up -d
    • To run the default test scenario (e.g. End to End Scenario) on your own machine, use the following command:

    Maven:

    mvn clean test -P docker

    Gradle:

    gradle clean docker

    To run a specific test scenario, use the following command with the additional 'test-name' argument:

    Maven:

    mvn clean test -P docker -Dtest=LoginDataDrivenTest

    Gradle:

    gradle clean docker -Ptest-name=LoginDataDrivenTest

    where, the argument test or test-name can be any testclass implemented in this repository.

  • After tests are complete, you can stop the Docker by running the following command:

    docker-compose down
  • Output

    This run profile executes a specific test scenario on a single browser deployed on a docker image.

Run the entire test suite in parallel using Docker

  • How to run the test?

    • Start the docker image first by running the following command:
    docker-compose up -d
    • To run the entire test suite in parallel on the docker image, use the following command:

    Maven:

    mvn clean test -P docker-parallel

    Gradle:

    gradle clean docker-parallel
    • After the tests are complete stop the Selenium grid by running the following command:
    docker-compose down
  • Output

    This run profile executes the entire test suite in parallel across multiple instances of the same browser, deployed on a docker image.

  • Note: By default, this execution would run maximum 5 test threads in parallel on Docker. Refer to the section "Configuring the maximum parallel test threads for this repository" for updating the parallel thread count based on your requirements.


BrowserStack

BrowserStack provides instant access to 2,000+ real mobile devices and browsers on a highly reliable cloud infrastructure that effortlessly scales as testing needs grow.

Prerequisites

  • Create a new BrowserStack account or use an existing one.

  • Identify your BrowserStack username and access key from the BrowserStack Automate Dashboard and export them as environment variables using the below commands.

    • For *nix based and Mac machines:
    export BROWSERSTACK_USERNAME=<browserstack-username> &&
    export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
    • For Windows:
    set BROWSERSTACK_USERNAME=<browserstack-username>
    set BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>

    Alternatively, you can also hardcode username and access_key objects in the test_caps.json file.

Note:

  • We have configured a list of test capabilities in the test_caps.json file. You can certainly update them based on your device / browser test requirements.
  • The exact test capability values can be easily identified using the Browserstack Capability Generator

Running Your Tests

Run a specific test on BrowserStack

In this section, we will run a single test on Chrome browser on Browserstack. To change test capabilities for this configuration, please refer to the single object in caps.json file.

  • How to run the test?

    • To run the default test scenario (e.g. End to End Scenario) on your own machine, use the following command:

    Maven:

    mvn clean test -P bstack-single

    Gradle:

    gradle clean bstack-single

    To run a specific test scenario, use the following command with the additional 'test-name' argument: Maven:

    mvn clean test -P bstack-single -Dtest=LoginDataDrivenTest

    Gradle:

    gradle clean bstack-single -Ptest-name=LoginDataDrivenTest

    where, the argument test or test-name can be any testclass implemented in this repository.

  • Output

    This run profile executes a single test on a single browser on BrowserStack. Please refer to your BrowserStack dashboard for test results.

Run the entire test suite in parallel on a single BrowserStack browser

In this section, we will run the tests in parallel on a single browser on Browserstack. Refer to single object in test_caps.json file to change test capabilities for this configuration.

  • How to run the test?

    To run the entire test suite in parallel on a single BrowserStack browser, use the following command:

    Maven:

    mvn clean test -P bstack-parallel

    Gradle:

    gradle clean bstack-parallel
  • Output

    This run profile executes the entire test suite in parallel on a single BrowserStack browser. Please refer to your BrowserStack dashboard for test results.

Run the entire test suite in parallel on multiple BrowserStack browsers

In this section, we will run the tests in parallel on multiple browsers on Browserstack. Refer to the parallel object in caps.json file to change test capabilities for this configuration.

  • How to run the test?

    To run the entire test suite in parallel on multiple BrowserStack browsers, use the following command:

    Maven:

    mvn clean test -P bstack-parallel-browsers

    Gradle:

    gradle clean bstack-parallel-browsers

[Web application hosted on internal environment] Running your tests on BrowserStack using BrowserStackLocal

Prerequisites

  • Clone the BrowserStack demo application repository.

    git clone https://github.com/browserstack/browserstack-demo-app
  • Please follow the README.md on the BrowserStack demo application repository to install and start the dev server on localhost.

  • In this section, we will run a single test case to test the BrowserStack Demo app hosted on your local machine i.e. localhost. Refer to the single_local object in caps.json file to change test capabilities for this configuration.

  • Note: You may need to provide additional BrowserStackLocal arguments to successfully connect your localhost environment with BrowserStack infrastructure. (e.g if you are behind firewalls, proxy or VPN).

  • Further details for successfully creating a BrowserStackLocal connection can be found here:

[Web application hosted on internal environment] Run a specific test on BrowserStack using BrowserStackLocal

  • How to run the test?

    • To run the default test scenario (e.g. End to End Scenario) on a single BrowserStack browser using BrowserStackLocal, use the following command:

    Maven:

    mvn clean test -P bstack-local

    Gradle:

    gradle clean bstack-local

    To run a specific test scenario, use the following command with the additional test-name argument: Maven:

    mvn clean test -P bstack-local -Dtest=LoginDataDrivenTest

    Gradle:

    gradle clean bstack-local -Ptest-name=LoginDataDrivenTest

    where, the argument test or test-name can be any testclass implemented in this repository.

  • Output

    This run profile executes a single test on an internally hosted web application on a single browser on BrowserStack. Please refer to your BrowserStack dashboard(https://automate.browserstack.com/) for test results.

[Web application hosted on internal environment] Run the entire test suite in parallel on a single BrowserStack browser using BrowserStackLocal

In this section, we will run the test cases to test the internally hosted website in parallel on a single browser on Browserstack. Refer to the single_local object in caps.json file to change test capabilities for this configuration.

  • How to run the test?

    To run the entire test suite in parallel on a single BrowserStack browser using BrowserStackLocal, use the following command: Maven:

    mvn clean test -P bstack-local-parallel

    Gradle:

    gradle clean bstack-local-parallel
  • Output

    This run profile executes the entire test suite on an internally hosted web application on a single browser on BrowserStack. Please refer to your BrowserStack dashboard for test results.

  • Note: By default, this execution would run maximum 5 test threads in parallel on BrowserStack. Refer to the section "Configuring the maximum parallel test threads for this repository" for updating the parallel thread count based on your requirements.

[Web application hosted on internal environment] Run the entire test suite in parallel on multiple BrowserStack browser using BrowserStackLocal

In this section, we will run the test cases to test the internally hosted website in parallel on multiple browsers on Browserstack. Refer to the parallel_local object in caps.json file to change test capabilities for this configuration.

  • How to run the test?

    To run the entire test suite in parallel on a single BrowserStack browser using BrowserStackLocal, use the following command:

    Maven:

    mvn clean test -P bstack-local-parallel-browsers

    Gradle:

    gradle clean bstack-local-parallel-browsers
  • Output

    This run profile executes the entire test suite on an internally hosted web application on multiple browsers on BrowserStack. Please refer to your BrowserStack dashboard for test results.

  • Note: By default, this execution would run maximum 5 test threads in parallel on BrowserStack. Refer to the section "Configuring the maximum parallel test threads for this repository" for updating the parallel thread count based on your requirements.

Generating Allure Reports

  • Generate Report using the following command:

    Maven:

    mvn allure:report

    Gradle:

    gradle allureReport
  • Serve the Allure report on a server:

    Maven:

    mvn allure:serve

    Gradle:

    gradle allureServe

Percy

Percy provides a visual review platform.

Prerequisites

  • Sign up with your BrowserStack account, or create a new BrowserStack account.
  • Create a new Percy project.
  • Go to the Project's Settings page, identify your Percy Token, and export them as environment variables using the following commands.

Installation

  1. Install the Percy CLI.
npm install @percy/cli

Export the Percy Token

  • For *nix based and Mac machines:

    export PERCY_TOKEN=[your-project-token]
  • For Windows:

    set PERCY_TOKEN=[your-project-token]

Run your first Visual Test

In this section, we will run the test cases to detect the visual differences. We run the test first, then toggle the property that instructs our test to change some CSS.

  1. Run the test. Maven:
npx percy exec -- mvn clean test -P percy

Gradle:

npx percy exec -- gradle clean percy
  1. Set the changeCSS property in the src/test/java/com/browserstack/test/login/LoginVisuaalTest directory to true.

  2. Run the test again.

  3. View your Project in the Percy dashboard and verify the differences.

Run the Ignore Region Test

In this section, we will run the test that ignores a specific area of a webpage. In a real-world situation, you can think of dynamic content and advertisements where this use case applies.

  1. Run the test. Maven:
npx percy exec -- mvn clean test -P percy-ignore

Gradle:

npx percy exec -- gradle clean percy-ignore
  1. View your Project in the Percy dashboard and verify the differences.

Additional Resources

cv_debug's People

Contributors

shaikhalid avatar

Watchers

 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.