Giter Club home page Giter Club logo

cbt-4-ways-java's Introduction

4 Ways To Do Cross-Browser Testing in Java

This repository shows how to do cross-browser testing with Selenium WebDriver in Java in four different ways:

  1. Using a local machine
  2. Using Selenium Grid
  3. Using a cloud testing platform (LambdaTest)
  4. Using visual testing (Applitools)

I chose to develop this project using Selenium WebDriver and Java because they are very popular choices for test automation. However, these techniques could be done with other tools (like Cypress and Playwright) and languages (like C#, JavaScript, Python, and Ruby) as well.

The main test

This repository contains one main test case that is implemented once for each of the four ways to do cross-browser testing.

The main test case is a login test for the Applitools demo app. The steps are:

  1. Load the login page.
  2. Verify that the login page loads correctly.
  3. Perform login.
  4. Verify that the main page loads correctly.

Project setup

This repository is a Java Maven project. To build the project and run the tests, you will need to install the Java Development Kit (JDK) 17. It is recommended to use an IDE like IntelliJ IDEA.

Running the tests

All tests are located under src/test/java/com/automationpanda/. They are written using the JUnit 5 framework. There are 4 test case classes, one for each cross-browser testing method: Each test has unique setup needs and environment variables (documented below).

You can run tests individually from an IDE like IntelliJ IDEA. You can also run tests using mvn test (including single tests). Just remember to set the required environment variables first!

1. Using a local machine

Test class: LocalMachineTest

Extra setup:

  • Install target browsers (Chrome, Firefox, Edge, Safari)
  • Install target browser drivers (ChromeDriver, geckodriver, EdgeDriver)

Environment variables:

  • BROWSER: (optional) chrome, edge, firefox, or safari
  • EDGE_DRIVER_PATH: (required for Edge) the absolute path to EdgeDriver

2. Using Selenium Grid

Test class: SeleniumGridTest

Extra setup:

  • You must set up your own Selenium Grid instance
  • You could use VMs, containers, or Kubernetes for Selenium Grid infrastructure
  • Read the Selenium Grid docs to learn how to set it up
  • I used Ubuntu VMs on Digital Ocean
    • 1 VM for the hub
    • 2 VMs for 2 nodes
    • Each node had Chrome and Firefox
    • Config file and launch script copies are located under segrid/

Environment variables:

  • BROWSER: (optional) chrome or firefox
  • GRID_URL: the URL for the Selenium Grid instance

3. Using a cloud testing platform

Test class: CloudPlatformTest

Extra setup:

Environment variables:

  • LT_USERNAME: your LambdaTest username
  • LT_ACCESS_KEY: your LambdaTest access key
  • GRID_URL: (optional) the LambdaTest grid URL
  • BROWSER_NAME: (optional) the browser name
  • VERSION: (optional) the browser version
  • PLATFORM: (optional) the operating system or device
  • RESOLUTION: (optional) the viewport size

4. Using visual testing

Test class: VisualSnapshotTest

Extra setup:

  • You must have an Applitools account, which you can register for free
  • You can change the cross-browser configurations in the setUpVisualAI method
  • Test results will appear in the Applitools dashboard
    • The first time you run tests will save baseline snapshots
    • The second time you run tests will compare the latest snapshots against baselines
    • Change DEMO_SITE from original to changed to introduce visual bugs

Environment variables:

  • APPLITOOLS_API_KEY: your Applitools API key
  • DEMO_SITE: (optional) original or changed; the changed site introduces visual bugs

cbt-4-ways-java's People

Contributors

automationpanda avatar

Watchers

 avatar  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.