Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Getting started Doc #37

Open
ramyaa opened this issue Oct 27, 2017 · 6 comments
Open

Getting started Doc #37

ramyaa opened this issue Oct 27, 2017 · 6 comments

Comments

@ramyaa
Copy link

ramyaa commented Oct 27, 2017

Hi
Is there a simple getting started guide which has a "hello world" sample to use this mocha-pupeeteer?
Thanks
Ramya

@ctdio
Copy link
Owner

ctdio commented Oct 27, 2017

Hello @ramyaa, thanks for creating this issue!. At the moment I don't have a getting started guide for this project, but that is definitely something that should be added.

This module is designed to be easy to use. I wanted it to be simplistic, much like regular mocha, so things such as bundling are all handled for you.

To start, just create a test file and maybe call it something like test.js:

const assert = require('assert')

describe('my test', () => {
  it('should pass', () => {
    assert(1 + 1 === 2)
  })
})

Afterwards, install mocha-puppeteer and run either npx mocha-puppeteer test.js or ./node_modules/.bin/mocha-puppeteer test.js (use the latter if you are using a version of npm below 5.2.

The cli is quite different from regular mocha's cli, so I recommend checking the README to see what is supported.

Let me know if you have any questions!

@ramyaa
Copy link
Author

ramyaa commented Oct 31, 2017

Hi @charlieduong94 thanks for the explanation. Maybe im missing something very basic. when I do a " npx mocha-puppeteer test.js" - I see "Test server is listening on http://localhost:64594..." - What is this test server?
I want to test my webapp at localhost:3000. But when i give this command,

describe('screenshot test', function () {
  it('should take a screenshot', async () => {
    await window.puppeteerCommand({
      type: 'setViewport',
      args: [ {width: 1600, height: 1200} ]
    });
    await window.puppeteerCommand({
      type: 'goto',
      args: [{url: 'http://localhost:3000'}]
    })
  })
})

I get an error "(node:95200) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Protocol error (Page.navigate): Invalid parameters url: string value expected"

How can I navigate to http://localhost:3000 ?
Thanks!

@austinkelleher
Copy link
Collaborator

@ramyaa window.puppeteerCommand(...) accepts an args argument as you're defining in your above example. The problem is that args expects the exact arguments of whatever puppeteer function you're trying to execute. page.goto(...) expects a string for the first argument. You're passing it an object. I think the following will fix your problem:

await window.puppeteerCommand({
  type: 'goto',
  args: ['http://localhost:3000']
})

@ramyaa
Copy link
Author

ramyaa commented Oct 31, 2017

Hi @austinkelleher that was what I tried firstly, but it didnt work. I got the following error:
"(node:95264) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Converting circular structure to JSON"

So I thought it must be a JSON.

@ctdio
Copy link
Owner

ctdio commented Oct 31, 2017

@ramyaa If you are looking for a way to run assertions based off of content running on another page, it might be better to use standard mocha with puppeteer. That will give you the control and functionality you need.

This module was designed to be somewhat of a replacement for mocha-phantomjs (with some extra features) and runs your tests within the browser. Performing something like a goto within the test suite that mocha-puppeteer runs will cause issues since it will cause the current page to unload and all test context will be lost (chances are, the test server will end up hanging).

@nathancarter
Copy link

I'll second the need for a getting started doc. My primary question is just how to ensure that the scripts I'm trying to test are loaded into Chromium, so that my tests can actually call the functions I define in my to-be-tested code.

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

No branches or pull requests

4 participants