Skip to content

Rename browser to driver#976

Merged
pekkaklarck merged 14 commits intorobotframework:masterfrom
aaltat:rename_browser_to_driver_2
Nov 8, 2017
Merged

Rename browser to driver#976
pekkaklarck merged 14 commits intorobotframework:masterfrom
aaltat:rename_browser_to_driver_2

Conversation

@aaltat
Copy link
Copy Markdown
Contributor

@aaltat aaltat commented Oct 30, 2017

To do:

  • fix browsermanagement.py, because it says browser in many places where it should say driver
  • deprecate method self.browser

@aaltat
Copy link
Copy Markdown
Contributor Author

aaltat commented Oct 31, 2017

But it definitely looks like my rebase with master did not go smoothly. Have to take a look later.

@pekkaklarck
Copy link
Copy Markdown
Member

I'd still use webdriver instead of driver as the attribute name, but it seems everyone else likes the latter so let's use that. I'd still use use WebDriverCache and not DriverCache, though. More importantly, the type of the attribute (i.e. property) should be specified in the docstring. That makes the attribute type unambiguous for users and also helps IDEs.

@aaltat
Copy link
Copy Markdown
Contributor Author

aaltat commented Oct 31, 2017

The windowmanager.py needs some refactoring, so that it does not pass the driver as argument but uses the self.driver instead

WindowKeywords(self)
]
self._browsers = BrowserCache()
self._webdrivers = WebDriverCache()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be _drivers to match driver.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@property
def browsers(self):
return self.ctx._browsers
def webdrivers(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be drivers to match driver.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self.ctx.speed = timestr_to_secs(value)
for browser in self.browsers.browsers:
self._monkey_patch_speed(browser)
for driver in self.webdrivers.drivers:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't ConnectionCache iterable? If it is, this could be just for driver in self.drivers. If it isn't, it should be changed!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be iterable, but changes the code to only iterate drivers which are not closed.

@aaltat aaltat force-pushed the rename_browser_to_driver_2 branch from d212b8e to 476cb6f Compare November 6, 2017 20:47
self._running_on_failure_keyword = False

@property
def driver(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. missing at the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

:rtype: selenium.webdriver.remote.webdriver.WebDriver
:raises RuntimeError if driver is not created
"""
if not self._drivers.current:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange error message. Perhaps this should still be No browser is open.? Also, should we use a dedicated exception?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, browser is better.

It's strange exception, but that is how the original code worked. Dedicated exception would be better, would NoBrowser be good?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps NoOpenBrowser or NoBrowserOpen?

if browser not in self._closed:
open_browsers.append(browser)
return open_browsers
def get_open_drivers(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open driver sounds a bit odd. Should this perhaps be get_active_browsers()? Or perhaps property active_browsers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did go with active_drivers

Copy link
Copy Markdown
Member

@pekkaklarck pekkaklarck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Added few line notes, though.

@aaltat aaltat force-pushed the rename_browser_to_driver_2 branch from 476cb6f to 2faa957 Compare November 7, 2017 21:39

def __init__(self):
ConnectionCache.__init__(self, no_current_msg='No current browser')
ConnectionCache.__init__(self, no_current_msg='No current driver')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still say browser. And have . at the end.

If that message is ever used, it's used by ConnectionCache as a message for RuntimeError. We have our own NoOpenBrowser now, but there's no good API to use that here. We could set self._no_current to an object using our exception (and it could extend NoConnection) but I'm not sure is that worth the effort.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did change to driver -> browser.

If the start seeing the RuntimeErrorin real life, lets then decide what we should do.

:rtype: selenium.webdriver.remote.webdriver.WebDriver
:raises RuntimeError if driver is not created
"""
if not self._drivers.current:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Exception type not updated in the doc string above.
  • This error message could have . at the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@aaltat aaltat force-pushed the rename_browser_to_driver_2 branch from f24f1ca to c8a7c2f Compare November 8, 2017 20:13
def driver(self):
"""Current active driver.

:rtype: selenium.webdriver.remote.webdriver.WebDriver
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought it would raise NoOpenBrowser....

@pekkaklarck pekkaklarck merged commit dc875cf into robotframework:master Nov 8, 2017
@aaltat aaltat deleted the rename_browser_to_driver_2 branch November 14, 2017 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants