utilities | verify human | | Search

The testVerify function is an asynchronous function that checks if a provided page parameter is falsy, sets it to a default value if so, navigates to the specified page using a Selenium driver, and calls the verifyHuman function to verify a user is human. The testVerify function is then exported as a module, making it available for use in other JavaScript files.

Run example

npm run import -- "test verify human"

test verify human

const getClient = importer.import("selenium client")
const verifyHuman = importer.import("verify human")

async function testVerify(page) {
  let driver = await getClient()

  if(!page) {
    page = 'https://medium.com/@hanton.yang/how-to-create-a-360-video-player-with-opengl-es-3-0-and-glkit-360-3f29a9cfac88'
  }

  await driver.get(page)

  return await verifyHuman()
}


module.exports = {
  testVerify
}

What the code could have been:

const { SeleniumClient } = require('selenium-client');
const VerifyHuman = require('verify-human');

const PAGE_URL = 'https://medium.com/@hanton.yang/how-to-create-a-360-video-player-with-opengl-es-3-0-and-glkit-360-3f29a9cfac88';

class VerifyPage {
  async verify(page = PAGE_URL) {
    const client = new SeleniumClient();
    try {
      await client.get(page);
      const human = new VerifyHuman();
      return await human.verify();
    } catch (error) {
      // Catch and log any errors that occur during the verification process
      globalThis.console.error(error);
      return false;
    } finally {
      // Close the selenium client to free up resources
      await client.quit();
    }
  }
}

module.exports = VerifyPage;

Code Breakdown

Imported Modules

testVerify Function

Module Exports