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
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,36 @@ pytest my_first_test.py --demo

> (Chrome is the default browser if not specified with ``--browser``. On Linux, ``--headless`` is the default behavior.)

<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py"><img src="https://seleniumbase.io/cdn/gif/my_first_test_2.gif" alt="SeleniumBase Test" title="SeleniumBase Demo Mode" width="400" /></a>
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py"><img src="https://seleniumbase.io/cdn/gif/swag_labs_4.gif" alt="SeleniumBase Test" title="SeleniumBase Test" width="400" /></a>

<p align="left"><b>Here's the code for <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py">my_first_test.py</a>:</b></p>

```python
from seleniumbase import BaseCase

class MyTestClass(BaseCase):
def test_swag_labs(self):
self.open("https://www.saucedemo.com")
self.type("#user-name", "standard_user")
self.type("#password", "secret_sauce\n")
self.assert_element("#inventory_container")
self.assert_text("PRODUCTS", "span.title")
self.click('button[name*="backpack"]')
self.click("#shopping_cart_container a")
self.assert_text("YOUR CART", "span.title")
self.assert_text("Backpack", "div.cart_item")
self.click("button#checkout")
self.type("#first-name", "SeleniumBase")
self.type("#last-name", "Automation")
self.type("#postal-code", "77123")
self.click("input#continue")
self.assert_text("CHECKOUT: OVERVIEW")
self.assert_text("Backpack", "div.cart_item")
self.click("button#finish")
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
self.assert_element('img[alt="Pony Express"]')
self.js_click("a#logout_sidebar_link")
```

