Coder Social home page Coder Social logo

smartui-jest-puppeteer-sample's Introduction

LambdaTest SmartUI Puppeteer Jest Sample

This project demonstrates how to use Puppeteer, Jest, and LambdaTest together to run automated tests on the LambdaTest platform.

Setup

First, clone this repository to your local machine.

git clone https://github.com/LambdaTest/smartui-jest-puppeteer-sample.git
cd smartui-jest-puppeteer-sample

Next, install the necessary dependencies:

npm i

You'll need to set your LambdaTest username and access key as environment variables. They can be found on your LambdaTest profile.

export LT_USERNAME="Your LambdaTest Username"
export LT_ACCESS_KEY="Your LambdaTest Access Key"

About the Test

The test navigates to the LambdaTest homepage and checks the page title. After the title check, it will take a full-page screenshot for visual regression testing.

About SmartUI Webhook

LambdaTest's SmartUI uses a webhook to call the smartui.takeScreenshot function. This function captures a screenshot of the full page and uses it for visual regression testing. The function is called using the page.evaluate method with the lambdatest_action parameter.

Here's an example of how to use the smartui.takeScreenshot function:

await page.evaluate((_) => { },
    `lambdatest_action: ${JSON.stringify({ 
        action: "smartui.takeScreenshot", 
        arguments: { 
            fullPage: true, 
            screenshotName: "<Your Screenshot Name>" 
        } })}
    `);

Replace <Your Screenshot Name> with a relevant name for the screenshot. The screenshot will be saved with this name in the LambdaTest platform, and you can use it for comparing the UI changes over time.

Running Tests

To run the test, execute:

npm test

Troubleshooting

If you encounter the error Exceeded timeout of 5000 ms for a hook, try increasing the default timeout for Jest. You can do this by adding jest.setTimeout(30000); to the top of your test file.

smartui-jest-puppeteer-sample's People

Contributors

srivishnua-lambdatest avatar sushobhit-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.