Git Product home page Git Product logo

percy-webdriverio's Introduction

@percy/webdriverio

Version Test

Percy visual testing for WebdriverIO.

Installation

$ npm install --save-dev @percy/cli @percy/webdriverio

Usage

This is an example using the percySnapshot() function in async mode.

const percySnapshot = require('@percy/webdriverio');

describe('webdriver.io page', () => {
  it('should have the right title', async () => {
    await browser.url('https://webdriver.io');
    await expect(browser).toHaveTitle('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js');
    await percySnapshot('webdriver.io page');
  });
});

Running the test above will result in the following log:

$ wdio wdio.conf.js
...

[...] webdriver.io page
[percy] Percy is not running, disabling snapshots
[...]    ✓ should have the right title

...

When running with percy exec, and your project's PERCY_TOKEN, a new Percy build will be created and snapshots will be uploaded to your project.

$ export PERCY_TOKEN=[your-project-token]
$ percy exec -- wdio wdio.conf.js
[percy] Percy has started!
[percy] Created build #1: https://percy.io/[your-project]
[percy] Running "wdio wdio.conf.js"
...

[...] webdriver.io page
[percy] Snapshot taken "webdriver.io page"
[...]    ✓ should have the right title

...
[percy] Stopping percy...
[percy] Finalized build #1: https://percy.io/[your-project]
[percy] Done!

Standalone mode

When using WebdriverIO in standalone mode, the browser object must be provided as the first argument to the percySnapshot function.

const { remote } = require('webdriverio');
const percySnapshot = require('@percy/webdriverio');

(async () => {
  const browser = await remote({
    logLevel: 'trace',
    capabilities: {
      browserName: 'chrome'
    }
  });

  await browser.url('https://duckduckgo.com');

  const inputElem = await browser.$('#search_form_input_homepage');
  await inputElem.setValue('WebdriverIO');

  const submitBtn = await browser.$('#search_button_homepage');
  await submitBtn.click();

  // the browser object is required in standalone mode
  percySnapshot(browser, 'WebdriverIO at DuckDuckGo');

  await browser.deleteSession();
})().catch((e) => console.error(e));

Configuration

percySnapshot(name[, options])

percySnapshot(browser, name[, options]) (standalone mode only)

Upgrading

Automatically with @percy/migrate

We built a tool to help automate migrating to the new CLI toolchain! Migrating can be done by running the following commands and following the prompts:

$ npx @percy/migrate
? Are you currently using @percy/webdriverio? Yes
? Install @percy/cli (required to run percy)? Yes
? Migrate Percy config file? Yes
? Upgrade SDK to @percy/[email protected]? Yes

This will automatically run the changes described below for you.

Manually

If you're coming from a pre-2.0 version of this package, the percySnapshot function is now the default export, and the browser argument is now only required when used in standalone mode.

// before 
const { percySnapshot } = require('@percy/webdriverio');
await percySnapshot(browser, 'Snapshot name', options);

// after
const percySnapshot = require('@percy/webdriverio');
await percySnapshot('Snapshot name', options);

// in standalone mode, browser is still required
await percySnapshot(browser, 'Snapshot name', options);

Migrating Config

If you have a previous Percy configuration file, migrate it to the newest version with the config:migrate command:

$ percy config:migrate

percy-webdriverio's People

Contributors

amit3200 avatar anaulin avatar bstack-security-github avatar cadeparade avatar chinmay-browserstack avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar djones avatar fotinakis avatar itsjwala avatar jardakotesovec avatar joscha avatar kaelig avatar maprules1000 avatar mfazekas avatar prklm10 avatar robdel12 avatar samarsault avatar semantic-release-bot avatar shantanuk-browserstack avatar timhaines avatar wwilsman avatar zoramite 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

percy-webdriverio's Issues

Standalone support

We use WebdriverIO in standalone mode for our browser tests, along with Spectron (which uses WebdriverIO underneath) for testing our Electron-based desktop apps. Is it on the road map to make this compatible with WDIO standalone? The idea behind Percy is great, and it would be nice to have the option of leveraging it as a drop-in module with config via CLI arguments, in addition to plugging into various tools directly.

TypeError: webdriverio_1.default is not a function using webdriverIO 7 and percy 2

I get this error using webdriverio v7 and latest Percy for visual testing:

