-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from StatCan/feature-read-and-execute-commands-15
Feature read and execute commands 15 - v. 0.1.0 Candidate
- Loading branch information
Showing
9 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,88 @@ | ||
{ | ||
"uuid":"sample-test-run", | ||
"build":"0.1.0Test", | ||
"browser": "chrome", | ||
"test_cases":[ | ||
{ | ||
"uuid":"sample-test-case", | ||
"name":"Sample Test Case A", | ||
|
||
"steps":[ | ||
{ | ||
"uuid":"sample-test-step-0", | ||
"name":"Launch google.ca", | ||
"action":"load_file", | ||
"parameters":["relative_path", "tests/pages/page1.html"] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-1", | ||
"name":"Type search query into google", | ||
"action":"type", | ||
"parameters":["locator", {"by":"id", "value":"nameField"}, "text", "do a barrel roll"] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-2", | ||
"name":"Click the search button", | ||
"action":"click", | ||
"parameters":["locator", {"by": "id", "value": "btnColor"}] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-3", | ||
"name":"Read search query", | ||
"action":"read_css", | ||
"parameters":["locator", {"by": "id", "value": "btnColor"}, "attribute", "background-color"] | ||
} | ||
] | ||
|
||
}, | ||
{ | ||
"uuid":"sample-test-case", | ||
"name":"Sample Test Case B", | ||
"steps":[ | ||
{ | ||
"uuid":"sample-test-step-0", | ||
"name":"Launch google.ca", | ||
"action":"load_file", | ||
"parameters":["relative_path", "tests/pages/page1.html"] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-1", | ||
"name":"Type search query into google", | ||
"action":"type", | ||
"parameters":["locator", {"by":"id", "value":"nameField"}, "text", "do a barrel roll"] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-2", | ||
"name":"Click the search button", | ||
"action":"click", | ||
"parameters":["locator", {"by": "id", "value": "btnColor"}] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-3", | ||
"name":"Read search query", | ||
"action":"read_css", | ||
"parameters":["locator", {"by": "id", "value": "btnColor"}, "attribute", "background-color"] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-1", | ||
"name":"Type search query into google", | ||
"action":"type", | ||
"parameters":["locator", {"by":"id", "value":"nameField"}, "text", "don't do a barrel roll"] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-2", | ||
"name":"Click the search button", | ||
"action":"click", | ||
"parameters":["locator", {"by": "id", "value": "btnColor"}] | ||
}, | ||
{ | ||
"uuid":"sample-test-step-3", | ||
"name":"Read search query", | ||
"action":"read_css", | ||
"parameters":["locator", {"by": "id", "value": "btnColor"}, "attribute", "background-color"] | ||
} | ||
] | ||
|
||
} | ||
] | ||
} |
This file contains 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,20 @@ | ||
import argparse | ||
import json | ||
from tass.core.tass_files import TassRun | ||
|
||
|
||
def main(args): | ||
print(args.file) | ||
with open(args.file) as file: | ||
test = TassRun(args.file, **json.load(file)) | ||
for case in test.collect(): | ||
print(case) | ||
case.execute_tass() | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--file', | ||
action='store', required=True) | ||
|
||
main(parser.parse_args()) |
This file contains 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
Empty file.
This file contains 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,32 @@ | ||
from tass.core.tass_items import TassItem | ||
from tass.drivers.browserdriver import newDriver | ||
import tass.actions.selenium as actions | ||
|
||
|
||
class TassCase(TassItem): | ||
def execute_tass(self): | ||
# print(self.steps) | ||
for step in self._steps: | ||
print('') | ||
print('* * * * * * * * * *') | ||
print(step) | ||
print('* * * * * * * * * *') | ||
_execute_step(step, self.driver) | ||
|
||
def __init__(self, *, steps=[], browser_config={}, **kwargs): | ||
# TODO: Include Pages after confirming data structure | ||
super().__init__(**kwargs) | ||
self._browser_config = browser_config | ||
self._steps = steps | ||
self._driver = None | ||
|
||
@property | ||
def driver(self): | ||
if (self._driver is None): | ||
self._driver = newDriver(**self._browser_config) | ||
return self._driver | ||
|
||
|
||
def _execute_step(step, driver): | ||
params = dict(zip(it := iter(step.get('parameters', None)), it)) | ||
getattr(actions, step.get('action'))(driver=driver, **params) |
This file contains 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,37 @@ | ||
import json | ||
from tass.core.tass_items import TassFile | ||
from tass.core.tass_case import TassCase | ||
from tass.drivers.supportedbrowsers import Browsers | ||
|
||
|
||
class TassSuite(TassFile): | ||
|
||
def collect(self): | ||
# TODO: Collect all test cases as TassItems and yield | ||
pass | ||
|
||
|
||
class TassRun(TassFile): | ||
|
||
def __init__(self, path, test_cases, browser, **kwargs): | ||
super().__init__(path, **kwargs) | ||
self._test_cases = test_cases | ||
self._browser_name = browser | ||
|
||
def collect(self): | ||
# TODO: Collect all test cases as TassItems, | ||
# then collect all TestSuites and yield TassItems | ||
# print(self.file) | ||
|
||
try: | ||
browser = Browsers.browser(self._browser_name) | ||
except (KeyError) as ke: | ||
print('') | ||
print('Not a supported browser: ', self._browser_name) | ||
raise ke | ||
|
||
for case in self._test_cases: | ||
driver = {'browser': browser, | ||
'config': json.load(open('tass/config/browsers.json')) | ||
.get(browser, {})} | ||
yield TassCase(parent=self, browser_config=driver, **case) |
This file contains 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,34 @@ | ||
class TassItem(): | ||
|
||
def __init__(self, parent=None, name=None, uuid=None, build=None): | ||
self._parent = parent | ||
self._name = name | ||
self._uuid = uuid | ||
self._build = build if build else parent.build | ||
|
||
@property | ||
def name(self): | ||
return self._name | ||
|
||
@property | ||
def uuid(self): | ||
return self._uuid | ||
|
||
@property | ||
def parent(self): | ||
return self._parent | ||
|
||
@property | ||
def build(self): | ||
return self._build | ||
|
||
|
||
class TassFile(TassItem): | ||
|
||
def __init__(self, file_path, **kwargs): | ||
super().__init__(**kwargs) | ||
self._file_path = file_path | ||
|
||
@property | ||
def file_path(self): | ||
return self._file_path |
This file contains 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 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,13 @@ | ||
from enum import Enum | ||
from tass.drivers.browserdriver import ChromeDriver | ||
from tass.drivers.browserdriver import FirefoxDriver | ||
from tass.drivers.browserdriver import EdgeDriver | ||
|
||
|
||
class Browsers(Enum): | ||
CHROME = ChromeDriver | ||
FIREFOX = FirefoxDriver | ||
EDGE = EdgeDriver | ||
|
||
def browser(name): | ||
return Browsers[name.upper()].value |