Giter Site home page Giter Site logo

webdriverio / chrome-recorder Goto Github PK

View Code? Open in Web Editor NEW
28.0 4.0 6.0 3.38 MB

Generate WebdriverIO Tests from Google Chrome DevTools Recordings.

Home Page: https://webdriver.io

License: MIT License

JavaScript 1.07% TypeScript 98.93%
chrome chrome-extension recorder wdio webdriverio

chrome-recorder's Introduction

WebdriverIO Chrome Recorder Build npm

This repo provide tools to convert JSON user flows from Google Chrome DevTools Recorder to WebdriverIO test scripts programmatically (WebdriverIO v7.24.0 or higher required).

โœ… Converts multiple recordings to WebdriverIO tests in one go (out-of-the-box glob support)
๐Ÿ—‚ User can pass their custom path to export tests.
๐Ÿ’ƒ Users can also use a dry run to see the interim output of the recordings
๐Ÿ‘จโ€๐Ÿ’ป Programmatic API which users can use in their own project to create plugins or custom scripts.

Alternatively, you can export JSON user flows as WebdriverIO test scripts straight away from Chrome DevTools with our WebdriverIO Recorder Chrome extension.

๐Ÿ— Installation

npm install -g @wdio/chrome-recorder

๐Ÿš€ Usage

To quickly run the interactive CLI, run:

npx @wdio/chrome-recorder

The CLI will prompt you to enter the path of directory or file of the chrome devtool recordings that you will modify and path to write the generated WebdriverIO tests

โšก๏ธ Transform individual recordings

npx @wdio/chrome-recorder <path to the chrome devtools recording>

โšก๏ธ Transform multiple recordings

npx @wdio/chrome-recorder <path to the chrome devtools recording>*.json

๐Ÿ‘‰ By default output will be written to webdriverio folder. If you don't have these folders, tool will create it for you or install WebdriverIO by running npm init webdriverio in your project.

You can specify different output directory, specify that via CLI:

npx @wdio/chrome-recorder <path to the chrome devtools recording> --output=<folder-name>

โš™๏ธ CLI Options

Option Description
-d, --dry Dry run the output of the transformed recordings
-o, --output Output location of the files generated by the exporter

๐Ÿ’ป Programmatic API

import { stringifyChromeRecording } from '@wdio/chrome-recorder';

const recordingContent = {
  title: 'recording',
  steps: [
    {
      type: 'setViewport',
      width: 1905,
      height: 223,
      deviceScaleFactor: 1,
      isMobile: false,
      hasTouch: false,
      isLandscape: false,
    },
  ],
};

const stringifiedContent = await stringifyChromeRecording(
  JSON.stringify(recordingContent),
);

console.log(stringifiedContent);
// Console Log output
//
// describe('recording', function () {
//   it('tests recording', function (browser) {
//     browser.setWindowRect({ width: 1905, height: 223 });
//   });
// });

๐Ÿ› Issues

Issues with this schematic can filed here

If you want to contribute (or have contributed in the past), feel free to add yourself to the list of contributors in the package.json before you open a PR!

๐Ÿ‘จโ€๐Ÿ’ป Development

Getting started

๐Ÿ› ๏ธ Node.js and npm are required for the scripts. Make sure it's installed on your machine.

โฌ‡๏ธ Install the dependencies for the WebdriverIO chrome recorder tool

npm install

๐Ÿ‘ทโ€โ™‚๏ธ Build the tools using typescript compiler

npm run build

๐Ÿƒ Run the tool

./bin/wdio-chrome-recorder.js

๐Ÿงช Unit Testing

Run the unit tests using mocha as a runner and test framework

npm run test

โ™ป๏ธ Clean build files

npm run clean

Supported Chrome Devtools Recorder Steps

WebdriverIO supports all existing StepTypes. If any step type seems to be missing, please raise an issue so we can add it. Thanks!


For more information on WebdriverIO see the homepage. The initial implementation was inspired by Nightwatch Chrome Recorder

chrome-recorder's People

Contributors

christian-bromann avatar dependabot[bot] avatar dilpreetj avatar jecfish avatar seanpoulter avatar wdio-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

chrome-recorder's Issues

Duration is not converted

When I use the duration parameter in Chrome Recorder, I'm not able to get this parameter when I convert the Json to the Webdriver script.

Is there a solution for that?

Regards

Update argument name for meow dependency

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch @wdio/[email protected] for the project I'm working on.

The dependency "meow" is throwing the following error:

Error: The option `alias` has been renamed to `shortFlag`. The following flags need to be updated: `--output`

Here is the diff that solved my problem:

diff --git a/node_modules/@wdio/chrome-recorder/dist/cli/index.js b/node_modules/@wdio/chrome-recorder/dist/cli/index.js
index 08484db..5e2999b 100644
--- a/node_modules/@wdio/chrome-recorder/dist/cli/index.js
+++ b/node_modules/@wdio/chrome-recorder/dist/cli/index.js
@@ -27,7 +27,7 @@ const cli = meow(`
         },
         output: {
             type: 'string',
-            alias: 'o',
+            shortFlag: 'o',
         },
     },
 });

This issue body was partially generated by patch-package.

Preference for ARIA Selector over XPath Selector

Currently, in the stringifyExtension.ts file, the code for converting JSON user flows into WebdriverIO test scripts prioritizes XPath selectors over ARIA selectors. However, it would be more desirable to have ARIA selectors as the preferred choice.

Steps to Reproduce:

  • Create a JSON user flow containing both ARIA and XPath selectors.
  • Convert the JSON user flow into a WebdriverIO test script using the chrome-recorder tool.

Expected Behavior:
The generated WebdriverIO test script should prefer ARIA selectors over XPath selectors when both are available.

Actual Behavior:
The current implementation in the getSelector() method of the StringifyExtension class prioritizes XPath selectors over ARIA selectors.

Proposed Solution:
Modify the getSelector() method in stringifyExtension.ts to prioritize ARIA selectors over XPath selectors. This change will ensure that the generated WebdriverIO test scripts use ARIA selectors when available as per the WebdriverIO selectors recommendation.

Add support for text and XPath selector

DevTools Recorder support text and XPath selector from Chrome 108 onwards. I am wondering if there are similar selector in WebdriverIO?

Here is the example step's json.

{
      "type": "click",
      "target": "main",
      "selectors": [
        [
          "aria/Proceed to checkout"
        ],
        [
          "[data-test=checkout]"
        ],
        [
          "xpath///*[@data-test=\"checkout\"]"
        ],
        [
          "text/Total: $0.00"
        ]
      ]
    }

Screen Shot 2022-10-16 at 9 35 19 AM

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.