Last active
January 23, 2017 10:58
-
-
Save aaltat/3bc147cf1051bb2266b030f47274b00e to your computer and use it in GitHub Desktop.
S2L new architecture
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
import inspect | |
from robot.api.deco import keyword | |
class FindElement(object): | |
def __init__(self, ctx): | |
self.ctx = ctx | |
@keyword | |
def wait_untill_page_contains(self, text): | |
els = self.find_elements('//*[contains(text(), "{}"")'.format(text)) | |
print els | |
self.ctx.driver() | |
@keyword | |
def wait_untill_page_contains_element(self, locator): | |
els = self.find_elements(locator) | |
print els | |
self.ctx.driver() | |
def find_elements(self, locator): | |
print locator | |
return [1, 2] | |
class BrowserManagement(object): | |
def __init__(self, ctx): | |
self.ctx = ctx | |
@keyword | |
def open_browser(self, url, browser): | |
print url | |
if browser == 'chrome': | |
self.chrome() | |
else: | |
self.ff() | |
@keyword | |
def close_browser(self): | |
pass | |
def chrome(self): | |
print 'Opening chrome' | |
self.ctx.current_browser = 'Chrome' | |
def ff(self): | |
print 'Opening ff' | |
self.ctx.current_browser = 'Firefox' | |
class S2L(object): | |
def __init__(self): | |
self._components = [ | |
FindElement(self), | |
BrowserManagement(self) | |
] | |
self.keywords = dict(self._find_keywords(self._components)) | |
def __getattr__(self, name): | |
if name not in self.keywords.keys(): | |
raise AttributeError('Attribute not found {}'.format(name)) | |
return self.keywords[name] | |
def driver(self): | |
print 'foobar' | |
def get_keyword_names(self): | |
return list(self.keywords) | |
def _find_keywords(self, libraries): | |
for library in libraries: | |
for name, kw in inspect.getmembers(library): | |
if callable(kw) and hasattr(kw, 'robot_name'): | |
name = kw.robot_name or name | |
yield name, kw | |
if __name__ == '__main__': | |
x = S2L() | |
print 1 | |
print x.get_keyword_names() | |
print 2 | |
print x.keywords | |
print 'open_browser' | |
print x.open_browser('http://google.fi', 'chrome') | |
print 'current browser', x.current_browser | |
print 'wait_untill_page_contains' | |
print x.wait_untill_page_contains('some text') | |
print 'wait_untill_page_contains_element' | |
print x.wait_untill_page_contains_element('//div') | |
print x.close_browser() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment