Skip to content

Commit c8aa891

Browse files
committed
Update the example test
1 parent 39a8c9f commit c8aa891

File tree

3 files changed

+30
-46
lines changed

3 files changed

+30
-46
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,11 @@ class MyTestClass(BaseCase):
122122
self.open('http://xkcd.com/353/')
123123
self.assert_element('img[alt="Python"]')
124124
self.click('a[rel="license"]')
125-
text = self.get_text("div center")
126-
self.assertTrue("reuse any of my drawings" in text)
127-
self.open('http://xkcd.com/1481/')
128-
title = self.get_attribute('#comic img', 'title')
129-
self.assertTrue('connections to the server' in title)
130-
self.click_link_text('Blag')
125+
self.assert_text('free to copy', 'div center')
126+
self.open("http://xkcd.com/1481/")
127+
title = self.get_attribute("#comic img", "title")
128+
self.assertTrue("86,400 seconds per day" in title)
129+
self.click('link=Blag')
131130
self.assert_text('The blag of the webcomic', 'h2')
132131
self.update_text('input#s', 'Robots!\n')
133132
self.assert_text('Hooray robots!', '#content')

examples/my_first_test.py

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ def test_basic(self):
77
self.open('http://xkcd.com/353/') # Navigate to the web page
88
self.assert_element('img[alt="Python"]') # Assert element on page
99
self.click('a[rel="license"]') # Click element on page
10-
text = self.get_text("div center") # Grab text from page element
11-
self.assertTrue("reuse any of my drawings" in text)
12-
self.open('http://xkcd.com/1481/')
13-
title = self.get_attribute('#comic img', 'title') # Grab an attribute
14-
self.assertTrue('connections to the server' in title)
15-
self.click_link_text('Blag') # Click on link with the text
16-
self.assert_text('The blag of the webcomic', 'h2') # Assert text in h2
10+
self.assert_text('free to copy', 'div center') # Assert text on page
11+
self.open("http://xkcd.com/1481/")
12+
title = self.get_attribute("#comic img", "title") # Grab an attribute
13+
self.assertTrue("86,400 seconds per day" in title)
14+
self.click('link=Blag') # Click on link with the text
15+
self.assert_text('The blag of the webcomic', 'h2')
1716
self.update_text('input#s', 'Robots!\n') # Fill in field with the text
1817
self.assert_text('Hooray robots!', '#content')
1918
self.open('http://xkcd.com/1319/')
@@ -26,33 +25,25 @@ def test_basic(self):
2625
# **** NOTES / USEFUL INFO ****
2726
#
2827
# 1. By default, CSS Selectors are used to identify elements.
29-
# You can use other identification options like PARTIAL_LINK_TEXT:
28+
# Other options include: "LINK_TEXT", "PARTIAL_LINK_TEXT", "NAME",
29+
# "CLASS_NAME", and "ID", but most of those can be expressed as CSS.
30+
# Here's an example of changing the "by":
3031
# [
3132
# from selenium.webdriver.common.by import By
3233
# ...
3334
# self.click('Next', by=By.PARTIAL_LINK_TEXT)
3435
# ]
35-
# For the full list of `By` options, type ``dir(By)`` into a python
36-
# command prompt after importing it (or in ipdb debugger mode). Ex:
37-
# {
38-
# >>> dir(By)
39-
# ['CLASS_NAME', 'CSS_SELECTOR', 'ID', 'LINK_TEXT', 'NAME', ...
40-
# }
4136
# XPath is used by default if the arg starts with "/", "./", or "(":
4237
# [
4338
# self.click('/html/body/div[3]/div[4]/p[2]/a')
4439
# ]
45-
# But if you want XPath-clicking to be more clear in the code, use:
46-
# [
47-
# self.click_xpath('/html/body/div[3]/div[4]/p[2]/a')
48-
# ]
4940
#
5041
# If you're completely new to CSS selectors, right-click on a
51-
# web page and select "Inspect Element" to see the CSS in the html.
42+
# web page and select "Inspect" to see the CSS in the html.
5243
#
5344
# 2. Most methods have the optional `timeout` argument. Ex:
5445
# [
55-
# self.get_text('center', timeout=15)
46+
# self.get_text('div center', timeout=15)
5647
# ]
5748
# The `timeout` argument tells the method how many seconds to wait
5849
# for an element to appear before raising an exception. This is
@@ -62,33 +53,28 @@ def test_basic(self):
6253
#
6354
# 3. There's usually more than one way to do the same thing. Ex:
6455
# [
65-
# header_text = self.get_text('header h2')
66-
# self.assertTrue('The blag of the webcomic' in header_text)
56+
# self.assert_text('free to copy', 'div center')
6757
# ]
68-
# Can be simplified to:
69-
# [
70-
# self.assert_text('The blag of the webcomic', 'header_text')
71-
# ]
72-
#
73-
# The following line:
58+
# Is the same as:
7459
# [
75-
# title = self.get_attribute('#comic img', 'title')
60+
# text = self.get_text("div center")
61+
# self.assertTrue("free to copy" in text)
7662
# ]
77-
# Can also be written as:
63+
# Or:
7864
# [
79-
# element = self.find_element('#comic img')
80-
# title = element.get_attribute('title')
65+
# text = self.find_element('div center').text
66+
# assert("free to copy" in text)
8167
# ]
8268
#
8369
# And the following line:
8470
# [
85-
# text = self.get_text("div center")
71+
# title = self.get_attribute("#comic img", "title")
8672
# ]
8773
# Can also be written as:
8874
# [
89-
# text = self.find_element('div center').text
75+
# element = self.find_element("#comic img")
76+
# title = element.get_attribute("title")
9077
# ]
91-
# ...and in many more ways!
9278
#
9379
# For backwards-compatibilty, some methods have multiple names.
9480
# Ex: wait_for_element_visible() is the same as find_element().

integrations/node_js/my_first_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ def test_basic(self):
77
self.open('http://xkcd.com/353/')
88
self.assert_element('img[alt="Python"]')
99
self.click('a[rel="license"]')
10-
text = self.get_text("div center")
11-
self.assertTrue("reuse any of my drawings" in text)
12-
self.open('http://xkcd.com/1481/')
13-
title = self.get_attribute('#comic img', 'title')
14-
self.assertTrue('connections to the server' in title)
10+
self.assert_text('free to copy', 'div center')
11+
self.open("http://xkcd.com/1481/")
12+
title = self.get_attribute("#comic img", "title")
13+
self.assertTrue("86,400 seconds per day" in title)
1514
self.click('link=Blag')
1615
self.assert_text('The blag of the webcomic', 'h2')
1716
self.update_text('input#s', 'Robots!\n')

0 commit comments

Comments
 (0)