-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* - Add asynchronous modules and classes - Add sync version of the async test for performance comparison - Change asynchronous tests to run asynchronously - Unit test passing * Fix issues * fix issue * remove 'Execution with Caqui' session from README * small fixes * reorder logs in Application * Improve report error of async OppenApp and CloseApp
- Loading branch information
1 parent
f3e8555
commit 72a18d0
Showing
16 changed files
with
399 additions
and
119 deletions.
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
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
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,29 @@ | ||
from typing import Any, TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from guara.asynchronous.transaction import AbstractTransaction | ||
|
||
|
||
class IAssertion: | ||
async def asserts(self, actual: "AbstractTransaction", expected: Any) -> None: | ||
raise NotImplementedError | ||
|
||
|
||
class IsEqualTo(IAssertion): | ||
async def asserts(self, actual, expected): | ||
assert actual.result == expected | ||
|
||
|
||
class IsNotEqualTo(IAssertion): | ||
async def asserts(self, actual, expected): | ||
assert actual.result != expected | ||
|
||
|
||
class Contains(IAssertion): | ||
async def asserts(self, actual, expected): | ||
assert expected.result in actual | ||
|
||
|
||
class DoesNotContain(IAssertion): | ||
async def asserts(self, actual, expected): | ||
assert expected.result not in actual |
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 @@ | ||
from guara.asynchronous.transaction import AbstractTransaction | ||
|
||
|
||
class OpenApp(AbstractTransaction): | ||
""" | ||
Not Implemented as Selenium not is executed asynchronously. | ||
Use your preferable asynchronous Web Driver. | ||
For example: https://github.com/douglasdcm/caqui | ||
""" | ||
|
||
def __init__(self, driver): | ||
super().__init__(driver) | ||
|
||
async def do(self, **kwargs): | ||
raise NotImplementedError( | ||
"Selenium does not support asynchronous execution." | ||
" Use your preferable async WebDriver. " | ||
" For example https://github.com/douglasdcm/caqui" | ||
) | ||
|
||
|
||
class CloseApp(AbstractTransaction): | ||
""" | ||
Not Implemented as Selenium is not executed asynchronously. | ||
Use your preferable asynchronous Web Driver. | ||
For example: https://github.com/douglasdcm/caqui | ||
""" | ||
|
||
def __init__(self, driver): | ||
super().__init__(driver) | ||
|
||
async def do(self, **kwargs): | ||
raise NotImplementedError( | ||
"Selenium does not support asynchronous execution." | ||
" Use your preferable async WebDriver. " | ||
" For example https://github.com/douglasdcm/caqui" | ||
) |
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,70 @@ | ||
import logging | ||
from typing import Any, NoReturn | ||
from selenium.webdriver.remote.webdriver import WebDriver | ||
from guara.asynchronous.it import IAssertion | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class AbstractTransaction: | ||
def __init__(self, driver: WebDriver): | ||
self._driver = driver | ||
|
||
async def do(self, **kwargs) -> Any | NoReturn: | ||
raise NotImplementedError | ||
|
||
|
||
class Application: | ||
""" | ||
This is the runner of the automation. | ||
""" | ||
|
||
def __init__(self, driver): | ||
self._driver = driver | ||
self._result = None | ||
self._coroutines = [] | ||
self._TRANSACTION = "transaction" | ||
self._ASSERTION = "assertion" | ||
|
||
@property | ||
def result(self): | ||
return self._result | ||
|
||
def at(self, transaction: AbstractTransaction, **kwargs): | ||
"""It executes the `do` method of each transaction""" | ||
|
||
LOGGER.info(f"Transaction '{transaction.__name__}'") | ||
for k, v in kwargs.items(): | ||
LOGGER.info(f" {k}: {v}") | ||
|
||
coroutine = transaction(self._driver).do(**kwargs) | ||
self._coroutines.append({self._TRANSACTION: coroutine}) | ||
|
||
return self | ||
|
||
def asserts(self, it: IAssertion, expected): | ||
"""The `asserts` method receives a reference to an `IAssertion` instance. | ||
It implements the `Strategy Pattern (GoF)` to allow its behavior to change at runtime. | ||
It validates the result using the `asserts` method.""" | ||
|
||
LOGGER.info(f"Assertion '{it.__name__}'") | ||
LOGGER.info(f" actual: '{self._result}'") | ||
LOGGER.info(f" expected: '{expected}'") | ||
LOGGER.info("---") | ||
|
||
coroutine = it().asserts(self, expected) | ||
self._coroutines.append({self._ASSERTION: coroutine}) | ||
|
||
return self | ||
|
||
async def perform(self) -> "Application": | ||
"""Executes the coroutines in order and saves the result of the transaction | ||
in `result`""" | ||
|
||
for coroutine in self._coroutines: | ||
if coroutine.get(self._TRANSACTION): | ||
self._result = await coroutine.get(self._TRANSACTION) | ||
continue | ||
await coroutine.get(self._ASSERTION) | ||
self._coroutines.clear() | ||
return self |
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
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
Oops, something went wrong.