[0-2] Error in "0: I can see page "Product Detail Page of the last product""
TypeError: webdriverio_1.default is not a function
    at C:\WORK\AutomationPlayground\domain-work\webdriverio-tutorial-demo\src\step_definitions\visual\visual-steps.ts:7:45
    at Browser.call (C:\WORK\AutomationPlayground\domain-work\webdriverio-tutorial-demo\node_modules\webdriverio\build\commands\browser\call.js:43:16)
    at Browser.runCommandWithHooks (C:\WORK\AutomationPlayground\domain-work\webdriverio-tutorial-demo\node_modules\@wdio\sync\build\wrapCommand.js:105:34)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Browser.runCommandWithHooks (C:\WORK\AutomationPlayground\domain-work\webdriverio-tutorial-demo\node_modules\@wdio\sync\build\wrapCommand.js:100:24)
    at Browser.wrapCommandFn (C:\WORK\AutomationPlayground\domain-work\webdriverio-tutorial-demo\node_modules\@wdio\sync\build\wrapCommand.js:67:44)
    at World.<anonymous> (C:\WORK\AutomationPlayground\domain-work\webdriverio-tutorial-demo\src\step_definitions\visual\visual-steps.ts:7:13)
    at World.executeSync (C:\WORK\AutomationPlayground\domain-work\webdriverio-tutorial-demo\node_modules\@wdio\sync\build\index.js:38:22)
    at C:\WORK\AutomationPlayground\domain-work\webdriverio-tutorial-demo\node_modules\@wdio\sync\build\index.js:69:68  

It doesn't even get to percy, so there is no screenshot there.
All I do in the code is taking screenshot of the page:

import percySnapshot from '@percy/webdriverio';
import { Then } from '@cucumber/cucumber';
Then(/^I can see page "([^"]*)"$/, (name: string) => {
  browser.waitForPageToLoad();
  browser.call(() => percySnapshot(name));
});  

This is my package.json file:

"devDependencies": {
    "@cucumber/cucumber": "^7.1.0",
    "@percy/cli": "^1.0.0-beta.48",
    "@percy/webdriverio": "^2.0.0",
    "@types/chai": "^4.2.16",
    "@types/node": "^14.14.41",
    "@typescript-eslint/eslint-plugin": "^4.22.0",
    "@typescript-eslint/parser": "^4.22.0",
    "allure-commandline": "^2.13.8",
    "app-root-path": "^3.0.0",
    "chai": "^4.3.4",
    "eslint": "^7.24.0",
    "eslint-config-prettier": "^8.2.0",
    "eslint-plugin-prettier": "^3.4.0",
    "husky": "^6.0.0",
    "npm-run-all": "^4.1.5",
    "prettier": "^2.2.1",
    "ts-node": "^9.1.1",
    "tsconfig-paths": "^3.9.0",
    "typescript": "^4.2.4",
    "webdriverio": "^7.4.6"
  },
  "dependencies": {
    "@wdio/allure-reporter": "^7.4.2",
    "@wdio/cli": "^7.4.6",
    "@wdio/cucumber-framework": "^7.4.6",
    "@wdio/local-runner": "^7.4.6",
    "@wdio/selenium-standalone-service": "^7.4.2",
    "@wdio/spec-reporter": "^7.4.3",
    "@wdio/sync": "^7.4.6"
  }

Note:
This used to work prior upgrading to webdriverIO v7 and percy v2.

Percy exec stuck forever

Version: "@percy/webdriverio": "1.0.4"

Im running percy the way that it's described in the docs. By using "percy exec -- wdio run wdio.conf.js". However, I noticed that sometimes the build is getting stuck forever when percy is stopping.

Here are some logs from the CI

Spec Files:   15 passed, 2 failed, 17 total (100% completed) in 00:18:59 

