Page MenuHomePhabricator

mediawiki_selenium feature to show/capture Selenium WebDriver requests to remote browser.
Closed, DeclinedPublic

Description

I have found no good way to capture the communications between Watir/Selenium Webdriver and the browser being driven. While investigating some weird delay in our browser tests scenarii, I end up doing a tcpdump to capture the http requests driving the browser ( T92613 ).

It would be rather nice to have the Selenium logs to be optionally emitted on the terminal. Would help diagnosis.

mediawiki_selenium creates a browser objects invoking Watir (in turn invoking Selenium WebDriver). The browser creation accepts a :listen option to attach a class implementing AbstractWebDriverEventListener https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/events/AbstractWebDriverEventListener.html

Should let us log everything.

Details

Related Gerrit Patches:

Event Timeline

hashar raised the priority of this task from to Needs Triage.
hashar updated the task description. (Show Details)
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 31 2015, 4:24 PM
zeljkofilipin triaged this task as High priority.
zeljkofilipin set Security to None.
zeljkofilipin removed zeljkofilipin as the assignee of this task.Apr 1 2015, 1:18 PM

Removing myself from assigned, I did not read the ticket carefully, this is about logging support in mediawiki_selenium Ruby gem.

Or figure out how to easily enable some logging of the selenium commands and add the instructions to the mediawiki_selenium README.md file :)

Found this just now:

How To Access Selenium Logs In Real Time
http://elementalselenium.com/tips/54-logging

zeljkofilipin lowered the priority of this task from High to Low.Jun 9 2015, 3:51 PM
zeljkofilipin raised the priority of this task from Low to High.
zeljkofilipin moved this task from Inbox to Next on the Browser-Tests-Infrastructure board.
hashar updated the task description. (Show Details)Jun 9 2015, 7:31 PM
zeljkofilipin lowered the priority of this task from High to Medium.Sep 29 2015, 3:57 PM

Change 310583 had a related patch set uploaded (by Hashar):
(WIP) Demo to dump browser and selenium logs (WIP)

https://gerrit.wikimedia.org/r/310583

@zeljkofilipin Could we use this task too for tracking capturing the page errors / js logs too? Or should I open a different one?

I will take a look.

Change 310583 abandoned by Hashar:
(WIP) Demo to dump browser and selenium logs (WIP)

Reason:
That was just for demoing purpose :-}

https://gerrit.wikimedia.org/r/310583

@Jhernandez, @hashar:

Looks like this works great for Chrome, but it is not implemented for Firefox (yet?).

A simple HTML page with JavaScript error:

<a href="#" name="q" onclick="a">Click Me</a>

A simple Ruby script:

require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
driver.navigate.to ARGV[0]
driver.find_element(:name, 'q').click
p driver.manage.logs.get(:browser)

The output of the script:

$ ruby chrome.rb file:///path/to/file
[#<Selenium::WebDriver::LogEntry:0x007fdbaaa52570 @level="SEVERE", @timestamp=1474367536635, @message="file:///path/to/file 1:34 Uncaught ReferenceError: a is not defined">]

Nice progress!

I believe reading web's tests in jenkins mw-selenium job are running in chrome so even if we can't get it to work in the other ones there's value to this for diagnosing failures on patchsets.

zeljkofilipin added a comment.EditedSep 21 2016, 4:11 PM

I have forgot to mention, a simple change in the script displays webdriver instead of browser log. It is useful for debugging problems in higher level tools (watir, page-object).

driver.manage.logs.get(:driver)

instead of

driver.manage.logs.get(:browser)

The script:

require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
driver.navigate.to ARGV[0]
driver.find_element(:name, 'q').click
p driver.manage.logs.get(:driver)

Output (showing just the first and the last element, there were many many):

$ ruby chrome.rb file:///path/to/file
[#<Selenium::WebDriver::LogEntry:0x007fdd438ebcc8
  @level="INFO",
  @message='
Populating Preferences file: {
   "alternate_error_pages": {
      "enabled": false
   },
   "autofill": {
      "enabled": false
   },
   "browser": {
      "check_default_browser": false
   },
   "distribution": {
      "import_bookmarks": false,
      "import_history": false,
      "import_search_engine": false,
      "make_chrome_default_for_user": false,
      "show_welcome_page": false,
      "skip_first_run_ui": true
   },
   "dns_prefetching": {
      "enabled": false
   },
   "profile": {
      "content_settings": {
         "pattern_pairs": {
            "https://*,*": {
               "media-stream": {
                  "audio": "Default",
                  "video": "Default"
               }
            }
         }
      },
      "default_content_setting_values": {
         "geolocation": 1
      },
      "default_content_settings": {
         "geolocation": 1,
         "mouselock": 1,
         "notifications": 1,
         "popups": 1,
         "ppapi-broker": 1
      },
      "password_manager_enabled": false
   },
   "safebrowsing": {
      "enabled": false
   },
   "search": {
      "suggest_enabled": false
   },
   "translate": {
      "enabled": false
   }
}',
  @timestamp=1474477725283>,

...

 #<Selenium::WebDriver::LogEntry:0x007fdd438f9170
  @level="DEBUG",
  @message='
DEVTOOLS RESPONSE Runtime.evaluate (id=22) {
   "result": {
      "description": "1",
      "type": "number",
      "value": 1
   },
   "wasThrown": false
}',
  @timestamp=1474477756252>]
zeljkofilipin removed zeljkofilipin as the assignee of this task.Nov 8 2016, 11:57 AM
zeljkofilipin awarded a token.
zeljkofilipin closed this task as Declined.May 26 2017, 3:43 PM
zeljkofilipin lowered the priority of this task from Medium to Low.

Unlikely to ever be resolved because of T139740: Port Selenium tests from Ruby to Node.js.

Apparently one can set the DEBUG environment variable and selenium-webdriver will happily log at debug level (instead of warning)