Skip to content
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

Integrate with Broserist #14

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
captures

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ tests/web_ui_local/test_local_page.py::TestLocalTransaction::test_local_page
INFO guara.transaction:transaction.py:26 2025-01-06 01:51:41.654542 Transaction 'OpenApp'
INFO guara.transaction:transaction.py:28 url: file:////sample.html
INFO guara.transaction:transaction.py:28 window_width: 1094
INFO guara.transaction:transaction.py:28 window_hight: 765
INFO guara.transaction:transaction.py:28 window_height: 765
INFO guara.transaction:transaction.py:28 implicitly_wait: 0.5
--------------------------------------------------------------- live log call ----------------------------------------------------------------
INFO guara.transaction:transaction.py:26 2025-01-06 01:51:41.788494 Transaction 'SubmitText'
Expand Down
6 changes: 3 additions & 3 deletions guara/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class OpenApp(AbstractTransaction):
Args:
url (str): the path where the screenshot is saved.
window_width (int): The width of the browser. Defaults to 1094
window_hight (int): The hight of the browser. Defaults t0 765
window_height (int): The height of the browser. Defaults t0 765
implicitly_wait (int): the implicity timeout for an element to be found.
Defaults to 10 (seconds)
Returns:
Expand All @@ -19,8 +19,8 @@ class OpenApp(AbstractTransaction):
def __init__(self, driver):
super().__init__(driver)

def do(self, url, window_width=1094, window_hight=765, implicitly_wait=10):
self._driver.set_window_size(window_width, window_hight)
def do(self, url, window_width=1094, window_height=765, implicitly_wait=10):
self._driver.set_window_size(window_width, window_height)
self._driver.get(url)
self._driver.implicitly_wait(implicitly_wait)
return self._driver.title
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exclude = ["tests*", ".vscode", ".git*", "dist", "*pytest*"]

[project]
name = "guara"
version = "0.0.4"
version = "0.0.5"
authors = [
{ name="Douglas Cardoso", email="noemail@noemail.com" },
]
Expand Down
3 changes: 2 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ black
requests
caqui
tox
pytest-playwright
pytest-playwright
browserist
2 changes: 2 additions & 0 deletions tests/web_ui_playwrigth/pages/getting_started.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from playwright.sync_api import Page
from guara.transaction import AbstractTransaction


Expand All @@ -11,6 +12,7 @@ class NavigateToWritingTests(AbstractTransaction):

def __init__(self, driver):
super().__init__(driver)
self._driver: Page

def do(self, **kwargs):
self._driver.get_by_role("link", name="Writing tests", exact=True).click()
Expand Down
2 changes: 2 additions & 0 deletions tests/web_ui_playwrigth/pages/home.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from playwright.sync_api import Page
from guara.transaction import AbstractTransaction


Expand All @@ -11,6 +12,7 @@ class NavigateToGettingStarted(AbstractTransaction):

def __init__(self, driver):
super().__init__(driver)
self._driver: Page

def do(self, **kwargs):
self._driver.get_by_role("link", name="Get started").click()
Expand Down
2 changes: 2 additions & 0 deletions tests/web_ui_playwrigth/pages/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from playwright.sync_api import Page
from guara.transaction import AbstractTransaction


Expand All @@ -14,6 +15,7 @@ class OpenApp(AbstractTransaction):

def __init__(self, driver):
super().__init__(driver)
self._driver: Page

def do(self, with_url):
self._driver.goto(with_url)
Expand Down
26 changes: 26 additions & 0 deletions tests/web_ui_selenium/test_browserist/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from browserist import Browser
from guara.transaction import AbstractTransaction


class SubmitText(AbstractTransaction):
"""
Submits the text

Args:
text (str): The text to be submited

Returns:
str: the label 'It works! {code}!'
"""

def __init__(self, driver):
super().__init__(driver)
self._driver: Browser

def do(self, text):
TEXT = '//*[@id="input"]'
BUTTON_TEST = '//*[@id="button"]'
RESULT = '//*[@id="result"]'
self._driver.input.value(TEXT, text)
self._driver.click.button(BUTTON_TEST)
return self._driver.get.text(RESULT)
57 changes: 57 additions & 0 deletions tests/web_ui_selenium/test_browserist/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from datetime import datetime
from browserist import Browser
from guara.transaction import AbstractTransaction


