How to use the @percy/agent/dist/utils/sdk-utils.isAgentRunning function in @percy/agent

To help you get started, we’ve selected a few @percy/agent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github percy / percy-webdriverio / lib / index.ts View on Github external
export async function percySnapshot(browser: any, name: string, options: any = {}) {
  if (!browser) {
    throw new Error("WebdriverIO 'browser' object must be provided.");
  }
  if (!name) {
    throw new Error("'name' must be provided. In Mocha, this.test.fullTitle() is a good default.");
  }

  if (! await isAgentRunning()) {
     return
  }

  await browser.execute(fs.readFileSync(agentJsFilename()).toString(), []);

  // WebdriverIO v4 returns an object with the return value from the execute command
  // WebdriverIO v5 returns whatever is returned from the execute command
  const browserResult: any = await browser.execute((name: string, options: any) => {
    var percyAgentClient = new PercyAgent({ handleAgentCommunication: false });

    return percyAgentClient.snapshot(name, options);
  }, name, options);

  const resultIsString = typeof browserResult === "string";
  const domSnapshot = resultIsString ? browserResult : browserResult.value;

@percy/agent

An agent process for integrating with Percy.

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis