4
4
class MyTestClass (BaseCase ):
5
5
6
6
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" )
7
10
self .open ("https://xkcd.com/353/" )
8
11
self .assert_title ("xkcd: Python" )
9
12
self .assert_element ('img[alt="Python"]' )
10
13
self .click ('a[rel="license"]' )
11
14
self .assert_text ("free to copy and reuse" )
12
15
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" )
18
18
19
19
####
20
20
@@ -23,14 +23,17 @@ def test_basic(self):
23
23
# **** NOTES / USEFUL INFO ****
24
24
#
25
25
# 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",
27
28
# "CLASS_NAME", and "ID", but most of those can be expressed as CSS.
29
+ #
28
30
# Here's an example of changing the "by":
29
31
# [
30
32
# from selenium.webdriver.common.by import By
31
33
# ...
32
34
# self.click('Next', by=By.PARTIAL_LINK_TEXT)
33
35
# ]
36
+ #
34
37
# XPath is used by default if the arg starts with "/", "./", or "(":
35
38
# [
36
39
# self.click('/html/body/div[3]/div[4]/p[2]/a')
@@ -39,27 +42,46 @@ def test_basic(self):
39
42
# If you're completely new to CSS selectors, right-click on a
40
43
# web page and select "Inspect" to see the CSS in the html.
41
44
#
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":
43
47
# [
44
48
# self.assert_element('img[alt="Python"]', timeout=15)
45
49
# ]
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
48
52
# 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.
50
54
# Default timeouts are configured in seleniumbase/config/settings.py
51
55
#
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"
59
63
#
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()
61
82
#
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:
63
85
# [
64
86
# self.assert_text("xkcd: volume 0", "h3")
65
87
# ]
@@ -68,33 +90,37 @@ def test_basic(self):
68
90
# text = self.get_text("h3")
69
91
# self.assert_true("xkcd: volume 0" in text)
70
92
# ]
71
- # Or :
93
+ # Is also the same as :
72
94
# [
73
- # text = self.find_element("h3").text
95
+ # element = self.find_element("h3")
96
+ # text = element.text
74
97
# self.assert_true("xkcd: volume 0" in text)
75
98
# ]
76
99
#
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:
78
111
# [
79
112
# title = self.get_attribute("#comic img", "title")
80
113
# ]
81
- # Can also be written as:
114
+ # Is the same as:
82
115
# [
83
116
# element = self.find_element("#comic img")
84
117
# title = element.get_attribute("title")
85
118
# ]
86
119
#
87
- # 5 . self.assert_exact_text(TEXT) ignores leading and trailing
120
+ # 6 . self.assert_exact_text(TEXT) ignores leading and trailing
88
121
# whitespace in the TEXT assertion.
89
122
# So, self.assert_exact_text("Some Text") will find [" Some Text "].
90
123
#
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
- #
98
124
# 7. If a URL starts with "://", then "https://" is automatically used.
99
125
# Example: [self.open("://URL")] becomes [self.open("https://URL")]
100
126
# This helps by reducing the line length by 5 characters.
0 commit comments