Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ pytest test_coffee_cart.py --trace
--brave # (Shortcut for "--browser=brave".)
--comet # (Shortcut for "--browser=comet".)
--atlas # (Shortcut for "--browser=atlas".)
--chromium # (Shortcut for using base `Chromium`)
--settings-file=FILE # (Override default SeleniumBase settings.)
--env=ENV # (Set the test env. Access with "self.env" in tests.)
--account=STR # (Set account. Access with "self.account" in tests.)
Expand Down
2 changes: 1 addition & 1 deletion examples/cdp_mode/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ with SB(uc=True, test=True, ad_block=True) as sb:
sb.click_if_visible('[data-automation-id="sb-btn-close-mark"]')
items = sb.find_elements('[data-item-id]')
for item in items:
if required_text in item.text:
if required_text.lower() in item.text.lower():
description = item.querySelector(
'[data-automation-id="product-title"]'
)
Expand Down
29 changes: 29 additions & 0 deletions examples/cdp_mode/playwright/raw_pixelscan_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import asyncio
import time
from playwright.async_api import async_playwright
from playwright.async_api import expect
from seleniumbase import cdp_driver


async def main():
driver = await cdp_driver.start_async()
endpoint_url = driver.get_endpoint_url()

async with async_playwright() as p:
browser = await p.chromium.connect_over_cdp(endpoint_url)
page = browser.contexts[0].pages[0]
await page.goto("https://pixelscan.net/fingerprint-check")
time.sleep(4)
await expect(
page.locator("pxlscn-bot-detection")
).to_contain_text("No automated behavior", timeout=4000)
await page.wait_for_selector("span.status-success", timeout=4000)
await expect(
page.locator("pxlscn-fingerprint-masking")
).to_contain_text("No masking detected", timeout=4000)
time.sleep(2)
print("Bot Not Detected")


if __name__ == "__main__":
asyncio.run(main())
21 changes: 21 additions & 0 deletions examples/cdp_mode/playwright/raw_pixelscan_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from playwright.sync_api import sync_playwright
from playwright.sync_api import expect
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome()
endpoint_url = sb.get_endpoint_url()

