Skip to content

Files

Latest commit

 

History

History
316 lines (222 loc) · 13.8 KB

playwright-junit-on-hyperexecute.md

File metadata and controls

316 lines (222 loc) · 13.8 KB
id title hide_title sidebar_label description keywords url site_name slug
playwright-junit-on-hyperexecute
Run playwright automation tests on HyperExecute using JUnit
true
JUnit
Learn how to run playwright automation tests on HyperExecute using JUnit framework
unittest
unittest selenium
python selenium
unit testing
unit testing tutorial
python unit testing
python automation testing
selenium webdriver python
selenium python testing tutorial
python selenium framework
selenium
selenium automation testing
selenium testing tool
selenium testing tutorial
hyperexecute
hyperexecute pyunit testing
hyperexecute automation testing
hyperexecute pyunit testing
hyperexecute python testing
LambdaTest
playwright-junit-on-hyperexecute/

import CodeBlock from '@theme/CodeBlock'; import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys";

<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify({ "@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{ "@type": "ListItem", "position": 1, "name": "Home", "item": "https://www.lambdatest.com" },{ "@type": "ListItem", "position": 2, "name": "Support", "item": "https://www.lambdatest.com/support/docs/" },{ "@type": "ListItem", "position": 3, "name": "How to run playwright automation tests on HyperExecute using JUnit framework", "item": "https://www.lambdatest.com/support/docs/playwright-junit-on-hyperexecute/" }] }) }} ></script>

Running JUnit Framework Tests on HyperExecute

JUnit is a widely-used testing framework for Java applications, designed to simplify and enhance the testing process for developers. It provides a flexible and powerful platform for running test suites, enabling effective unit testing, integration testing, and end-to-end testing of Java applications

HyperExecute is an AI Native Test Orchestration Cloud Platform that empowers you to run end-to-end tests quickly and efficiently. It provides Just-in-Time (JIT) testing infrastructure with fast execution speeds, smart orchestration, and detailed logs.

This guide details how to execute your JUnit framework tests on HyperExecute via two different methods:

1. Testing Using Local System

Follow the step-by-step guide to execute your test on HyperExecute.

Prerequisites

To run the Tests on HyperExecute from your Local System, you are required:

Step 1: Configure Your Test Suite

You can use your own project to configure and test it. For demo purposes, we are using the sample repository.

:::tip Sample repo

Download or Clone the code sample for the JUnit from the LambdaTest GitHub repository to run the tests on the HyperExecute.

<img loading="lazy" src={require('../assets/images/icons/github.png').default} alt="Image" className="doc_img"/> View on GitHub

:::

If you are using your own project, make sure you update the Hub endpoint in your tests file.

By setting up the Hub endpoint, you establish the communication channel between your tests and the browser nodes, enabling effective test distribution and execution.

You can also use dev and beta browser versions. To generate capabilities for your test requirements, you can use our inbuilt 🔗 Capabilities Generator Tool.

Step 2: Setup the CLI in your Test Suite

After cloning / downloading the sample repo, you need to setup the CLI and the environment variables.

Download the HyperExecute CLI

The CLI is used for triggering the tests on HyperExecute. It is recommend to download the CLI binary on the host system and keep it in the root directory of the suite to perform the tests on HyperExecute.

You can download the CLI for your desired platform from the below mentioned links:

Platform HyperExecute CLI
Windows https://downloads.lambdatest.com/hyperexecute/windows/hyperexecute.exe
MacOS https://downloads.lambdatest.com/hyperexecute/darwin/hyperexecute
Linux https://downloads.lambdatest.com/hyperexecute/linux/hyperexecute

Setup Environment Variable

Now, you need to export your environment variables LT_USERNAME and LT_ACCESS_KEY that are available in the LambdaTest Profile page.

Run the below mentioned commands in your terminal to setup the CLI and the environment variables.

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

{`export LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" export LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`}
{`set LT_USERNAME="${ YOUR_LAMBDATEST_USERNAME()}" set LT_ACCESS_KEY="${ YOUR_LAMBDATEST_ACCESS_KEY()}"`}

Step 3: Configure YAML in your Test Suite

Configure your YAML file as per your use cases using key value pairs.

In this sample YAML file, we have mentioned:

  • version of the YAML file
  • Timeouts for executing your project
  • Mode of execution is Autosplit. You can also opt for Matrix or Hybrid mode.
  • Pre and Post commands
  • Reports and Artefacts that will be generated after the completion of tests
  • and other necessary YAML Parameters
---
version: 0.1
globalTimeout: 150
testSuiteTimeout: 150
testSuiteStep: 150

runson: linux

autosplit: true
retryOnFailure: false

maxRetries: 1
concurrency: 1

env:
  # PAT: ${{ .secrets.testKey }}
  CACHE_DIR: m2_cache_dir
  TARGET_OS: linux

cacheKey: '{{ checksum "pom.xml" }}'
cacheDirectories:
  - ${CACHE_DIR}

shell: bash

pre:
  # install playwright version to be used.
  - npm install playwright@1.23.0 --save-exact
  # Download and install packages in the CACHE_DIR.
  # Skip execution of the tests in the pre step
  - mvn -Dmaven.repo.local=${CACHE_DIR} -Dmaven.test.skip=true clean install

post:
  - cat yaml/linux/junit_hyperexecute_autosplit_sample.yaml

mergeArtifacts: true

uploadArtefacts:
 - name: Surefire-Report
   path:
    - target/surefire-reports/**

testDiscovery:
  type: raw
  mode: dynamic
  command: grep 'public class' src/test/java/SampleTest.java | awk '{print$3}'

testRunnerCommand: mvn -Dplatname=linux -Dmaven.repo.local=m2_cache_dir -Dtest=$test test surefire-report:report

jobLabel: [playwright-Junit, linux, autosplit] 

Step 4: Execute your Test Suite

NOTE : In case of MacOS, if you get a permission denied warning while executing CLI, simply run chmod u+x ./hyperexecute to allow permission. In case you get a security popup, allow it from your System PreferencesSecurity & PrivacyGeneral tab.

Run the below command in your terminal at the root folder of the project:

./hyperexecute --config RELATIVE_PATH_OF_YOUR_YAML_FILE

OR use this command if you have not exported your username and access key in the step 2.

{`./hyperexecute --user ${ YOUR_LAMBDATEST_USERNAME()} --key ${ YOUR_LAMBDATEST_ACCESS_KEY()} --config RELATIVE_PATH_OF_YOUR_YAML_FILE `}

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/selenium/testng/cmd_1.png').default} alt="JUnit HyperExecute Terminal Logs" width="1920" height="868" className="doc_img"/>

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/selenium/testng/cmd_2.png').default} alt="JUnit HyperExecute Terminal Logs" width="1920" height="868" className="doc_img"/>

Step 5: Monitor the Test Execution

Visit the HyperExecute Dashboard and check your Job status.

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/selenium/testng/testng_autosplit_1.png').default} alt="automation-dashboard" width="1920" height="868" className="doc_img"/>

Step 6: Download Artifacts and Reports

HyperExecute also facilitates the provision to download the Artifacts and Reports on your local machine. Click on the corresponding button to download your generated artifacts and reports.

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/selenium/testng/testng_autosplit_2.png').default} alt="automation-dashboard" width="1920" height="868" className="doc_img"/>

2. Testing Using Gitpod

You can also use the Gitpod platform to execute our sample repository. It will fetch all the sample codebases and trigger the CLI to execute the tests.

Follow the below steps to run Test using Gitpod:

Step 1: Click 'Open in Gitpod' button. You will be redirected to Login/Signup page. This button is configured to redirect you to the Gitpod platform where you will be able to execute our sample repository.

Run in Gitpod

Step 2: Login with LambdaTest credentials. Once logged in, a pop-up confirmation will appear, asking you to 'Proceed' to the Gitpod editor in a new tab. The current tab will display the HyperExecute Dashboard.

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/gitpod_popup.png').default} alt="Gitpod popup" width="1919" height="878" className="doc_img"/>

Step 3: Choose your preferred editor (we recommend VS Code Editor)

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/gitpod_config.png').default} alt="Image" className="doc_img"/>

Step 4: As you are running a sample project, Fetching of the Test Scripts, HyperExecute YAML, HyperExecute CLI and Triggering your tests using the Execution Command will be automated.

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/gitpod2.png').default} alt="Image" className="doc_img"/>

Step 5: Once you see the Job Link in the logs, you can visit the HyperExecute dashboard to see the tests getting executed.

:::tip

You can also implement Secret Keys in your YAML file. :::

Navigation in Automation Dashboard

Every test run on the HyperExecute has a unique jobId associated with it. Each jobId can in turn constitute single (or multiple) groupId(s). You can visit HyperExecute Automation Dashboard for checking the status of the test execution.

You can seamlessly navigate between JobId's and taskId's. You need to click on the testID to navigate from the HyperExecute logs to the Automation Dashboard.

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/selenium/testng/testng_autosplit_1.png').default} alt="automation-dashboard" width="1920" height="868" className="doc_img"/>

The snapshot below shows the videos, logs and other meta data for that specific test_ID

<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/selenium/testng/testng_artifacts_2.png').default} alt="automation-dashboard" width="1920" height="868" className="doc_img"/>

For any query or doubt, please feel free to contact us via <span className="doc__lt" onClick={() => window.openLTChatWidget()}>24×7 chat support or you can also drop a mail to support@lambdatest.com.
Happy testing!