16:53:59
[36m [0m
16:53:59
[percy] stopping percy... [36m[ [35mpercy [39m] stopping percy... [0m
16:53:59
[percy] waiting for 73 snapshots to complete...

How do I go about fixing this issue? I've already tried setting the maxInstances to 1 so that nothing runs in parralel

[percy] Encountered an error uploading snapshot:

I am trying to integrate Visual Regression Testing using Percy in WebdriverIO Browser framework.
Following SDK, I am using in my code.
const percySnapshot=require('@percy/webdriverio');
.....
Package.json
"devDependencies": {
"@percy/cli": "^1.27.3",
"@percy/webdriverio": "^3.0.1",............}

TestCase
const percySnapshot=require('@percy/webdriverio');
describe('visual test with Percy', async () => {
it('HomePage', async () => {
await browser.url("https://www.amazon.in/")
await expect(browser).toHaveUrl("https://www.amazon.in/")
await expect(browser).toHaveUrlContaining("https://www.amazon.in/");
await percySnapshot('amazon Home Page')
})
})

My test case is getting executed when run induvial. When I try to run my testcase with percy with following cmd
npx percy exec wdio run ./wdio.conf.js

I am getting log in my test case as snapshot taken however failed to upload.
[percy] Snapshot taken: amazon Home Page
.
.
.
[percy] Encountered an error uploading snapshot: amazon Home Page
[percy] Error: Cannot finalize snapshots in app builds. Did you mean to call comparison finalize?
[percy] Error: Finalizing build 30743767 failed: cannot finalize before all snapshots have comparisons created. This is likely
an SDK error, please make sure that comparisons are created before calling finalize.

Console warning when no screenshots were taken

If none of my calls to browser.percySnapshot ever get called (which is conceivable if test's assertions are failing) the following error is printed to the console:

TypeError: Cannot read property 'then' of undefined
    at Object.wait (*\node_modules\fibers\future.js:449:15)
    at Object.percyFinalizeBuild (*\node_modules\wdio-sync\build\index.js:287:31)
    at Object.after (*\wdio.conf.js:236:17)
    at execHook (*\node_modules\wdio-sync\build\index.js:166:35)
    - - - - -
    at percyFinalizeBuild() - *\node_modules\wdio-sync\build\index.js:267:37
    at execute(<Function>) -     at *\node_modules\wdio-sync\build\index.js:316:3

This isn't blocking anything for me that i'm aware of, just wanted to raise it as a potential issue

[percy:webdriverio] Could not take DOM snapshot

I am using the below node version and other details

@percy/webdriverio": "^2.0.0"
"@percy/cli": "^1.0.0-beta.76"
node: v14.16.1
npm: 7.20.5
@cucumber/cucumber:7.3.1
[email protected]

Issue: With WDIO,trying to get percy working throws up the error

[percy:webdriverio] Could not take DOM snapshot "test_screenshot" (59928ms)
Below are the verbose logs

[percy:webdriverio] Could not take DOM snapshot "testing" (59928ms)
[percy:webdriverio] Cannot read property 'element-6066-11e4-a52e-4f735466cecf' of undefined
TypeError: Cannot read property 'element-6066-11e4-a52e-4f735466cecf' of undefined
at \node_modules\devtools\build\utils.js:153:16
at Array.map ()
at DevToolsDriver.transformExecuteArgs (********\node_modules\devtools\build\utils.js:152:29)
at DevToolsDriver.executeScript (\node_modules\devtools\build\commands\executeScript.js:29:179)
at Browser.wrappedCommand (
\node_modules\devtools\build\devtoolsdriver.js:102:55)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Browser.wrapCommandFn (
\node_modules@wdio\utils\build\shim.js:104:29)
at Browser.wrapCommandFn (
*********\node_modules@wdio\utils\build\shim.js:104:29)
at **\node_modules@percy\webdriverio\index.js:26:34
at Browser.wrapCommandFn (
\node_modules@wdio\utils\build\shim.js:104:29) (1ms)

Command to run the Percy Tests:

npx percy exec --verbose -- wdio dist\config\wdio.conf.js

I am using WDIO with Devtools protocol

Receiving empty screenshots

I've been dealing with this issue for the last 2 days. For some reason Percy is capturing empty screenshots.

This is one example:

Screenshot 2021-05-27 at 19 11 58

The code is quite simple

before(async function beforeAll() {
  this.timeout(loadWebsiteTimeout);
  await NavigateToUrlAndWaitUntilLoaded('/buy/bmw');
  await percySnapshot('clp - bmw');
});

Inside the navigate method

export const NavigateToUrlAndWaitUntilLoaded = async (url) => {
  await browser.url(url);
  await browser.waitUntil(() => $('.next-body').isExisting(), loadWebsiteTimeout);
}

There are no errors in the webdriver tests.

how to run percysnapshot() synchromusly

Hi Team,

I am running webdriverio tests in synchronous mode and when I am using percySnapshot() without await it is running asynchronously and creating a problem.

My use case:
on-page there are multiple images and I want to take a screenshot once all the images are loaded.
So to achieve that I have written below piece of code.

`snapShot(element, name) {
if (type == 'visual') {
element.waitForDisplayed({
timeout: config.elementTimeout,
});

  browser.waitUntil(function () {
    let resultStatus = false;
    let imagesCount = browser.execute(() => {
      return document.images.length;
    });
    console.log(`count is: ${imagesCount} `);
    let allLoaded = false;
    while (!allLoaded) {
      let count = 0;
      for (let i = 0; i < imagesCount; i++) {
        let loaded = browser.execute(i1 => {
          return document.images[i1].complete;
        }, i);

        if (loaded) count++;
        console.log(`total count: ${count}`);
      }
      // Breaking the while loop if all the images loading completes
      if (count == imagesCount) {
        console.log('=> All the Images are loaded...');
        console.log(`=>total count: ${count}`);
        resultStatus = true;
        break;
      } else {
        console.log('=> Not yet loaded...');
        console.log(`=>total not count: ${count}`);
        count = 0;
      }
      this.wait(2000);
      // setTimeout(waitUntilAllImageLoaded(), 300);
    }
    return resultStatus;
  });
  browser.percySnapshot(name);
}

}
`
still i can see screenshot without images. I beleive its because percySnapshot is running asynchronously.

Could u please help me to run percySnapshot synchronously.

404 when using enableJavaScript

Bit of a strange one, but have two URL's where the same code is deployed. One just happens to be behind a proxy.

For example

This code works just fine on the front-end application, but returns a 404 when I run it on the proxy URL.

  percySnapshot(name, {
    enableJavaScript: true,
    widths: [375, 414, 768, 1024, 1280],
  })

It only works when I remove the enableJavaScript flag

  percySnapshot(name, {
    widths: [375, 414, 768, 1024, 1280],
  })

This is what appears in my Percy test run, have to hide the URL's unfortunately.

b78c803feca08618c9f111ff7b5883a267cec37076311539fa99a6afab8b1737

It's most peculiar and I don't know where to start with this. Do any of the maintainers have any insight?

I'm using these packages:

"@percy/cli": "1.0.0-beta.50",
"@percy/storybook": "3.3.1",  <-- not being used in this scenario
"@percy/webdriverio": "2.0.0",

Percy dont receive screenshot from CircleCi

I can run Percy locally but when I commit to GitHub and CircleCi starting pull code and execute jobs, Percy don't get screenshots
even it shows there snapshots

[percy] stopping percy...
[percy] waiting for 1 snapshots to complete...
[percy] done.
[percy] finalized build #55: https://percy.io/TechMode/CircleCi_test/builds/2618111

Ability to make percy a no-op for local builds.

I may be missing something from the docs or something obvious, but it would be nice to be able to have the ability to configure percy to be a no-op when running tests locally.

For example:

// wdio.local.config.js
var percy = require('@percy-io/percy-webdriverio');

// Some method to make percy no do anything.
percy.noop();

// The config stays the same, but it ignores the requirement for percy tokens
// and any `browser.percySnapshot('Homepage')` are just ignored or logged 
// as being ignored.
// Also the `percy.createBuild(assetLoaders)` and `percy.finalizeBuild()` are 
// minimal no-ops.
exports.config = require('./wdio.conf.js');

Then when writing and debugging tests I can use the local config:

wdio wdio.local.conf.js

Could not take DOM snapshot WDIO v7

Hi I am trying to setup Percy with our application and having made the call under a sync cucumber step:

Home_Page.homePageIsVisible();
         browser.call(
            () => percySnapshot('Home Page')
        );

I am getting the following when running the test.

[percy] Could not take DOM snapshot "Home Page"
[percy] [object Object]

Would you have any idea why this might be the case?

I have installed:

"@percy/cli": "^1.0.0-beta.50",
   "@percy/webdriverio": "^2.0.0",

"@wdio/allure-reporter": "^6.11.0",
   "@wdio/cli": "^7.2.3",
   "@wdio/config": "^7.2.1",
   "@wdio/cucumber-framework": "^7.2.1",
   "@wdio/local-runner": "^7.2.3",
   "@wdio/selenium-standalone-service": "^7.2.1",
   "@wdio/spec-reporter": "^7.2.1",
   "@wdio/static-server-service": "^7.2.1",
   "@wdio/sync": "^7.2.3",

Thanks in advance

[percy] Unsupported Percy CLI version, disabling snapshots.Please help its blocker for me

I am trying to integrate Visual Regression Testing using Percy in Mobile automation with Appium and WebdriverIO framework.
Following SDK, I am using in my code.
const percySnapshot=require('@percy/webdriverio');

package.json
"devDependencies": {
"@percy/appium-app": "^2.0.1",
"@percy/appium-wd": "^0.3.0",
"@percy/cli": "^1.27.3",
"@percy/cli-app": "^1.27.3",
"@percy/webdriverio": "^3.0.1",

TestCase
const percySnapshot=require('@percy/webdriverio');
const LoginScreen = require("../../screenobjects/android/login.screen.js")
const ProfilePage = require("../../screenobjects/android/profile.page.js")
describe('sample', async () => {
it('User Preferences for communication and User avaibility on Profile page', async () => {
await driver.pause(10000);
await LoginScreen.loginBtn.click();
await driver.pause(20000);
await ProfilePage.userPreferencesArrow.click();
await percySnapshot('webdriverPage');
await driver.pause(15000);
})
})
Following test script work when running without Percy.
When I try to run my testcase with percy with following cmd
npx percy exec wdio config\wdio.android.conf.js

I am getting log in my test case as
[percy] created build #40: https://percy.io/bfd0c1e6/webdriverio-visual/builds/30744549
[percy] percy has started.
........
[percy] Unsupported Percy CLI version, disabling snapshots
............
"spec" Reporter:

[RZ8N919VG9V Android 12 #0-0] Running: RZ8N919VG9V on Android 12 executing C:\Users\GharatLa\Repository\project\leadx\webdriverio-appium-v8\app\android\application-2d021449-ab[RZ8N919VG9V Android 12 #0-0]
[RZ8N919VG9V Android 12 #0-0] » \test\specs\android\login-screen.specs.js
[RZ8N919VG9V Android 12 #0-0] sample
[RZ8N919VG9V Android 12 #0-0] - Edit your Profile details for
[RZ8N919VG9V Android 12 #0-0] ✓ User Preferences for communication and User avaibility on Profile page
[RZ8N919VG9V Android 12 #0-0] - User skills or technology on Profile page
[RZ8N919VG9V Android 12 #0-0] - View Dashboard on Profile page
[RZ8N919VG9V Android 12 #0-0]
[RZ8N919VG9V Android 12 #0-0] 1 passing (52.1s)
[RZ8N919VG9V Android 12 #0-0] 3 skipped

Spec Files: 1 passed, 1 total (100% completed) in 00:01:29

2023-10-20T07:31:04.832Z INFO @wdio/local-runner: Shutting down spawned worker
2023-10-20T07:31:05.098Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2023-10-20T07:31:05.101Z INFO @wdio/local-runner: shutting down
[percy] stopping percy...
[percy] waiting for 0 snapshots to complete...
[percy] done.
[percy] finalized build #40: https://percy.io/bfd0c1e6/webdriverio-visual/builds/30744549

waiting for 0 snapshots to complete...

I tried to integrate Percy with CircleCi
I set the Percy_token on the environment variable

here is the whole yml script

version: 2.1

default_test_steps: &default_test_steps

  working_directory: ~/repo/cats-client
  steps:
    - checkout:
        path: ~/repo
    - run: yarn
    - run: yarn test

jobs:
  test_node_8:
    docker:
      - image: circleci/node:8-browsers

    environment:
      PERCY_ENABLE: 0
    <<: *default_test_steps
  test_node_10_with_percy:
    # We've opted this node version to be the one that runs and reports Percy's status
    docker:
      - image: circleci/node:10-browsers
    <<: *default_test_steps
  release:
    docker:
      # specify the version you desire here
      - image: circleci/node:8

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo/cats-client

    steps:
      - checkout:
          path: ~/repo

      - run: yarn
      - run: npx semantic-release

workflows:
  version: 2.1
  test_and_release:
    jobs:
      - test_node_8
      - test_node_10_with_percy
      - release:
          requires:
            - test_node_8
            - test_node_10_with_percy

my test code

const assert = require("assert");
const { percySnapshot } = require("@percy/webdriverio");

describe("webdriver.io page", () => {
 
  it("should have the right title", () => {
    browser.url("https://webdriver.io");
    percySnapshot(browser, "sample");
    browser.getTitle().then(function(title) {
      assert.strictEqual(
        title,
        "WebdriverIO · Next-gen WebDriver test framework for Node.js"
      );
    });
  });
});

what I am missing

Typescript compilation error: BrowserObject

I'm using @percy/webdriverio in a project written in Typescript and whenever I compile, I get this error:

node_modules/@percy/webdriverio/dist/index.d.ts:7:48 - error TS2304: Cannot find name 'BrowserObject'.  7 export declare function percySnapshot(browser: BrowserObject, name: string, options?: any): Promise<void>;

My tsconfig.json file:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "baseUrl": ".",
    "paths": {
      "*": ["src", "pages"]
    },
    "sourceMap": false,
    "types": ["node", "webdriverio"]
  },
  "exclude":[],
  "include": [
    "src/**/*.spec.ts",
    "**/*.ts"
  ]
}

I'm using @percy/webdriverio 1.0.2, webdriverio 5.12.5.

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.