Question

I know it's possible to use phantomJS with Watir-Webdriver, but is there some 'mode' I can pass it to actually see what it's doing before I decide to use the (default) headless mode?

Was it helpful?

Solution 4

You could log all the request and responses using onResourceRequested and onResourceReceived api's. I do this for a scraper I wrote in casperjs which uses phantomjs underneath. The Watir-Webdriver should provide some hook into webPage object of phantomjs.

page.onResourceRequested = function(requestData, networkRequest) {
  console.log('Request (#' + requestData.id + '): ' + JSON.stringify(requestData));
};

page.onResourceReceived = function(response) {
  console.log('Response (#' + response.id + ', stage "' + response.stage + '"): ' + JSON.stringify(response));
};

OTHER TIPS

Not sure about a mode, but you can try this:

require 'watir-webdriver'
b = Watir::Browser.new :phantomjs
b.screenshot.save 'step1.png'
b.goto "www.google.com"
b.screenshot.save 'step2.png'
b.url #"http://www.google.com/"
b.screenshot.save 'step3.png'
b.title #"Google"
b.screenshot.save 'step4.png'

You'll get output that looks like this: screenshot of step 2

Extending other responses, you can automatically do screenshots before clicking or sending keys to element.

class Screenshotter < Selenium::WebDriver::Support::AbstractEventListener
  def before_click(_, driver)
    driver.save_screenshot("screenshot-#{Time.now.to_i}.png")
  end

  def before_change_value_of(_, driver)
    driver.save_screenshot("screenshot-#{Time.now.to_i}.png")
  end
end

browser = Watir::Browser.new(:phantomjs, listener: Screenshotter.new)

Moving forward, you can join all screenshots to a GIF which will work like live video of your test.

Like artjom B is writing, there is not possibility for other modes than headless in PhantomJS.

So either change the browser - I have made all my tests able to run in every browser by changing an Environment variable in the CMD box.

Or else take a lot of screenshots with: @b.screenshot.save 'filename' - and you can follow the flow through even though you keep on using PhantomJS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top