Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

Add integration test use case to Examples section in README #24

Open
dlisboa opened this issue Jul 26, 2017 · 2 comments
Open

Add integration test use case to Examples section in README #24

dlisboa opened this issue Jul 26, 2017 · 2 comments

Comments

@dlisboa
Copy link

dlisboa commented Jul 26, 2017

Since running integration tests in parallel is one of the great benefits of the project it'd be good to have a small example showing how it can be done. The examples available right now enlighten the uses in automation and scraping, but not so much on tests.

@chebyte
Copy link

chebyte commented Aug 2, 2017

anyone knows how run many instances in parallel?

@adieuadieu
Copy link
Collaborator

While we don't yet have a "recommended" way, here are two options. Both assume you're running the tests over the Proxy.:

  1. Write tests with a test runner that supports concurrent execution (e.g. ava --concurrency <num>, jest--maxWorkers=<num>). Then write any number of tests, for example:
import test from 'ava'
import Chromeless from 'chromeless'

test('google title', async t => {
  const chromeless = new Chromeless({ remote: true })
  const title = await chromeless
    .goto('https://www.google.com')
    .evaluate(() => document.title)

  await chromeless.end()

  t.is(title, 'Google')
})

Then:

export CHROMELESS_ENDPOINT_URL=https://XXXXX.execute-api.eu-west-1.amazonaws.com/dev
export CHROMELESS_ENDPOINT_API_KEY=mulolKOvmeowIaqEC6Azs9Csausages2lCychahal
ava

This first method is used by Graphcool for integration tests on in-production code. You can see a work-in-progress example of this in their Console repository. You'll start seeing these types of tests more within this repository as we improve our test coverage.

  1. Initialise a Chromeless instance n-times that you need it. For example, here's a hacky way I test the Proxy's parallelisation:
const Chromeless = require('chromeless').default

async function run() {
  const chromeless = new Chromeless({
    remote: {
      endpointUrl: 'https://XXXXX.execute-api.eu-west-1.amazonaws.com/dev',
      apiKey: 'mulolKOvmeowIaqEC6Azs9Csausages2lCychahal',
    },
    debug: true,
  })

  const screenshot = await chromeless
    .goto('https://www.google.com')
    .type('chromeless', 'input[name="q"]')
    .press(13)
    .wait('#resultStats')
    .screenshot()

  console.log(screenshot) // prints local file path or S3 url

  await chromeless.end()
}

const concurrency = 1 // increase this to run multiple at once. May cause unexpected AWS usage billing if you're not careful.

for (var i = 0; i < concurrency; i++) {
  run().catch(console.error.bind(console))
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants