rosshinkley / nightmare-examples

Examples and supplementary documentation for Nightmare
251 stars 46 forks source link

Describe what the examples are actually doing #6

Closed Mr0grog closed 8 years ago

Mr0grog commented 8 years ago

At the very least, everywhere the Yahoo example is used, it would be good to have a quick description, e.g. “here’s how to get the URL for the top result in a Yahoo search for ‘github nightmare’.”

Line-by-line comments describing each action probably aren’t needed, but could be helpful for someone just getting started, e.g:

nightmare
  // load a URL
  .goto('http://yahoo.com')
  // simulate typing into an element identified by a CSS selector
  .type('input[title="Search"]', 'github nightmare')
  // click the search button
  .click('#uh-search-button')
  // wait for results to load
  .wait('#main')
  // run some javascript inside the webpage to get the URL of the first link
  .evaluate(function() {
    return document.querySelector('#main .searchCenterMiddle li a')
      .href;
  })
rosshinkley commented 8 years ago

Line-by-line comments certainly won't hurt and cost (almost) nothing outside of a small time investment. A quick description of what the example does wouldn't hurt, either. Will do. :)