Skip to content

Commit 96ea531

Browse files
authored
Merge pull request #1965 from seleniumbase/general-refactoring
The big refactor, and more
2 parents 614af48 + 8ace0a8 commit 96ea531

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+803
-804
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class CoffeeCartTest(BaseCase):
136136

137137
<p>💡 With raw Selenium, commands that use selectors need to specify the type of selector (eg. <code>"css selector", "button#myButton"</code>). With SeleniumBase, there's auto-detection between CSS Selectors and XPath, which means you don't need to specify the type of selector in your commands (<i>but optionally you could</i>).</p>
138138

139-
<p>💡 SeleniumBase methods often perform multiple actions in a single method call. For example, <code>self.type(selector,text)</code> does the following:<br />1. Waits for the element to be visible.<br />2. Waits for the element to be interactive.<br />3. Clears the text field.<br />4. Types in the new text.<br />5. Presses Enter/Submit if the text ends in "\n".<br />With raw Selenium, those actions require multiple method calls.</p>
139+
<p>💡 SeleniumBase methods often perform multiple actions in a single method call. For example, <code>self.type(selector,text)</code> does the following:<br />1. Waits for the element to be visible.<br />2. Waits for the element to be interactive.<br />3. Clears the text field.<br />4. Types in the new text.<br />5. Presses Enter/Submit if the text ends in <code>"\n"</code>.<br />With raw Selenium, those actions require multiple method calls.</p>
140140

141141
<p>💡 SeleniumBase uses default timeout values when not set:<br />
142142
✅<code>self.click("button")</code><br />
@@ -659,8 +659,8 @@ pytest test_coffee_cart.py --trace
659659
--incognito # (Enable Chrome's Incognito mode.)
660660
--guest # (Enable Chrome's Guest mode.)
661661
--devtools # (Open Chrome's DevTools when the browser opens.)
662-
--reuse-session | --rs # (Reuse browser session for all tests.)
663-
--reuse-class-session | --rcs # (Reuse session for tests in class.)
662+
--rs | --reuse-session # (Reuse browser session for all tests.)
663+
--rcs | --reuse-class-session # (Reuse session for tests in class.)
664664
--crumbs # (Delete all cookies between tests reusing a session.)
665665
--disable-beforeunload # (Disable the "beforeunload" event on Chrome.)
666666
--window-size=WIDTH,HEIGHT # (Set the browser's starting window size.)

examples/custom_settings.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,22 @@
1919
# Selenium default = "normal"
2020
PAGE_LOAD_STRATEGY = "normal"
2121

22-
# If False, only logs from the most recent test run will be saved.
22+
# If True, existing logs from past test runs will be saved and take up space.
23+
# If False, only the logs from the most recent test run will be saved locally.
24+
# You can also archive existing logs on the command line with: "--archive_logs"
2325
ARCHIVE_EXISTING_LOGS = False
26+
27+
# If True, existing downloads from past runs will be saved and take up space.
28+
# If False, only the downloads from the most recent run will be saved locally.
2429
ARCHIVE_EXISTING_DOWNLOADS = False
2530

31+
# If True, the last page screenshot will include the <body> and background.
32+
# If False, the last page screenshot will only include the <body> section.
33+
# Depending on the screen size, including a background could make the <body>
34+
# appear very small in the screenshot, which may require manually zooming in
35+
# on the <body> to see page details if you decide to include the background.
36+
SCREENSHOT_WITH_BACKGROUND = False
37+
2638
# If True, switch to new tabs automatically if a click opens a new one.
2739
# (Only happens if the initial tab is still on same URL as before.)
2840
SWITCH_TO_NEW_TABS_ON_CLICK = True

examples/hack_the_planet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_all_your_base_are_belong_to_us(self):
196196
self.set_text_content('a[prettyslug="your-profile"]', "BASE")
197197
self.set_text_content('a[prettyslug="connect-tools"]', "ARE")
198198
self.set_text_content('a[prettyslug="administration"]', "BELONG")
199-
self.set_text_content('a[prettyslug="tutorials"]', "TO US")
199+
self.set_text_content('a[prettyslug*="tutorials"]', "TO US")
200200
self.set_text_content("h1.article_title", aybabtu)
201201
self.highlight("h1", loops=4, scroll=False)
202202
self.highlight("div#global_menu", loops=2, scroll=False)
@@ -205,7 +205,7 @@ def test_all_your_base_are_belong_to_us(self):
205205
self.highlight('a[prettyslug="your-profile"]', loops=2, scroll=False)
206206
self.highlight('a[prettyslug="connect-tools"]', loops=1, scroll=False)
207207
self.highlight('a[prettyslug="administration"]', loops=1, scroll=False)
208-
self.highlight('a[prettyslug="tutorials"]', loops=2, scroll=False)
208+
self.highlight('a[prettyslug*="tutorials"]', loops=2, scroll=False)
209209
self.highlight("h1.article_title", loops=5, scroll=False)
210210

211211
self.open("https://kubernetes.io/")

examples/migration/raw_selenium/ReadMe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ With a complete test automation framework built, most of the hard work is alread
4747

4848
<p>💡 With raw Selenium, commands that use selectors need to specify the type of selector (eg. <code>"css selector", "button#myButton"</code>). With SeleniumBase, there's auto-detection between CSS Selectors and XPath, which means you don't need to specify the type of selector in your commands (<i>but optionally you could</i>).</p>
4949