* By default, **[CSS Selectors](https://www.w3schools.com/cssref/css_selectors.asp)** are used for finding page elements.
* If you're new to CSS Selectors, games like [CSS Diner](http://flukeout.github.io/) can help you learn.
Expand Down
10 changes: 2 additions & 8 deletions examples/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Run an example test in Chrome: (Default: ``--browser=chrome``)
pytest my_first_test.py
```

<img src="https://seleniumbase.io/cdn/gif/swag_labs_4.gif" /><br />

Run an example test in Firefox:

```bash
Expand All @@ -29,14 +31,6 @@ pytest my_first_test.py --browser=firefox

Run an example test in Demo Mode: (highlight assertions)

```bash
pytest my_first_test.py --demo
```

<img src="https://seleniumbase.io/cdn/gif/my_first_test_2.gif" title="SeleniumBase Demo Mode" /><br />

Run a different example in Demo Mode:

```bash
pytest test_swag_labs.py --demo
```
Expand Down
22 changes: 13 additions & 9 deletions examples/basic_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""
Add an item to a shopping cart, and verify.
"""
from seleniumbase import BaseCase


class MyTestClass(BaseCase):
def test_basics(self):
self.open("https://store.xkcd.com/search")
self.type('input[name="q"]', "xkcd book\n")
self.assert_text("xkcd book", "div.results")
self.open("https://xkcd.com/353/")
self.click('a[rel="license"]')
self.go_back()
self.click_link("About")
self.click_link("comic #249")
self.assert_element('img[alt*="Chess"]')
self.open("https://www.saucedemo.com")
self.type("#user-name", "standard_user")
self.type("#password", "secret_sauce\n")
self.assert_element("#inventory_container")
self.assert_exact_text("PRODUCTS", "span.title")
self.click('button[name*="backpack"]')
self.click("#shopping_cart_container a")
self.assert_exact_text("YOUR CART", "span.title")
self.assert_text("Backpack", "div.cart_item")
self.js_click("a#logout_sidebar_link")
4 changes: 2 additions & 2 deletions examples/list_assert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class MyTestClass(BaseCase):
def test_assert_list_of_elements(self):
self.open("https://store.xkcd.com/collections/posters")
self.open("https://seleniumbase.io/demo_page")
self.assert_elements_present("head", "style", "script")
self.assert_elements("h1", "h2", "h3")
my_list = ["#top-menu", "#col-main", "#col-widgets"]
my_list = ["#myDropdown", "#myButton", "#svgRect"]
self.assert_elements(my_list)
44 changes: 28 additions & 16 deletions examples/my_first_test.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
"""
A complete end-to-end test for an e-commerce website.
"""
from seleniumbase import BaseCase


class MyTestClass(BaseCase):
def test_basics(self):
url = "https://store.xkcd.com/collections/posters"
self.open(url)
self.type('input[name="q"]', "xkcd book")
self.click('input[value="Search"]')
self.assert_text("xkcd: volume 0", "h3")
self.open("https://xkcd.com/353/")
self.assert_title("xkcd: Python")
self.assert_element('img[alt="Python"]')
self.click('a[rel="license"]')
self.assert_text("free to copy and reuse")
self.go_back()
self.click_link("About")
self.assert_exact_text("xkcd.com", "h2")
def test_swag_labs(self):
self.open("https://www.saucedemo.com")
self.type("#user-name", "standard_user")
self.type("#password", "secret_sauce\n")
self.assert_element("#inventory_container")
self.assert_text("PRODUCTS", "span.title")
self.click('button[name*="backpack"]')
self.click("#shopping_cart_container a")
self.assert_text("YOUR CART", "span.title")
self.assert_text("Backpack", "div.cart_item")
self.click("button#checkout")
self.type("#first-name", "SeleniumBase")
self.type("#last-name", "Automation")
self.type("#postal-code", "77123")
self.click("input#continue")
self.assert_text("CHECKOUT: OVERVIEW")
self.assert_text("Backpack", "div.cart_item")
self.click("button#finish")
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
self.assert_element('img[alt="Pony Express"]')
self.js_click("a#logout_sidebar_link")

####

Expand Down Expand Up @@ -123,10 +133,12 @@ def test_basics(self):
# whitespace in the TEXT assertion.
# So, self.assert_exact_text("Some Text") will find [" Some Text "].
#
# 7. If a URL starts with "://", then "https://" is automatically used.
# 7. self.js_click(SELECTOR) can be used to click on hidden elements.
#
# 8. If a URL starts with "://", then "https://" is automatically used.
# Example: [self.open("://URL")] becomes [self.open("https://URL")]
# This helps by reducing the line length by 5 characters.
#
# 8. For the full method list, see one of the following:
# 9. For the full method list, see one of the following:
# * SeleniumBase/seleniumbase/fixtures/base_case.py
# * SeleniumBase/help_docs/method_summary.md
2 changes: 1 addition & 1 deletion examples/swag_labs_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_swag_labs_basic_flow(self, username):
self.assert_exact_text("1", "span.shopping_cart_badge")

# Verify your cart
self.click("#shopping_cart_container")
self.click("#shopping_cart_container a")
self.assert_element('span:contains("Your Cart")')
self.assert_text(item_name, "div.inventory_item_name")
self.assert_exact_text("1", "div.cart_quantity")
Expand Down
8 changes: 4 additions & 4 deletions examples/test_download_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def test_download_files(self):

# Get file sizes in kB to compare actual values with displayed values
whl_file_kb = whl_file_bytes / 1000.0
whl_line_fi = self.get_text('a[href$=".whl"]')
whl_line = self.get_text('tbody th:contains("%s")' % whl_line_fi)
whl_line_fi = self.get_text('a[href$=".whl"]').strip()
whl_line = self.get_text('div.file:contains("%s")' % whl_line_fi)
whl_display_kb = float(whl_line.split("(")[1].split(" ")[0])
tar_gz_file_kb = tar_gz_file_bytes / 1000.0
tar_gz_line_fi = self.get_text('a[href$=".tar.gz"]')
tar_gz_line = self.get_text('tbody th:contains("%s")' % tar_gz_line_fi)
tar_gz_line_fi = self.get_text('a[href$=".tar.gz"]').strip()
tar_gz_line = self.get_text('div.file:contains("%s")' % tar_gz_line_fi)
tar_gz_display_kb = float(tar_gz_line.split("(")[1].split(" ")[0])

# Verify downloaded files are the correct size (account for rounding)
Expand Down
9 changes: 6 additions & 3 deletions examples/test_event_firing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def test_event_firing_webdriver(self):
print("\n* EventFiringWebDriver example *")
self.open("https://xkcd.com/1862/")
self.click("link=About")
self.open("https://store.xkcd.com/search")
self.type('input[name="q"]', "xkcd book\n")
self.open("https://xkcd.com/1822/")
self.open("https://xkcd.com/1820/")
self.assert_text("Security Advice", "#ctitle")
self.click('a:contains("Next >")')
self.assert_text("Incinerator", "#ctitle")
self.click('a[rel="next"]')
self.assert_text("Existential Bug Reports", "#ctitle")
4 changes: 2 additions & 2 deletions examples/test_swag_labs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_swag_labs_basic_flow(self):
self.assert_exact_text("1", "span.shopping_cart_badge")

# Verify your cart
self.click("#shopping_cart_container")
self.click("#shopping_cart_container a")
self.assert_element('span:contains("Your Cart")')
self.assert_text(item_name, "div.inventory_item_name")
self.assert_exact_text("1", "div.cart_quantity")
Expand All @@ -60,7 +60,7 @@ def test_swag_labs_basic_flow(self):
# Finish Checkout and verify that the cart is now empty
self.click("button#finish")
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
self.click("#shopping_cart_container")
self.click("#shopping_cart_container a")
self.assert_element_absent("div.inventory_item_name")
self.click("button#continue-shopping")
self.assert_element_absent("span.shopping_cart_badge")
Expand Down
15 changes: 15 additions & 0 deletions examples/test_xkcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from seleniumbase import BaseCase


class MyTestClass(BaseCase):
def test_xkcd(self):
self.open("https://xkcd.com/353/")
self.assert_title("xkcd: Python")
self.assert_element('img[alt="Python"]')
self.click('a[rel="license"]')
self.assert_text("free to copy and reuse")
self.go_back()
self.click_link("About")
self.assert_exact_text("xkcd.com", "h2")
self.click_link("comic #249")
self.assert_element('img[alt*="Chess"]')
10 changes: 5 additions & 5 deletions examples/xpath_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class XPathTests(BaseCase):
def test_xpath(self):
self.open("https://xkcd.com/1319/")
self.assert_element("//img")
self.assert_element("/html/body/div[2]/div[2]/img")
self.click("//ul/li[6]/a")
self.assert_text("xkcd.com", "//h2")
self.open("https://seleniumbase.io/demo_page")
self.assert_element("/html/body/form/table/tbody/tr[1]/td[1]/h1")
self.type('//*[@id="myTextInput"]', "XPath Test!")
self.click("/html/body/form/table/tbody/tr[3]/td[4]/button")
self.assert_text("SeleniumBase", '//table/tbody/tr[1]/td[2]/h2')
2 changes: 1 addition & 1 deletion mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lunr==0.6.1;python_version>="3.6"
nltk==3.6.7;python_version>="3.6"
watchdog==2.1.6;python_version>="3.6"
mkdocs==1.2.3;python_version>="3.6"
mkdocs-material==8.1.8;python_version>="3.6"
mkdocs-material==8.1.9;python_version>="3.6"
mkdocs-exclude-search==0.6.4;python_version>="3.6"
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.0.3;python_version>="3.6"
Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pip>=20.3.4;python_version<"3.6"
pip>=21.3.1;python_version>="3.6"
pip>=21.3.1;python_version>="3.6" and python_version<"3.7"
pip>=22.0.2;python_version>="3.7"
packaging>=20.9;python_version<"3.6"
packaging>=21.3;python_version>="3.6"
setuptools>=44.1.1;python_version<"3.5"
setuptools>=50.3.2;python_version>="3.5" and python_version<"3.6"
setuptools>=59.6.0;python_version>="3.6" and python_version<"3.7"
setuptools>=60.5.0;python_version>="3.7"
setuptools>=60.6.0;python_version>="3.7"
setuptools-scm>=5.0.2;python_version<"3.6"
setuptools-scm>=6.4.2;python_version>="3.6"
tomli>=1.2.2;python_version>="3.6" and python_version<"3.7"
Expand All @@ -27,7 +28,7 @@ idna==2.10;python_version<"3.6"
idna==3.3;python_version>="3.6"
chardet==3.0.4;python_version<"3.5"
chardet==4.0.0;python_version>="3.5"
charset-normalizer==2.0.10;python_version>="3.5"
charset-normalizer==2.0.11;python_version>="3.5"
urllib3==1.26.8
requests==2.27.0;python_version<"3.5"
requests==2.25.1;python_version>="3.5" and python_version<"3.6"
Expand All @@ -37,7 +38,7 @@ sniffio==1.2.0;python_version>="3.7"
h11==0.13.0;python_version>="3.7"
trio==0.19.0;python_version>="3.7"
trio-websocket==0.9.2;python_version>="3.7"
pyopenssl==21.0.0;python_version>="3.7"
pyopenssl==22.0.0;python_version>="3.7"
wsproto==1.0.0;python_version>="3.7"
selenium==3.141.0;python_version<"3.7"
selenium==4.1.0;python_version>="3.7"
Expand Down Expand Up @@ -88,7 +89,7 @@ pygments==2.5.2;python_version<"3.5"
pygments==2.11.2;python_version>="3.5"
prompt-toolkit==1.0.18;python_version<"3.5"
prompt-toolkit==2.0.10;python_version>="3.5" and python_version<"3.6.2"
prompt-toolkit==3.0.24;python_version>="3.6.2"
prompt-toolkit==3.0.26;python_version>="3.6.2"
decorator==4.4.2;python_version<"3.5"
decorator==5.1.1;python_version>="3.5"
ipython==5.10.0;python_version<"3.5"
Expand Down Expand Up @@ -118,7 +119,7 @@ Pillow==8.4.0;python_version>="3.6" and python_version<"3.7"
Pillow==9.0.0;python_version>="3.7"
typing-extensions==3.10.0.2;python_version<"3.6"
typing-extensions==4.0.0;python_version>="3.6" and python_version<"3.8"
rich==11.0.0;python_version>="3.6" and python_version<"4.0"
rich==11.1.0;python_version>="3.6.2" and python_version<"4.0"
tornado==5.1.1;python_version<"3.5"
tornado==6.1;python_version>="3.5"
pdfminer.six==20191110;python_version<"3.5"
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "2.4.3"
__version__ = "2.4.4"
37 changes: 23 additions & 14 deletions seleniumbase/console_scripts/sb_mkdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,29 @@ def main():
data.append("")
data.append("")
data.append("class MyTestClass(BaseCase):")
data.append(" def test_basics(self):")
data.append(' url = "https://store.xkcd.com/collections/posters"')
data.append(" self.open(url)")
data.append(' self.type(\'input[name="q"]\', "xkcd book")')
data.append(" self.click('input[value=\"Search\"]')")
data.append(' self.assert_text("xkcd: volume 0", "h3")')
data.append(' self.open("https://xkcd.com/353/")')
data.append(' self.assert_title("xkcd: Python")')
data.append(" self.assert_element('img[alt=\"Python\"]')")
data.append(" self.click('a[rel=\"license\"]')")
data.append(' self.assert_text("free to copy and reuse")')
data.append(" self.go_back()")
data.append(' self.click_link("About")')
data.append(' self.assert_exact_text("xkcd.com", "h2")')
data.append(" def test_swag_labs(self):")
data.append(' self.open("https://www.saucedemo.com")')
data.append(' self.type("#user-name", "standard_user")')
data.append(' self.type("#password", "secret_sauce\\n")')
data.append(' self.assert_element("#inventory_container")')
data.append(' self.assert_text("PRODUCTS", "span.title")')
data.append(" self.click('button[name*=\"backpack\"]')")
data.append(' self.click("#shopping_cart_container a")')
data.append(' self.assert_text("YOUR CART", "span.title")')
data.append(' self.assert_text("Backpack", "div.cart_item")')
data.append(' self.click("button#checkout")')
data.append(' self.type("#first-name", "SeleniumBase")')
data.append(' self.type("#last-name", "Automation")')
data.append(' self.type("#postal-code", "77123")')
data.append(' self.click("input#continue")')
data.append(' self.assert_text("CHECKOUT: OVERVIEW")')
data.append(' self.assert_text("Backpack", "div.cart_item")')
data.append(' self.click("button#finish")')
data.append(
' self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")'
)
data.append(" self.assert_element('img[alt=\"Pony Express\"]')")
data.append(' self.js_click("a#logout_sidebar_link")')
data.append("")
file_path = "%s/%s" % (dir_name, "my_first_test.py")
file = codecs.open(file_path, "w+", "utf-8")
Expand Down
Loading