44class MyTestClass (BaseCase ):
55
66 def test_basic (self ):
7+ self .open ("https://store.xkcd.com/search" )
8+ self .type ('input[name="q"]' , "xkcd book\n " )
9+ self .assert_text ("xkcd: volume 0" , "h3" )
710 self .open ("https://xkcd.com/353/" )
811 self .assert_title ("xkcd: Python" )
912 self .assert_element ('img[alt="Python"]' )
1013 self .click ('a[rel="license"]' )
1114 self .assert_text ("free to copy and reuse" )
1215 self .go_back ()
13- self .click ("link=About" )
14- self .assert_text ("xkcd.com" , "h2" )
15- self .open ("://store.xkcd.com/collections/everything" )
16- self .update_text ("input.search-input" , "xkcd book\n " )
17- self .assert_exact_text ("xkcd: volume 0" , "h3" )
16+ self .click_link_text ("About" )
17+ self .assert_exact_text ("xkcd.com" , "h2" )
1818
1919 ####
2020
@@ -23,14 +23,17 @@ def test_basic(self):
2323 # **** NOTES / USEFUL INFO ****
2424 #
2525 # 1. By default, CSS Selectors are used to identify elements.
26- # Other options include: "LINK_TEXT", "PARTIAL_LINK_TEXT", "NAME",
26+ # CSS Guide: "https://www.w3schools.com/cssref/css_selectors.asp".
27+ # Other selectors include: "LINK_TEXT", "PARTIAL_LINK_TEXT", "NAME",
2728 # "CLASS_NAME", and "ID", but most of those can be expressed as CSS.
29+ #
2830 # Here's an example of changing the "by":
2931 # [
3032 # from selenium.webdriver.common.by import By
3133 # ...
3234 # self.click('Next', by=By.PARTIAL_LINK_TEXT)
3335 # ]
36+ #
3437 # XPath is used by default if the arg starts with "/", "./", or "(":
3538 # [
3639 # self.click('/html/body/div[3]/div[4]/p[2]/a')
@@ -39,27 +42,46 @@ def test_basic(self):
3942 # If you're completely new to CSS selectors, right-click on a
4043 # web page and select "Inspect" to see the CSS in the html.
4144 #
42- # 2. Most methods have the optional `timeout` argument. Ex:
45+ # 2. Most methods have the optional "timeout" argument.
46+ # Here's an example of changing the "timeout":
4347 # [
4448 # self.assert_element('img[alt="Python"]', timeout=15)
4549 # ]
46- # The ` timeout` argument tells the method how many seconds to wait
47- # for an element to appear before raising an exception . This is
50+ # The " timeout" argument tells the method how many seconds to wait
51+ # for an element to appear before failing the test . This is
4852 # useful if a web page needs additional time to load an element.
49- # If you don't specify a ` timeout` , a default timeout is used.
53+ # If you don't specify a " timeout" , a default timeout is used.
5054 # Default timeouts are configured in seleniumbase/config/settings.py
5155 #
52- # 3. SeleniumBase methods are very versatile . For example,
53- # self.update_text (SELECTOR, TEXT) does the following:
54- # * Waits for the element to be visible
55- # * Waits for the element to be interactive
56- # * Clears the text field
57- # * Types in the new text
58- # * Hits Enter/Submit ( if the text ends in "\n")
56+ # 3. SeleniumBase methods often perform multiple actions . For example,
57+ # self.type (SELECTOR, TEXT) will do the following:
58+ # * Wait for the element to be visible
59+ # * Wait for the element to be interactive
60+ # * Clear the text field
61+ # * Type in the new text
62+ # * Press Enter/Submit if the text ends in "\n"
5963 #
60- # self.update_text(S, T) can also be written as self.type(S, T)
64+ # 4. Duplicate method names may exist for the same method:
65+ # (This makes it easier to switch over from other test frameworks.)
66+ # Example:
67+ # self.open() = self.visit() = self.open_url() = self.goto()
68+ # self.type() = self.update_text() = self.input()
69+ # self.send_keys() = self.add_text()
70+ # self.get_element() = self.wait_for_element_present()
71+ # self.find_element() = self.wait_for_element_visible()
72+ # = self.wait_for_element()
73+ # self.assert_element() = self.assert_element_visible()
74+ # self.assert_text() = self.assert_text_visible()
75+ # self.find_text() = self.wait_for_text_visible()
76+ # = self.wait_for_text()
77+ # self.click_link_text(text) = self.click(link=text)
78+ # = self.click_link(text)
79+ # * self.get(url) is SPECIAL: *
80+ # If {url} is a valid URL, self.get() works just like self.open()
81+ # Otherwise {url} becomes a selector for calling self.get_element()
6182 #
62- # 4. There's usually more than one way to do the same thing. Ex:
83+ # 5. There's usually more than one way to do the same thing.
84+ # Example 1:
6385 # [
6486 # self.assert_text("xkcd: volume 0", "h3")
6587 # ]
@@ -68,33 +90,37 @@ def test_basic(self):
6890 # text = self.get_text("h3")
6991 # self.assert_true("xkcd: volume 0" in text)
7092 # ]
71- # Or :
93+ # Is also the same as :
7294 # [
73- # text = self.find_element("h3").text
95+ # element = self.find_element("h3")
96+ # text = element.text
7497 # self.assert_true("xkcd: volume 0" in text)
7598 # ]
7699 #
77- # And the following line:
100+ # Example 2:
101+ # [
102+ # self.assert_exact_text("xkcd.com", "h2")
103+ # ]
104+ # Is the same as:
105+ # [
106+ # text = self.get_text("h2").strip()
107+ # self.assert_true("xkcd.com".strip() == text)
108+ # ]
109+ #
110+ # Example 3:
78111 # [
79112 # title = self.get_attribute("#comic img", "title")
80113 # ]
81- # Can also be written as:
114+ # Is the same as:
82115 # [
83116 # element = self.find_element("#comic img")
84117 # title = element.get_attribute("title")
85118 # ]
86119 #
87- # 5 . self.assert_exact_text(TEXT) ignores leading and trailing
120+ # 6 . self.assert_exact_text(TEXT) ignores leading and trailing
88121 # whitespace in the TEXT assertion.
89122 # So, self.assert_exact_text("Some Text") will find [" Some Text "].
90123 #
91- # 6. For backwards-compatibilty, some SeleniumBase methods that do the
92- # same thing have multiple names, kept on from previous versions.
93- # Ex: self.wait_for_element() is the same as self.find_element().
94- # Both search for and return the element, and raise an exception if
95- # the element does not appear on the page within the timeout limit.
96- # And self.assert_element() does this too (without returning it).
97- #
98124 # 7. If a URL starts with "://", then "https://" is automatically used.
99125 # Example: [self.open("://URL")] becomes [self.open("https://URL")]
100126 # This helps by reducing the line length by 5 characters.
0 commit comments