50-
<p>💡 SeleniumBase methods often perform multiple actions in a single method call. For example, <code>self.type(selector,text)</code> does the following:<br />1. Waits for the element to be visible.<br />2. Waits for the element to be interactive.<br />3. Clears the text field.<br />4. Types in the new text.<br />5. Presses Enter/Submit if the text ends in "\n".<br />With raw Selenium, those actions require multiple method calls.</p>
50+
<p>💡 SeleniumBase methods often perform multiple actions in a single method call. For example, <code>self.type(selector,text)</code> does the following:<br />1. Waits for the element to be visible.<br />2. Waits for the element to be interactive.<br />3. Clears the text field.<br />4. Types in the new text.<br />5. Presses Enter/Submit if the text ends in <code>"\n"</code>.<br />With raw Selenium, those actions require multiple method calls.</p>
5151

5252
<p>💡 SeleniumBase uses default timeout values when not set, which means that methods automatically wait for elements to appear (<i>up to the timeout limit</i>) before failing:<br />✅<code>self.click("button")</code><br />With raw Selenium, methods would fail instantly (<i>by default</i>) if an element needed more time to load:<br />❌<code>self.driver.find_element(by="css selector", value="button").click()</code><br />(Reliable code is better than unreliable code.)</p>
5353

@@ -64,4 +64,4 @@ With a complete test automation framework built, most of the hard work is alread
6464

6565
--------
6666

67-
[<img src="https://seleniumbase.io/cdn/img/fancy_logo_14.png" title="SeleniumBase" width="290">](https://github.com/seleniumbase/SeleniumBase)
67+
[<img src="https://seleniumbase.github.io/cdn/img/fancy_logo_14.png" title="SeleniumBase" width="290">](https://github.com/seleniumbase/SeleniumBase)

examples/test_download_files.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Use SeleniumBase to download files and verify."""
22
import math
33
from seleniumbase import BaseCase
4+
BaseCase.main(__name__, __file__)
45

56

67
class DownloadTests(BaseCase):

examples/test_error_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ def test_error_page(self):
1414
self.highlight('img[alt*="404"]')
1515
self.highlight("img#octobi_wan_catnobi")
1616
self.highlight("img#speeder")
17-
self.save_screenshot_after_test = True # Automatic if test fails
17+
self.save_screenshot_after_test = True

examples/test_geolocation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ def test_geolocation(self):
3636
self.open("https://www.openstreetmap.org/")
3737
self.click("span.geolocate")
3838
self.assert_url_contains("48.87645/2.26340")
39+
self.save_screenshot_to_logs()
3940
if not (self.headless or self.headless2 or self.xvfb):
4041
self.sleep(2.5)

examples/translations/chinese_test_1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_例子1(self):
1616
self.输入文本("#searchInput", "麻婆豆腐")
1717
self.单击("#searchButton")
1818
self.断言文本("麻婆豆腐", "#firstHeading")
19-
self.断言元素('div.thumb div:contains("一家中餐館的麻婆豆腐")')
19+
self.断言元素('figure:contains("一家中餐館的麻婆豆腐")')
2020
self.输入文本("#searchInput", "精武英雄")
2121
self.单击("#searchButton")
2222
self.断言元素('img[src*="Fist_of_legend.jpg"]')

examples/translations/spanish_test_1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def test_ejemplo_1(self):
1111
self.escriba('[name="search"]', "Parque de Atracciones Tibidabo")
1212
self.haga_clic('button:contains("Buscar")')
1313
self.verificar_texto("Tibidabo", "#firstHeading")
14-
self.verificar_elemento('img[alt*="Tibidabo"]')
14+
self.verificar_elemento('img[src*="Tibidabo"]')
1515
self.escriba('input[name="search"]', "Palma de Mallorca")
1616
self.haga_clic('button:contains("Buscar")')
1717
self.verificar_texto("Palma de Mallorca", "#firstHeading")
18-
self.verificar_elemento('img[alt*="Palma"]')
18+
self.verificar_elemento('img[src*="Palma"]')
1919
self.volver()
2020
self.verificar_url_contiene("Tibidabo")
2121
self.adelante()

help_docs/customizing_test_runs.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ pytest test_swag_labs.py --mobile
7373
# Run mobile tests specifying CSS Width, CSS Height, and Pixel-Ratio
7474
pytest test_swag_labs.py --mobile --metrics="360,640,2"
7575

76+
# Run a test with an option to evade bot-detection services
77+
pytest verify_undetected.py --uc
78+
7679
# Run tests while changing SeleniumBase default settings
7780
pytest my_first_test.py --settings-file=custom_settings.py
7881
```
@@ -177,8 +180,8 @@ pytest my_first_test.py --settings-file=custom_settings.py
177180
--incognito # (Enable Chrome's Incognito mode.)
178181
--guest # (Enable Chrome's Guest mode.)
179182
--devtools # (Open Chrome's DevTools when the browser opens.)
180-
--reuse-session | --rs # (Reuse browser session for all tests.)
181-
--reuse-class-session | --rcs # (Reuse session for tests in class.)
183+
--rs | --reuse-session # (Reuse browser session for all tests.)
184+
--rcs | --reuse-class-session # (Reuse session for tests in class.)
182185
--crumbs # (Delete all cookies between tests reusing a session.)
183186
--disable-beforeunload # (Disable the "beforeunload" event on Chrome.)
184187
--window-size=WIDTH,HEIGHT # (Set the browser's starting window size.)

0 commit comments

Comments
 (0)