Update example tests
This commit is contained in:
parent
88f5230964
commit
994661af5a
|
@ -1,4 +1,4 @@
|
|||
"""Use SeleniumBase to test a Coffee Cart App."""
|
||||
"""Use SeleniumBase to test the Coffee Cart App."""
|
||||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
"""
|
||||
This test is only for Microsoft Edge (Chromium)!
|
||||
(Tested on Edge Version 96.0.1054.62)
|
||||
"""
|
||||
"""This test is only for Microsoft Edge (Chromium)!"""
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__, "--edge", "-s"])
|
||||
|
||||
|
||||
class EdgeTests(BaseCase):
|
||||
def test_edge(self):
|
||||
|
@ -13,7 +14,7 @@ class EdgeTests(BaseCase):
|
|||
print(' (Run this test using "--edge" or "--browser=edge")')
|
||||
self.skip('Use "--edge" or "--browser=edge"')
|
||||
if self.headless:
|
||||
self.open_if_not_url("about:blank")
|
||||
self.open("data:,")
|
||||
print("\n This test is NOT designed for Headless Mode!")
|
||||
self.skip('Do NOT use "--headless" with this test!')
|
||||
self.open("edge://settings/help")
|
||||
|
|
|
@ -5,7 +5,7 @@ BaseCase.main(__name__, __file__)
|
|||
class GitHubTests(BaseCase):
|
||||
def test_github(self):
|
||||
if self.headless or self.page_load_strategy == "none":
|
||||
self.open_if_not_url("about:blank")
|
||||
self.open_if_not_url("data:,")
|
||||
message = "Unsupported mode for this test."
|
||||
print("\n " + message)
|
||||
self.skip(message)
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
"""
|
||||
Solve the Wordle game using SeleniumBase.
|
||||
This test runs on archived versions of Wordle, containing Shadow-DOM.
|
||||
"""
|
||||
|
||||
"""Solve the Wordle game using SeleniumBase.
|
||||
This test runs on archived versions of Wordle, containing Shadow-DOM."""
|
||||
import ast
|
||||
import random
|
||||
import requests
|
||||
from seleniumbase import version_tuple
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__, "--sjw", "--pls=none"])
|
||||
|
||||
|
||||
class WordleTests(BaseCase):
|
||||
|
||||
|
|
|
@ -18,6 +18,3 @@ class GoogleTests(BaseCase):
|
|||
self.assert_text(expected_text, "#search")
|
||||
self.click('a:contains("%s")' % expected_text)
|
||||
self.assert_element(img)
|
||||
if "SeleniumBase" in search_key:
|
||||
self.click('img[alt="SeleniumBase"]')
|
||||
self.assert_element('img[title="SeleniumBase"]')
|
||||
|
|
|
@ -9,10 +9,10 @@ class UserAgentTests(BaseCase):
|
|||
original_user_agent = user_agent_detected
|
||||
if not self.user_agent:
|
||||
# Using the built-in user-agent string
|
||||
self._print("\n\nUser-Agent: %s" % user_agent_detected)
|
||||
print("\n\nUser-Agent: %s" % user_agent_detected)
|
||||
else:
|
||||
# User-agent was overridden using: --agent=STRING
|
||||
self._print("\n\nUser-Agent override: %s" % user_agent_detected)
|
||||
print("\n\nUser-Agent override: %s" % user_agent_detected)
|
||||
print("\n" + self.get_text(".ip-address p"))
|
||||
if not (self.headless or self.headless2 or self.xvfb):
|
||||
self.sleep(3)
|
||||
|
@ -20,7 +20,7 @@ class UserAgentTests(BaseCase):
|
|||
# Now change the user-agent using "execute_cdp_cmd()"
|
||||
if not self.is_chromium():
|
||||
msg = "\n* execute_cdp_cmd() is only for Chromium browsers"
|
||||
self._print(msg)
|
||||
print(msg)
|
||||
self.skip(msg)
|
||||
print("\n--------------------------")
|
||||
try:
|
||||
|
@ -35,7 +35,7 @@ class UserAgentTests(BaseCase):
|
|||
)
|
||||
self.open("http://whatsmyuseragent.org/")
|
||||
user_agent_detected = self.get_text(".user-agent p")
|
||||
self._print("\nUser-Agent override: %s" % user_agent_detected)
|
||||
print("\nUser-Agent override: %s" % user_agent_detected)
|
||||
print("\n" + self.get_text(".ip-address p") + "\n")
|
||||
if not (self.headless or self.headless2 or self.xvfb):
|
||||
self.sleep(3)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class AppleTests(BaseCase):
|
||||
|
@ -9,9 +10,11 @@ class AppleTests(BaseCase):
|
|||
self.message_duration = 2.0
|
||||
if self.headless:
|
||||
if self._multithreaded:
|
||||
self.open("data:,")
|
||||
print("Skipping test in headless multi-threaded mode.")
|
||||
self.skip("Skipping test in headless multi-threaded mode.")
|
||||
elif self.undetectable:
|
||||
self.open("data:,")
|
||||
print("Skipping test in headless undetectable mode.")
|
||||
self.skip("Skipping test in headless undetectable mode.")
|
||||
elif self.browser == "chrome" or self.browser == "edge":
|
||||
|
|
|
@ -9,7 +9,7 @@ class ChinesePdfTests(BaseCase):
|
|||
|
||||
# Get and print PDF text
|
||||
pdf_text = self.get_pdf_text(pdf, page=2)
|
||||
self._print("\n" + pdf_text)
|
||||
print("\n" + pdf_text)
|
||||
|
||||
# Assert PDF contains the expected text on Page 2
|
||||
self.assert_pdf_text(pdf, "个测试类", page=2)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class DemoSiteTests(BaseCase):
|
||||
|
@ -115,8 +116,3 @@ class DemoSiteTests(BaseCase):
|
|||
self.demo_mode = True
|
||||
self.type("input", "Have a Nice Day!")
|
||||
self.assert_text("SeleniumBase", "h2")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__, "-s"])
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Use SeleniumBase to download images and verify."""
|
||||
import os
|
||||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class DownloadImages(BaseCase):
|
||||
|
@ -21,7 +22,7 @@ class DownloadImages(BaseCase):
|
|||
self.assert_downloaded_file(filename)
|
||||
folder = "downloaded_files"
|
||||
file_path = os.path.join(folder, filename)
|
||||
self._print(file_path)
|
||||
print(file_path)
|
||||
|
||||
def test_download_images_via_screenshot(self):
|
||||
self.open("seleniumbase.io/error_page/")
|
||||
|
@ -48,9 +49,4 @@ class DownloadImages(BaseCase):
|
|||
file_path = os.path.join(folder, filename)
|
||||
image.screenshot(file_path)
|
||||
self.assert_downloaded_file(filename)
|
||||
self._print(file_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__, "-s"])
|
||||
print(file_path)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class PdfTests(BaseCase):
|
||||
|
@ -9,4 +10,4 @@ class PdfTests(BaseCase):
|
|||
"Automate_the_Boring_Stuff_sample_ch17.pdf"
|
||||
)
|
||||
pdf_text = self.get_pdf_text(pdf, page=1)
|
||||
self._print("\n" + pdf_text)
|
||||
print("\n" + pdf_text)
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
to modify a Google search into becoming a Bing search.
|
||||
set_attribute() -> Modifies the attribute of the first matching element.
|
||||
set_attributes() -> Modifies the attribute of all matching elements. """
|
||||
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
|
||||
class HackingTests(BaseCase):
|
||||
def test_hack_search(self):
|
||||
if self.headless:
|
||||
self.open_if_not_url("about:blank")
|
||||
self.open_if_not_url("data:,")
|
||||
print("\n This test is not for Headless Mode.")
|
||||
self.skip('Do not use "--headless" with this test.')
|
||||
self.open("https://google.com/ncr")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class ScrapeBingTests(BaseCase):
|
||||
|
@ -7,20 +8,20 @@ class ScrapeBingTests(BaseCase):
|
|||
self.wait_for_element("main h2 a")
|
||||
soup = self.get_beautiful_soup()
|
||||
titles = [item.text for item in soup.select("main h2 a")]
|
||||
self._print("\nSearch Result Headers:")
|
||||
print("\nSearch Result Headers:")
|
||||
for title in titles:
|
||||
if (
|
||||
"seleniumbase/" in title.lower()
|
||||
or "SeleniumBase Docs" in title
|
||||
):
|
||||
self._print(" " + title)
|
||||
print(" " + title)
|
||||
links = [item["href"] for item in soup.select("main h2 a")]
|
||||
self._print("Search Result Links:")
|
||||
print("Search Result Links:")
|
||||
for link in links:
|
||||
if (
|
||||
"github.com/seleniumbase" in link.lower()
|
||||
or "https://seleniumbase.io/" in link.lower()
|
||||
):
|
||||
self._print(" " + link)
|
||||
print(" " + link)
|
||||
self.click_if_visible('a[href="https://github.com/seleniumbase"]')
|
||||
self._print("Last Page = " + self.get_current_url())
|
||||
print("Last Page = " + self.get_current_url())
|
||||
|
|
|
@ -8,10 +8,15 @@ Default mobile settings for User Agent and Device Metrics if not specified:
|
|||
"""
|
||||
from seleniumbase import BaseCase
|
||||
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__, "--mobile", "--edge", "-s"])
|
||||
|
||||
|
||||
class SkypeTests(BaseCase):
|
||||
def test_skype_mobile_site(self):
|
||||
if not self.mobile_emulator:
|
||||
self.open("data:,")
|
||||
print("\n This test is only for mobile-device web browsers!")
|
||||
print(' (Use "--mobile" to run this test in Mobile Mode!)')
|
||||
self.skip('Use "--mobile" to run this test in Mobile Mode!')
|
||||
|
@ -27,8 +32,3 @@ class SkypeTests(BaseCase):
|
|||
self.highlight("#get-skype-0_android-download")
|
||||
self.highlight('[data-bi-id*="ios"]')
|
||||
self.highlight('[data-bi-id*="windows10"]')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from pytest import main
|
||||
main([__file__, "--mobile", "--edge", "-s"])
|
||||
|
|
|
@ -5,6 +5,7 @@ class ChromedriverTests(BaseCase):
|
|||
def test_fail_if_using_an_old_chromedriver(self):
|
||||
self.open("data:,")
|
||||
if self.browser != "chrome":
|
||||
self.open_if_not_url("data:,")
|
||||
print("\n This test is only for Chrome!")
|
||||
print(" (Run with: '--browser=chrome')")
|
||||
self.skip("This test is only for Chrome!")
|
||||
|
|
|
@ -9,16 +9,16 @@ class UserAgentTests(BaseCase):
|
|||
original_user_agent = user_agent_detected
|
||||
if not self.user_agent:
|
||||
# Using the built-in user-agent string
|
||||
self._print("\n\nUser-Agent = %s\n" % user_agent_detected)
|
||||
print("\n\nUser-Agent = %s\n" % user_agent_detected)
|
||||
else:
|
||||
# User-agent was overridden using: --agent=STRING
|
||||
self._print("\n\nUser-Agent override = %s\n" % user_agent_detected)
|
||||
print("\n\nUser-Agent override = %s\n" % user_agent_detected)
|
||||
if not (self.headless or self.headless2 or self.xvfb):
|
||||
self.sleep(3)
|
||||
if not self.is_chromium():
|
||||
# Skip the rest of the test if not using a Chromium browser
|
||||
msg = "\n* execute_cdp_cmd() is only for Chromium browsers"
|
||||
self._print(msg)
|
||||
print(msg)
|
||||
self.skip(msg)
|
||||
try:
|
||||
# Now change the user-agent using "execute_cdp_cmd()"
|
||||
|
@ -34,7 +34,7 @@ class UserAgentTests(BaseCase):
|
|||
)
|
||||
self.open("https://www.whatsmyua.info/")
|
||||
user_agent_detected = self.get_text("#custom-ua-string")
|
||||
self._print("\nUser-Agent override = %s\n" % user_agent_detected)
|
||||
print("\nUser-Agent override = %s\n" % user_agent_detected)
|
||||
if not (self.headless or self.headless2 or self.xvfb):
|
||||
self.sleep(3)
|
||||
finally:
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from seleniumbase import BaseCase
|
||||
BaseCase.main(__name__, __file__)
|
||||
|
||||
|
||||
class YouTubeSearchTests(BaseCase):
|
||||
def test_youtube_autocomplete_results(self):
|
||||
"""Verify YouTube autocomplete search results."""
|
||||
if self.headless:
|
||||
self.open("about:blank")
|
||||
self.open_if_not_url("data:,")
|
||||
message = "This test is skipped in headless mode."
|
||||
print(message)
|
||||
self.skip(message)
|
||||
|
|
Loading…
Reference in New Issue