with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(endpoint_url)
page = browser.contexts[0].pages[0]
page.goto("https://pixelscan.net/fingerprint-check")
sb.sleep(4)
expect(
page.locator("pxlscn-bot-detection")
).to_contain_text("No automated behavior", timeout=4000)
page.wait_for_selector("span.status-success", timeout=4000)
expect(
page.locator("pxlscn-fingerprint-masking")
).to_contain_text("No masking detected", timeout=4000)
sb.sleep(2)
print("Bot Not Detected")
2 changes: 1 addition & 1 deletion examples/cdp_mode/playwright/raw_walmart_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
items = page.locator('[data-item-id]')
for i in range(items.count()):
item = items.nth(i)
if required_text in item.inner_text():
if required_text.lower() in item.inner_text().lower():
description = item.locator('[data-automation-id="product-title"]')
if (
description
Expand Down
27 changes: 27 additions & 0 deletions examples/cdp_mode/raw_cdp_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome()
sb.goto("https://www.target.com/")
sb.sleep(1.5)
sb.click("input#search")
sb.sleep(0.5)
search = "Settlers of Catan Board Game"
required_text = "Catan"
sb.type("input#search", search)
sb.sleep(0.5)
sb.click('button[aria-label="search"]')
sb.sleep(2.5)
print('*** Target Search for "%s":' % search)
print(' (Results must contain "%s".)' % required_text)
unique_item_text = []
items = sb.find_elements('[data-test="product-details"]')
for item in items:
if required_text.lower() in item.text.lower():
description = item.querySelector('a[data-test*="Card/title"]')
if description and description.text not in unique_item_text:
unique_item_text.append(description.text)
print("* " + description.text)
price = item.querySelector('[data-test="current-price"]')
if price:
print(" (" + price.text + ")")
item.scroll_into_view()
9 changes: 0 additions & 9 deletions examples/cdp_mode/raw_cdp_tavus.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_cdp_walmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sb.click_if_visible('[data-automation-id="sb-btn-close-mark"]')
items = sb.find_elements('[data-item-id]')
for item in items:
if required_text in item.text:
if required_text.lower() in item.text.lower():
description = item.querySelector(
'[data-automation-id="product-title"]'
)
Expand Down
24 changes: 24 additions & 0 deletions examples/cdp_mode/raw_cdp_zillow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome(use_chromium=True, ad_block=True)
sb.goto("https://www.zillow.com/")
sb.sleep(2)
search = "Bar Harbor ME homes on the waterfront"
sb.type('input[aria-label="Search"]', search)
sb.sleep(1)
sb.click('button[type="submit"]')
sb.sleep(2)
sb.click_if_visible('span:contains("Cancel")')
sb.sleep(0.5)
sb.click_if_visible('button[title="Close"]')
items = sb.find_visible_elements('[data-testid="property-card"]')
print('*** %s:' % search)
for i, item in enumerate(items):
print("<----- %s ----->" % (i + 1))
print(item.query_selector('[data-testid*="price"]').text)
print(item.query_selector('[data-testid*="details"]').text)
print(item.query_selector('[data-testid*="address"]').text)
item.scroll_into_view()
print("<-------------->")
sb.sleep(2)
sb.quit()
6 changes: 3 additions & 3 deletions examples/cdp_mode/raw_indeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
with SB(uc=True, test=True) as sb:
sb.activate_cdp_mode()
sb.goto("https://www.indeed.com/companies/search")
sb.sleep(2)
sb.sleep(0.8)
sb.solve_captcha()
sb.sleep(1)
sb.sleep(0.8)
search_box = "input#company-search"
if not sb.is_element_present(search_box):
sb.solve_captcha()
sb.sleep(1)
sb.sleep(0.8)
company = "NASA Jet Propulsion Laboratory"
sb.click(search_box)
sb.sleep(0.1)
Expand Down
17 changes: 0 additions & 17 deletions examples/cdp_mode/raw_indeed_login.py

This file was deleted.

28 changes: 28 additions & 0 deletions examples/cdp_mode/raw_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from seleniumbase import SB

with SB(uc=True, test=True, ad_block=True) as sb:
sb.activate_cdp_mode()
sb.goto("https://www.target.com/")
sb.sleep(1.5)
sb.click("input#search")
sb.sleep(0.5)
search = "Settlers of Catan Board Game"
required_text = "Catan"
sb.type("input#search", search)
sb.sleep(0.5)
sb.click('button[aria-label="search"]')
sb.sleep(2.5)
print('*** Target Search for "%s":' % search)
print(' (Results must contain "%s".)' % required_text)
unique_item_text = []
items = sb.find_elements('[data-test="product-details"]')
for item in items:
if required_text.lower() in item.text.lower():
description = item.querySelector('a[data-test*="Card/title"]')
if description and description.text not in unique_item_text:
unique_item_text.append(description.text)
print("* " + description.text)
price = item.querySelector('[data-test="current-price"]')
if price:
print(" (" + price.text + ")")
item.scroll_into_view()
10 changes: 0 additions & 10 deletions examples/cdp_mode/raw_tavus.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/cdp_mode/raw_walmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
sb.click_if_visible('[data-automation-id="sb-btn-close-mark"]')
items = sb.find_elements('[data-item-id]')
for item in items:
if required_text in item.text:
if required_text.lower() in item.text.lower():
description = item.querySelector(
'[data-automation-id="product-title"]'
)
Expand Down
9 changes: 4 additions & 5 deletions examples/presenter/uc_presentation_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def test_presentation_4(self):
sb.click_if_visible('[data-automation-id="sb-btn-close-mark"]')
items = sb.find_elements('[data-item-id]')
for item in items:
if required_text in item.text:
if required_text.lower() in item.text.lower():
description = item.querySelector(
'[data-automation-id="product-title"]'
)
Expand Down Expand Up @@ -763,13 +763,12 @@ def test_presentation_4(self):
sb.activate_cdp_mode()
sb.goto("https://www.priceline.com")
sb.sleep(3)
input_selector = 'input[name="endLocation"]'
if not sb.is_element_present(input_selector):
input_selector = "div.location-input input"
input_selector = "div.location-input input"
sb.gui_hover_element(input_selector)
sb.mouse_click(input_selector)
sb.sleep(0.5)
location = "Portland, OR"
selection = "Oregon, United States" # (Dropdown option)
sb.gui_hover_element(input_selector)
sb.press_keys(input_selector, location)
sb.sleep(0.5)
sb.click(selection)
Expand Down
16 changes: 16 additions & 0 deletions examples/raw_uc_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""UC Mode Driver for evading bot-detection."""
from seleniumbase import Driver

driver = Driver(uc=True)
driver.get("https://browserscan.net/bot-detection")
driver.assert_element('strong:contains("Normal")')
driver.sleep(1)
driver.get("https://bot.sannysoft.com/")
driver.assert_element("#user-agent-result.passed")
driver.assert_element("#webdriver-result.passed")
driver.assert_element("#advanced-webdriver-result.passed")
driver.assert_element("#permissions-result.passed")
driver.assert_element("#plugins-length-result.passed")
driver.assert_element("#plugins-type-result.passed")
driver.sleep(1)
driver.quit()
4 changes: 2 additions & 2 deletions examples/test_chinese_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
BaseCase.main(__name__, __file__)


class ChinesePdfTests(BaseCase):
class ChinesePDFTests(BaseCase):
def test_chinese_pdf(self):
self.goto("data:,")
pdf = "https://seleniumbase.io/cdn/pdf/unittest_zh.pdf"

# Get and print PDF text
pdf_text = self.get_pdf_text(pdf, page=2)
pdf_text = self.get_pdf_text(pdf, page=2, nav=True)
print("\n" + pdf_text)

# Assert PDF contains the expected text on Page 2
Expand Down
10 changes: 7 additions & 3 deletions examples/test_get_pdf_text.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)
BaseCase.main(__name__, __file__, "--uc")


class PdfTests(BaseCase):
class PDFTests(BaseCase):
def test_get_pdf_text(self):
self.goto("data:,")
if self.headless:
self.skip("Skip this test in headless mode!")
if not self.undetectable or not self.external_pdf:
self.activate_cdp_mode(external_pdf=True)
pdf = (
"https://nostarch.com/download/"
"Automate_the_Boring_Stuff_sample_ch17.pdf"
)
pdf_text = self.get_pdf_text(pdf, page=1)
pdf_text = self.get_pdf_text(pdf, page=1, nav=True)
print("\n" + pdf_text)
7 changes: 5 additions & 2 deletions examples/test_pdf_asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
BaseCase.main(__name__, __file__)


class PdfAssertTests(BaseCase):
class PDFAssertTests(BaseCase):
def test_assert_pdf_text(self):
self.goto("data:,")
if self.headless:
self.skip("Skip this test in headless mode!")
if not self.undetectable or not self.external_pdf:
self.activate_cdp_mode(external_pdf=True)
# Assert PDF contains the expected text on Page 1
self.assert_pdf_text(
"https://nostarch.com/download/Automate_the_Boring_Stuff_dTOC.pdf",
"Programming Is a Creative Activity",
page=1,
)

# Assert PDF contains the expected text on any of the pages
self.assert_pdf_text(
"https://nostarch.com/download/Automate_the_Boring_Stuff_dTOC.pdf",
Expand Down
32 changes: 17 additions & 15 deletions examples/translations/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- SeleniumBase Docs -->

<a id="language_tests"></a>

<h2><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32"></a> 🌏 Translated Tests 🈺</h2>
Expand Down Expand Up @@ -48,7 +50,7 @@ class 私のテストクラス(セレニウムテストケース):
<a id="translation_api"></a>
<h2><img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32" /> Translation API 🈺</h2>

You can use SeleniumBase to selectively translate the method names of any test from one language to another with the console scripts interface. Additionally, the ``import`` line at the top of the Python file will change to import the new ``BaseCase``. Example: ``BaseCase`` becomes ``CasoDeTeste`` when a test is translated into Portuguese.
You can use SeleniumBase to selectively translate the method names of any test from one language to another with the console scripts interface. Additionally, the `import` line at the top of the Python file will change to import the new `BaseCase`. Example: `BaseCase` becomes `CasoDeTeste` when a test is translated into Portuguese.

```zsh
seleniumbase translate
Expand All @@ -59,19 +61,19 @@ seleniumbase translate
seleniumbase translate [SB_FILE.py] [LANGUAGE] [ACTION]

* Languages:
``--en`` / ``--English`` | ``--zh`` / ``--Chinese``
``--nl`` / ``--Dutch`` | ``--fr`` / ``--French``
``--it`` / ``--Italian`` | ``--ja`` / ``--Japanese``
``--ko`` / ``--Korean`` | ``--pt`` / ``--Portuguese``
``--ru`` / ``--Russian`` | ``--es`` / ``--Spanish``
`--en` / `--English` | `--zh` / `--Chinese`
`--nl` / `--Dutch` | `--fr` / `--French`
`--it` / `--Italian` | `--ja` / `--Japanese`
`--ko` / `--Korean` | `--pt` / `--Portuguese`
`--ru` / `--Russian` | `--es` / `--Spanish`

* Actions:
``-p`` / ``--print`` (Print translation output to the screen)
``-o`` / ``--overwrite`` (Overwrite the file being translated)
``-c`` / ``--copy`` (Copy the translation to a new ``.py`` file)
`-p` / `--print` (Print translation output to the screen)
`-o` / `--overwrite` (Overwrite the file being translated)
`-c` / `--copy` (Copy the translation to a new `.py` file)

* Options:
``-n`` (include line Numbers when using the Print action)
`-n` (include line Numbers when using the Print action)

* Examples:
Translate test_1.py into Chinese and only print the output:
Expand All @@ -83,14 +85,14 @@ Translate test_3.py into Dutch and make a copy of the file:

* Output:
Translates a SeleniumBase Python file into the language
specified. Method calls and ``import`` lines get swapped.
specified. Method calls and `import` lines get swapped.
Both a language and an action must be specified.
The ``-p`` action can be paired with one other action.
When running with ``-c`` (or ``--copy``) the new file name
The `-p` action can be paired with one other action.
When running with `-c` (or `--copy`) the new file name
will be the original name appended with an underscore
plus the 2-letter language code of the new language.
(Example: Translating ``test_1.py`` into Japanese with
``-c`` will create a new file called ``test_1_ja.py``.)
(Example: Translating `test_1.py` into Japanese with
`-c` will create a new file called `test_1_ja.py`.)
```

--------
Expand Down
Loading