class OpenApp(AbstractTransaction):
"""
Opens the app

Args:
url (str): the path where the screenshot is saved.
window_width (int): The width of the browser. Defaults to 1094
window_height (int): The height of the browser. Defaults t0 765
implicitly_wait (int): the implicity timeout for an element to be found.
Defaults to 10 (seconds)
Returns:
str: the title of the app
"""

def __init__(self, driver):
super().__init__(driver)
self._driver: Browser

def do(self, url, window_width=1094, window_height=765, implicitly_wait=10):
self._driver.window.set.width(window_width)
self._driver.window.set.height(window_height)
self._driver.open.url(url)
self._driver.wait.seconds(implicitly_wait)
return self._driver.get.page_title()


class CloseApp(AbstractTransaction):
"""
Closes the app and saves its screenshot (PNG)

Args:
screenshot_filename (str): the name of the screenshot file.
Defaults to 'guara-{datetime.now()}.png'.

screenshot_destination (str): the path where the screenshot is saved.
Defaults to './captures'.

"""

def __init__(self, driver):
super().__init__(driver)
self._driver: Browser

def do(
self,
screenshot_destination="./captures",
screenshot_filename="guara-capture",
):
self._driver.screenshot.complete_page(
f"{screenshot_filename}-{datetime.now()}.png", screenshot_destination
)
self._driver.quit()
32 changes: 32 additions & 0 deletions tests/web_ui_selenium/test_browserist/test_browserist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pathlib
import random
from guara.transaction import Application
from guara import it
from tests.web_ui_selenium.test_browserist import setup
from tests.web_ui_selenium.test_browserist import home
from browserist import Browser, BrowserSettings


class TestIntegrateBrowserist:
def setup_method(self, method):
file_path = pathlib.Path(__file__).parent.parent.resolve()

self._app = Application(Browser(BrowserSettings(headless=True)))
self._app.at(
setup.OpenApp,
url=f"file:///{file_path}/sample.html",
window_width=1094,
window_height=765,
implicitly_wait=0.5,
).asserts(it.IsEqualTo, "Sample page")

def teardown_method(self, method):
self._app.at(setup.CloseApp)

def test_local_page(self):
text = ["cheese", "selenium", "test", "bla", "foo"]
text = text[random.randrange(len(text))]
self._app.at(home.SubmitText, text=text).asserts(
it.IsEqualTo, f"It works! {text}!"
)
self._app.at(home.SubmitText, text=text).asserts(it.IsNotEqualTo, "Any")
17 changes: 0 additions & 17 deletions tests/web_ui_selenium/test_local_page/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@
from guara.transaction import AbstractTransaction


class Navigate(AbstractTransaction):
"""
Navigates to Home page

Returns:
str: the label 'It works! {code}!'
"""

def __init__(self, driver):
super().__init__(driver)

def do(self, **kwargs):
self._driver.find_element(By.CSS_SELECTOR, ".navbar-brand > img").click()
self._driver.find_element(By.CSS_SELECTOR, ".col-md-10").click()
return self._driver.find_element(By.CSS_SELECTOR, "label:nth-child(1)").text


class SubmitText(AbstractTransaction):
"""
Submits the text
Expand Down
6 changes: 3 additions & 3 deletions tests/web_ui_selenium/test_local_page/test_local_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

class TestLocalTransaction:
def setup_method(self, method):
file_path = pathlib.Path(__file__).parent.resolve()
file_path = pathlib.Path(__file__).parent.parent.resolve()
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
self._app = Application(webdriver.Chrome(options=options))
self._app.at(
setup.OpenApp,
url=f"file:///{file_path}/sample.html",
window_width=1094,
window_hight=765,
window_height=765,
implicitly_wait=0.5,
)
).asserts(it.IsEqualTo, "Sample page")

def teardown_method(self, method):
self._app.at(setup.CloseApp)
Expand Down
2 changes: 1 addition & 1 deletion tests/web_ui_selenium/test_web_page/test_vpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def setup_application():
configuration = {
"url": "https://vagaspramim.onrender.com/",
"window_width": 1094,
"window_hight": 765,
"window_height": 765,
"implicitly_wait": 0.5,
}
options = webdriver.ChromeOptions()
Expand Down
Loading