4

Can you please help on printing the console logs generate in web browser for any errors in Cucumber Capybara Test Automation? I am using PhantomJS webdriver as below:

Capybara::Selenium::Driver.new(app, :browser => :phantomjs, desired_capabilities: { 'phantomjs.cli.args' => ['--ignore-ssl-errors=yes']

I want to capture Browser JS console logs and print it while i need on automation execution

ses
  • 13,174
  • 31
  • 123
  • 226
SaeeK
  • 217
  • 1
  • 4
  • 12

1 Answers1

13

Since you're using selenium you can try

page.driver.browser.manage.logs.get("browser")

Note: I've never tried it with PhantomJS as the browser

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thanks for reply. I have used below codes: logs = page.driver.manage.logs.get("browser"); p "Logs: #{logs}" Getting below error: undefined method `manage' for # (NoMethodError) Please help... – SaeeK Jan 27 '16 at 18:36
  • That's right. I don't know how to accept it. I will accept after it works. Anyway still not working. I am getting this error while using chrome. unknown error: log type 'chrome' not found (Session info: chrome=47.0.2526.111) (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.9.5 x86_64) (Selenium::WebDriver::Error::UnknownError) . If the status is 200 instead any javascript errors, i should get 200 status code – SaeeK Jan 27 '16 at 19:01
  • Your question specifically says you're using PhantomJS -- where did using chrome come from? – Thomas Walpole Jan 27 '16 at 19:07
  • Huh -- I'm not really sure what you're asking now -- What do status codes have to do with console logs? – Thomas Walpole Jan 27 '16 at 19:09
  • but the log types arent chrome or phantomjs - the logtype is "browser" -- .get("browser") – Thomas Walpole Jan 27 '16 at 19:23