-
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.
Merge branch 'main' into add-readme-to-examples
- Loading branch information
Showing
4 changed files
with
82 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,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 |
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,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() |
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,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") |
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 |
---|---|---|
|
@@ -20,4 +20,4 @@ dogtail | |
splinter | ||
rpa | ||
psutil | ||
|
||
selenium-stealth |