Skip to content

Commit 3d9f067

Browse files
authored
Merge pull request #184 from seleniumbase/refactoring-updates
Refactoring, Updates, Fixes, and New Methods
2 parents e6dde2f + 7a20c7e commit 3d9f067

File tree

16 files changed

+327
-177
lines changed

16 files changed

+327
-177
lines changed

README.md

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
1-
<img src="https://cdn2.hubspot.net/hubfs/100006/images/expanded_icons_2.png" title="SeleniumBase" height="145">
1+
<img src="https://cdn2.hubspot.net/hubfs/100006/images/SB_Logo3d.png" title="SeleniumBase" height="48">
22

3-
## SeleniumBase &middot; [![](https://img.shields.io/pypi/v/seleniumbase.svg)](https://pypi.python.org/pypi/seleniumbase) [![Build Status](https://travis-ci.org/seleniumbase/SeleniumBase.svg?branch=master)](https://travis-ci.org/seleniumbase/SeleniumBase)<br />
3+
[![](https://img.shields.io/pypi/v/seleniumbase.svg)](https://pypi.python.org/pypi/seleniumbase) [![Build Status](https://travis-ci.org/seleniumbase/SeleniumBase.svg?branch=master)](https://travis-ci.org/seleniumbase/SeleniumBase) [![GitHub stars](https://img.shields.io/github/stars/seleniumbase/seleniumbase.svg "GitHub stars")](https://github.com/seleniumbase/SeleniumBase/stargazers)<br />
44

5-
SeleniumBase simplifies browser-based test automation with [WebDriver](https://docs.microsoft.com/en-us/microsoft-edge/webdriver) & [Pytest](https://github.com/pytest-dev/pytest).
5+
A reliable solution for fast & simple browser automation and testing with [WebDriver](https://docs.microsoft.com/en-us/microsoft-edge/webdriver) & [Pytest](https://github.com/pytest-dev/pytest).
66

7-
#### Quick start in a few steps: (requires [Python](https://www.python.org/downloads/))
7+
#### Quick start in a few steps: (Requires [Python](https://www.python.org/downloads/) and [Git](https://git-scm.com/))
88

99
```bash
10-
python -m pip install -U pip
11-
pip install -U seleniumbase --no-cache-dir
10+
git clone https://github.com/seleniumbase/SeleniumBase.git
11+
cd SeleniumBase
12+
python -m pip install pip --upgrade
13+
pip install -r requirements.txt --upgrade
14+
python setup.py develop
15+
1216
seleniumbase install chromedriver
13-
seleniumbase mkdir browser_tests
14-
cd browser_tests
17+
18+
cd examples
1519
pytest my_first_test.py --browser=chrome
1620
```
1721

18-
The ``seleniumbase mkdir [NAME]`` command creates a new folder with sample tests. To use a different browser other than Chrome, use ``seleniumbase install [DRIVER]`` with ``edgedriver`` (Microsoft Edge) or ``geckodriver`` (Firefox). Then you can use ``--browser=edge`` or ``--browser=firefox`` to run tests on those browsers. ``--browser=chrome`` is the default option.
22+
SeleniumBase has a very flexible [command line interface](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md) to change how your tests run. The following will run the same test from above using Nosetests and Firefox with geckodriver (although Pytest is recommended over Nosetests):
23+
24+
```bash
25+
seleniumbase install geckodriver
26+
nosetests my_first_test.py --browser=firefox
27+
```
28+
29+
Try out Demo Mode to see what what's being tested in real time! (Chrome is the default browser if not specified.)
1930

20-
**Slow-motion demo of [my_first_test.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) running:**<br>
21-
![](https://cdn2.hubspot.net/hubfs/100006/images/sb_demo.gif "SeleniumBase")<br>
31+
```bash
32+
pytest my_first_test.py --demo_mode
33+
```
34+
35+
![](https://cdn2.hubspot.net/hubfs/100006/images/sb_demo.gif "SeleniumBase")<br />
36+
(Above: Actual demo of [my_first_test.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) running against [xkcd.com](http://xkcd.com/353/))
2237

2338
There are many more examples to try out from the [SeleniumBase/examples](https://github.com/seleniumbase/SeleniumBase/blob/master/examples) directory, which you can run easily if you clone SeleniumBase.
2439

40+
Try out SeleniumBase Website Tours (from the ``examples/tour_examples`` folder). It's the best website onboarding experience available (and it's free too). Find the [WebSite Tours ReadMe here](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/ReadMe.md).
41+
42+
```bash
43+
cd tour_examples
44+
pytest google_tour.py
45+
```
46+
47+
![](https://cdn2.hubspot.net/hubfs/100006/images/google_tour.gif "SeleniumBase Tours")<br />
48+
(Above: Actual demo of [google_tour.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/google_tour.py) running against [google.com](https://google.com))
49+
2550
For more detailed steps on getting started, see the [**Detailed Instructions**](#seleniumbase_installation) section.
2651

2752
### Learn More:
@@ -205,13 +230,45 @@ pytest my_test_suite.py --browser=firefox
205230

206231
If you want to run tests headlessly, use ``--headless``, which you'll need to do if your system lacks a GUI interface. Even if your system does have a GUI interface, it may still support headless browser automation.
207232

233+
To run Pytest multithreaded on multiple CPUs at the same time, add ``-n=NUM`` or ``-n NUM`` on the command line, where NUM is the number of CPUs you want to use.
234+
235+
If you want to pass additional data from the command line to your tests, you can use ``--data=STRING``. Now inside your tests, you can use ``self.data`` to access that.
236+
237+
<img src="https://cdn2.hubspot.net/hubfs/100006/images/logo_base_4b.png" title="SeleniumBase" height="120">
238+
239+
### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") **Using SeleniumBase as your personal framework:**
240+
241+
You can install SeleniumBase without cloning the repo by doing this:
242+
243+
```bash
244+
python -m pip install -U pip
245+
pip install -U seleniumbase --no-cache-dir
246+
```
247+
248+
Now you can install webdrivers by doing this:
249+
250+
```bash
251+
seleniumbase install chromedriver
252+
seleniumbase install geckodriver
253+
```
254+
255+
Remember, you'll need chromedriver if you want to run automation on Chrome, geckodriver if you want to run automation on Firefox, edgedriver for Microsoft Edge, etc.
256+
257+
When creating your own test directories, keep these two things in mind:
258+
208259
For running tests outside of the SeleniumBase repo with **Pytest**, you'll want a copy of **[pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini)** on the root folder. (Subfolders should include a blank ``__init__.py`` file.)
209260

210261
For running tests outside of the SeleniumBase repo with **Nosetests**, you'll want a copy of **[setup.cfg](https://github.com/seleniumbase/SeleniumBase/blob/master/setup.cfg)** on the root folder. (Subfolders should include a blank ``__init__.py`` file.)
211262

212-
If you want to pass additional data from the command line to your tests, you can use ``--data=STRING``. Now inside your tests, you can use ``self.data`` to access that.
263+
(You'll be able to customize those files as needed.)
213264

214-
To run Pytest multithreaded on multiple CPUs at the same time, add ``-n=NUM`` or ``-n NUM`` on the command line, where NUM is the number of CPUs you want to use.
265+
As a shortcut, you'll be able to run ``seleniumbase mkdir [DIRECTORY_NAME]`` to create a new folder that already contains necessary files and some example tests that you can run. Example:
266+
267+
```bash
268+
seleniumbase mkdir browser_tests
269+
cd browser_tests
270+
pytest my_first_test.py --browser=chrome
271+
```
215272

216273
<img src="https://cdn2.hubspot.net/hubfs/100006/images/logo_base_4b.png" title="SeleniumBase" height="120">
217274

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
theme: jekyll-theme-cayman
22
title: SeleniumBase
3-
description: Automated Web-UI Testing Framework
3+
description: Web Automation & Testing Framework

console_scripts/ReadMe.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ For running tests from the command line, [use **pytest** with SeleniumBase](http
88

99
* Usage:
1010
``seleniumbase install [DRIVER_NAME]``
11-
(Drivers: chromedriver, geckodriver, edgedriver)
11+
(Drivers: chromedriver, geckodriver, edgedriver,
12+
iedriver, operadriver)
1213

1314
* Example:
1415
``seleniumbase install chromedriver``
@@ -18,6 +19,8 @@ Installs the specified webdriver.
1819
(chromedriver is required for Google Chrome automation)
1920
(geckodriver is required for Mozilla Firefox automation)
2021
(edgedriver is required for Microsoft Edge automation)
22+
(iedriver is required for Internet Explorer automation)
23+
(operadriver is required for Opera Browser automation)
2124

2225
### mkdir
2326

console_scripts/sb_install.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Installs the specified web driver.
33
44
Usage:
5-
seleniumbase install {chromedriver|geckodriver|edgedriver}
5+
seleniumbase install {chromedriver|geckodriver|edgedriver|
6+
iedriver|operadriver}
67
Output:
78
Installs the specified webdriver.
89
(chromedriver is required for Chrome automation)

help_docs/method_summary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ self.add_js_link(js_link)
8989

9090
self.add_css_style(css_style)
9191

92+
self.add_js_code_from_link(js_link)
93+
94+
self.add_meta_tag(http_equiv=None, content=None):
95+
9296
self.activate_jquery()
9397

9498
self.create_tour(name=None, theme=None)

help_docs/webdriver_installation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ To run web automation, you'll need to download a web driver for each browser you
77
seleniumbase install chromedriver
88
seleniumbase install geckodriver
99
seleniumbase install edgedriver
10+
seleniumbase install iedriver
11+
seleniumbase install operadriver
1012
```
1113

1214
If you plan on using the [Selenium Grid integration](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/selenium_grid/ReadMe.md) (which allows for remote webdriver), you'll need to put the drivers on your System PATH. On a Mac and Linux, ``/usr/local/bin`` is a good PATH spot. On Windows, you may need to set the System PATH under Environment Variables to include the location where you placed the driver files. As a shortcut, you could place the driver files into your Python ``Scripts/`` folder in the location where you have Python installed, which should already be on your System PATH.

integrations/selenium_ide/convert_ide.py

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ def main():
148148
'''\.click\(\)\s*$''', line)
149149
if data:
150150
whitespace = data.group(1)
151-
css_selector = '#%s' % data.group(2)
152-
css_selector = css_selector.replace('[', '\\[').replace(']', '\\]')
153-
command = '''%sself.click('%s')''' % (whitespace, css_selector)
151+
selector = '#%s' % data.group(2)
152+
selector = selector.replace('[', '\\[').replace(']', '\\]')
153+
command = '''%sself.click('%s')''' % (whitespace, selector)
154154
seleniumbase_lines.append(command)
155155
continue
156156

@@ -160,11 +160,11 @@ def main():
160160
'''\.send_keys\(\"([\S\s]+)\"\)\s*$''', line)
161161
if data:
162162
whitespace = data.group(1)
163-
css_selector = '#%s' % data.group(2)
164-
css_selector = css_selector.replace('[', '\\[').replace(']', '\\]')
163+
selector = '#%s' % data.group(2)
164+
selector = selector.replace('[', '\\[').replace(']', '\\]')
165165
text = data.group(3)
166166
command = '''%sself.update_text('%s', '%s')''' % (
167-
whitespace, css_selector, text)
167+
whitespace, selector, text)
168168
seleniumbase_lines.append(command)
169169
continue
170170

@@ -175,11 +175,11 @@ def main():
175175
if data:
176176
uses_keys = True
177177
whitespace = data.group(1)
178-
css_selector = '#%s' % data.group(2)
179-
css_selector = css_selector.replace('[', '\\[').replace(']', '\\]')
178+
selector = '#%s' % data.group(2)
179+
selector = selector.replace('[', '\\[').replace(']', '\\]')
180180
key = 'Keys.%s' % data.group(3)
181181
command = '''%sself.send_keys('%s', %s)''' % (
182-
whitespace, css_selector, key)
182+
whitespace, selector, key)
183183
seleniumbase_lines.append(command)
184184
continue
185185

@@ -189,8 +189,8 @@ def main():
189189
'''\.click\(\)\s*$''', line)
190190
if data:
191191
whitespace = data.group(1)
192-
css_selector = '[name="%s"]' % data.group(2)
193-
command = '''%sself.click('%s')''' % (whitespace, css_selector)
192+
selector = '[name="%s"]' % data.group(2)
193+
command = '''%sself.click('%s')''' % (whitespace, selector)
194194
seleniumbase_lines.append(command)
195195
continue
196196

@@ -200,10 +200,10 @@ def main():
200200
'''\.send_keys\(\"([\S\s]+)\"\)\s*$''', line)
201201
if data:
202202
whitespace = data.group(1)
203-
css_selector = '[name="%s"]' % data.group(2)
203+
selector = '[name="%s"]' % data.group(2)
204204
text = data.group(3)
205205
command = '''%sself.update_text('%s', '%s')''' % (
206-
whitespace, css_selector, text)
206+
whitespace, selector, text)
207207
seleniumbase_lines.append(command)
208208
continue
209209

@@ -214,10 +214,10 @@ def main():
214214
if data:
215215
uses_keys = True
216216
whitespace = data.group(1)
217-
css_selector = '[name="%s"]' % data.group(2)
217+
selector = '[name="%s"]' % data.group(2)
218218
key = 'Keys.%s' % data.group(3)
219219
command = '''%sself.send_keys('%s', %s)''' % (
220-
whitespace, css_selector, key)
220+
whitespace, selector, key)
221221
seleniumbase_lines.append(command)
222222
continue
223223

@@ -227,8 +227,8 @@ def main():
227227
'''\.click\(\)\s*$''', line)
228228
if data:
229229
whitespace = data.group(1)
230-
css_selector = '%s' % data.group(2)
231-
command = '''%sself.click('%s')''' % (whitespace, css_selector)
230+
selector = '%s' % data.group(2)
231+
command = '''%sself.click('%s')''' % (whitespace, selector)
232232
if command.count('\\"') == command.count('"'):
233233
command = command.replace('\\"', '"')
234234
seleniumbase_lines.append(command)
@@ -240,10 +240,10 @@ def main():
240240
'''\.send_keys\(\"([\S\s]+)\"\)\s*$''', line)
241241
if data:
242242
whitespace = data.group(1)
243-
css_selector = '%s' % data.group(2)
243+
selector = '%s' % data.group(2)
244244
text = data.group(3)
245245
command = '''%sself.update_text('%s', '%s')''' % (
246-
whitespace, css_selector, text)
246+
whitespace, selector, text)
247247
if command.count('\\"') == command.count('"'):
248248
command = command.replace('\\"', '"')
249249
seleniumbase_lines.append(command)
@@ -256,10 +256,10 @@ def main():
256256
if data:
257257
uses_keys = True
258258
whitespace = data.group(1)
259-
css_selector = '%s' % data.group(2)
259+
selector = '%s' % data.group(2)
260260
key = 'Keys.%s' % data.group(3)
261261
command = '''%sself.send_keys('%s', %s)''' % (
262-
whitespace, css_selector, key)
262+
whitespace, selector, key)
263263
if command.count('\\"') == command.count('"'):
264264
command = command.replace('\\"', '"')
265265
seleniumbase_lines.append(command)
@@ -271,10 +271,10 @@ def main():
271271
'''\.send_keys\(\"([\S\s]+)\"\)\s*$''', line)
272272
if data:
273273
whitespace = data.group(1)
274-
css_selector = '%s' % data.group(2)
274+
selector = '%s' % data.group(2)
275275
text = data.group(3)
276276
command = '''%sself.update_text("%s", '%s')''' % (
277-
whitespace, css_selector, text)
277+
whitespace, selector, text)
278278
if command.count('\\"') == command.count('"'):
279279
command = command.replace('\\"', '"')
280280
seleniumbase_lines.append(command)
@@ -287,10 +287,10 @@ def main():
287287
if data:
288288
uses_keys = True
289289
whitespace = data.group(1)
290-
css_selector = '%s' % data.group(2)
290+
selector = '%s' % data.group(2)
291291
key = 'Keys.%s' % data.group(3)
292-
command = '''%sself.send_keys('%s', %s)''' % (
293-
whitespace, css_selector, key)
292+
command = '''%sself.send_keys("%s", %s)''' % (
293+
whitespace, selector, key)
294294
if command.count('\\"') == command.count('"'):
295295
command = command.replace('\\"', '"')
296296
seleniumbase_lines.append(command)
@@ -303,10 +303,42 @@ def main():
303303
'''\"([\S\s]+)\"\)\s*$''', line)
304304
if data:
305305
whitespace = data.group(1)
306-
css_selector = '%s' % data.group(2)
306+
selector = '%s' % data.group(2)
307+
visible_text = '%s' % data.group(3)
308+
command = '''%sself.pick_select_option_by_text('%s', '%s')''' % (
309+
whitespace, selector, visible_text)
310+
if command.count('\\"') == command.count('"'):
311+
command = command.replace('\\"', '"')
312+
seleniumbase_lines.append(command)
313+
continue
314+
315+
# Handle Select / by_xpath() / select_by_visible_text()
316+
data = re.match(
317+
'''^(\s*)Select\(driver\.find_element_by_xpath\('''
318+
'''\"([\S\s]+)\"\)\)\.select_by_visible_text\('''
319+
'''\"([\S\s]+)\"\)\s*$''', line)
320+
if data:
321+
whitespace = data.group(1)
322+
selector = '%s' % data.group(2)
323+
visible_text = '%s' % data.group(3)
324+
command = '''%sself.pick_select_option_by_text("%s", '%s')''' % (
325+
whitespace, selector, visible_text)
326+
if command.count('\\"') == command.count('"'):
327+
command = command.replace('\\"', '"')
328+
seleniumbase_lines.append(command)
329+
continue
330+
331+
# Handle Select / by_name() / select_by_visible_text()
332+
data = re.match(
333+
'''^(\s*)Select\(driver\.find_element_by_name\('''
334+
'''\"([\S\s]+)\"\)\)\.select_by_visible_text\('''
335+
'''\"([\S\s]+)\"\)\s*$''', line)
336+
if data:
337+
whitespace = data.group(1)
338+
selector = '[name="%s"]' % data.group(2)
307339
visible_text = '%s' % data.group(3)
308340
command = '''%sself.pick_select_option_by_text('%s', '%s')''' % (
309-
whitespace, css_selector, visible_text)
341+
whitespace, selector, visible_text)
310342
if command.count('\\"') == command.count('"'):
311343
command = command.replace('\\"', '"')
312344
seleniumbase_lines.append(command)
@@ -423,14 +455,14 @@ def main():
423455
if data:
424456
whitespace = data.group(1)
425457
pre = data.group(2)
426-
css_selector = '''%s''' % data.group(3)
458+
selector = '''%s''' % data.group(3)
427459
post = data.group(4)
428460
uni = ""
429461
if '(u"' in line:
430462
uni = "u"
431463
has_unicode = True
432464
command = '''%s%sself.is_element_present("%s")%s''' % (
433-
whitespace, pre, css_selector, post)
465+
whitespace, pre, selector, post)
434466
seleniumbase_lines.append(command)
435467
continue
436468

0 commit comments

Comments
 (0)