Skip to content

Commit

Permalink
Merge branch 'main' into add-readme-to-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasdcm committed Feb 7, 2025
2 parents a4847ee + 8db8922 commit 4cd6f15
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
10 changes: 10 additions & 0 deletions examples/web_ui/selenium_stealth/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from guara.transaction import AbstractTransaction


class SubmitSeleniumStealth(AbstractTransaction):
"""Actions on the home page"""

def do(self, text):
self._driver.get("https://example.com")
self._driver.find_element("tag name", "h1").click()
return self._driver.page_source
23 changes: 23 additions & 0 deletions examples/web_ui/selenium_stealth/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from guara.transaction import AbstractTransaction


class OpenStealthBrowser(AbstractTransaction):
"""Initialize stealth browser"""

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

def do(self, url, window_width, window_height, implicitly_wait):
self._driver.get(url)
self._driver.set_window_size(window_width, window_height)
self._driver.implicitly_wait(implicitly_wait)


class CloseStealthBrowser(AbstractTransaction):
"""Close stealth browser"""

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

def do(self):
self._driver.quit()
48 changes: 48 additions & 0 deletions examples/web_ui/selenium_stealth/test_selenium_stealth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from guara.transaction import Application
from guara import it
from examples.web_ui.selenium_stealth import setup
from examples.web_ui.selenium_stealth import home
from random import randrange
from selenium import webdriver
from selenium_stealth import stealth


class TestSeleniumStealthIntegration:
"""
TestSeleniumStealthIntegration is a test class for integrating
Selenium Stealth with a local web page.
"""

def setup_method(self, method):
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
stealth(
driver,
languages=["en-US", "en"],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
)

self._app = Application(driver)
self._app.at(
setup.OpenStealthBrowser,
url="https://example.com",
window_width=1094,
window_height=765,
implicitly_wait=0.5,
)

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

def test_local_page(self):
text = ["cheese", "selenium", "test", "bla", "foo"]
text = text[randrange(len(text))]
self._app.at(home.SubmitSeleniumStealth, text=text).asserts(it.Contains, "Example Domain")
self._app.at(home.SubmitSeleniumStealth, text=text).asserts(it.IsNotEqualTo, "Any")
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ dogtail
splinter
rpa
psutil

selenium-stealth

0 comments on commit 4cd6f15

Please sign in to comment.