Repository navigation
Selenium2Library new architecture #770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6e84c52
POC for new architecture
0edb107
Fixing keyword classes to use new architecture
aaltat e109dd6
Fixed unit tests for the new architecture
aaltat c0f43a0
Fixed bug caused by the change.
aaltat f1edd9f
Fixed logging source
aaltat 44c5ab9
Fixes for page should* and close browser keywords
aaltat 791d650
Refactoring common methods to the Base class
aaltat 98ee06a
Refactored Base to contain getter for browser and browsers
aaltat 257ba6b
Fixes run on failure
aaltat 18eb9b3
Fixes waiting keywords
aaltat 71cfe94
Added TODO's to mark fixing in next PR
aaltat 1b9d717
Fixes imports to follow PEP8
aaltat 0e0a08e
Changed timer not to depend on the instance
aaltat 5a3521e
Moved timeouts to library __init__
aaltat 3ec0cce
Fixes too verbose coding style
aaltat 55c6137
More code formatting to less verbose format
aaltat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| decorator >= 3.3.2 | ||
| selenium | ||
| robotframework >= 2.6.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| from robot.api import logger | ||
| from selenium.webdriver.remote.webelement import WebElement | ||
|
|
||
| from .locators.elementfinder import ElementFinder | ||
|
|
||
|
|
||
| LOG_LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR'] | ||
|
|
||
|
|
||
| class Base(object): | ||
|
|
||
| def __init__(self, ctx): | ||
| self.ctx = ctx | ||
| self.element_finder = ElementFinder() | ||
|
|
||
| def info(self, msg, html=False): | ||
| logger.info(msg, html) | ||
|
|
||
| def debug(self, msg, html=False): | ||
| logger.debug(msg, html) | ||
|
|
||
| def log(self, msg, level='INFO', html=False): | ||
| if level.upper() in LOG_LEVELS: | ||
| logger.write(msg, level, html) | ||
|
|
||
| def warn(self, msg, html=False): | ||
| logger.warn(msg, html) | ||
|
|
||
| @property | ||
| def browser(self): | ||
| return self.ctx._browser | ||
|
|
||
| @property | ||
| def browsers(self): | ||
| return self.ctx._browsers | ||
|
|
||
| # TODO: Move logic in elementfinder.ElementFinder but keep method as proxy | ||
| # in Base class | ||
| def element_find(self, locator, first_only=True, required=True, tag=None): | ||
| if isinstance(locator, basestring): | ||
| elements = self.element_finder.find(self.browser, locator, tag) | ||
| if required and len(elements) == 0: | ||
| raise ValueError( | ||
| "Element locator '{}' did not match any elements.".format( | ||
| locator | ||
| ) | ||
| ) | ||
| if first_only: | ||
| if not elements: | ||
| return None | ||
| return elements[0] | ||
| elif isinstance(locator, WebElement): | ||
| elements = locator | ||
| return elements | ||
|
|
||
| # TODO: Move logic in elementfinder.ElementFinder but keep method as proxy | ||
| # in Base class | ||
| def get_value(self, locator, tag=None): | ||
| element = self.element_find( | ||
| locator, required=False, tag=tag | ||
| ) | ||
| return element.get_attribute('value') if element is not None else None | ||
|
|
||
| # TODO: Move logic in elementfinder.ElementFinder but keep method as proxy | ||
| # in Base class | ||
| def page_contains_element(self, locator, tag=None, | ||
| message=None, loglevel='INFO'): | ||
| element_name = tag if tag else 'element' | ||
| if not self.element_find(locator, required=False, tag=tag): | ||
| if not message: | ||
| message = ( | ||
| "Page should have contained %s " | ||
| "'%s' but did not" % (element_name, locator) | ||
| ) | ||
| self.ctx.log_source(loglevel) | ||
| raise AssertionError(message) | ||
| self.info( | ||
| "Current page contains %s '%s'." % (element_name, locator) | ||
| ) | ||
|
|
||
| # TODO: Move logic in elementfinder.ElementFinder but keep method as proxy | ||
| # in Base class | ||
| def page_not_contains_element(self, locator, tag=None, | ||
| message=None, loglevel='INFO'): | ||
| element_name = tag if tag else 'element' | ||
| if self.element_find(locator, required=False, tag=tag): | ||
| if not message: | ||
| message = ( | ||
| "Page should not have contained %s '%s'" | ||
| % (element_name, locator) | ||
| ) | ||
| self.ctx.log_source(loglevel) | ||
| raise AssertionError(message) | ||
| self.info( | ||
| "Current page does not contain %s '%s'." | ||
| % (element_name, locator) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +0,0 @@ | ||
| from .logging import LoggingKeywords | ||
| from .runonfailure import RunOnFailureKeywords | ||
| from .browsermanagement import BrowserManagementKeywords | ||
| from .element import ElementKeywords | ||
| from .tableelement import TableElementKeywords | ||
| from .formelement import FormElementKeywords | ||
| from .selectelement import SelectElementKeywords | ||
| from .javascript import JavaScriptKeywords | ||
| from .cookie import CookieKeywords | ||
| from .screenshot import ScreenshotKeywords | ||
| from .waiting import WaitingKeywords | ||
| from .alert import AlertKeywords | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "LoggingKeywords", | ||
| "RunOnFailureKeywords", | ||
| "BrowserManagementKeywords", | ||
| "ElementKeywords", | ||
| "TableElementKeywords", | ||
| "FormElementKeywords", | ||
| "SelectElementKeywords", | ||
| "JavaScriptKeywords", | ||
| "CookieKeywords", | ||
| "ScreenshotKeywords", | ||
| "WaitingKeywords", | ||
| "AlertKeywords" | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use
..baseinstead ofSelenium2Library.base? Robot uses the latter but the former would make the library name change easier. This isn't a big deal in general and definitely not in the context of this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets decide this one when we decide should we rename the library.