Skip to content

Commit acb6e81

Browse files
authored
Merge pull request #1323 from seleniumbase/mostly-gherkin-updates
Updates for the Behave-Gherkin integration
2 parents 8c09b76 + 6015a61 commit acb6e81

31 files changed

+1262
-477
lines changed

README.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<meta property="og:site_name" content="SeleniumBase">
22
<meta property="og:title" content="SeleniumBase: Python Web Automation and E2E Testing" />
33
<meta property="og:description" content="Fast, easy, and reliable Web/UI testing with Python." />
4-
<meta property="og:keywords" content="Python, pytest, selenium, webdriver, testing, automation, seleniumbase, framework, RPA, behave, nosetests, dashboard, recorder, reports, gui">
4+
<meta property="og:keywords" content="Python, pytest, selenium, webdriver, testing, automation, seleniumbase, framework, RPA, behave, BDD, nosetests, dashboard, recorder, reports, gui, screenshots">
55
<meta property="og:image" content="https://seleniumbase.io/cdn/img/mac_sb_logo_5.png" />
66
<link rel="icon" href="https://seleniumbase.io/img/green_logo.png" />
77

8-
<h3 align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/mac_sb_logo_9.png" alt="SeleniumBase" title="SeleniumBase" width="340" /></a></h3>
8+
<h3 align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/nice_logo_4t.png" alt="SeleniumBase" title="SeleniumBase" width="260" /></a></h3>
99
<!-- View on GitHub -->
1010

11-
<p align="center"><div align="center">Python framework for <a href="https://www.selenium.dev/documentation/" target="_blank">Selenium</a>. Supports <a href="https://docs.pytest.org/en/stable/" target="_blank">pytest</a> and <a href="https://behave.readthedocs.io/en/stable/index.html" target="_blank">behave-BDD</a>.</div></p>
11+
<p align="center"><div align="center">A Python ecosystem for <a href="https://www.selenium.dev/documentation/" target="_blank">Selenium</a> that extends <a href="https://docs.pytest.org/en/stable/" target="_blank">Pytest</a> and <a href="https://behave.readthedocs.io/en/stable/index.html" target="_blank">Behave</a>.</div></p>
1212

1313
<p align="center">
1414
<a href="https://github.com/seleniumbase/SeleniumBase/releases">
@@ -47,7 +47,7 @@
4747

4848
--------
4949

50-
<p align="left">↘️ Example test with the <b>BaseCase</b> class. Runs with <code>pytest</code> or <code>nosetests</code>. (<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">Learn more</a>)</p>
50+
<p align="left">🌱 An example with <b>BaseCase</b>, a subclass of <code>unittest.TestCase</code>. Runs with <code>pytest</code> or <code>nosetests</code>. (<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">Learn more</a>)</p>
5151

5252
```python
5353
from seleniumbase import BaseCase
@@ -64,7 +64,7 @@ class TestMFALogin(BaseCase):
6464
self.save_screenshot_to_logs()
6565
```
6666

67-
<p align="left">↘️ Example test with the <b>sb</b> pytest fixture. Runs with <code>pytest</code>.</p>
67+
<p align="left">🌱 An example with <b>sb</b>, a <code>pytest</code> fixture. Runs with <code>pytest</code>.</p>
6868

6969
```python
7070
def test_mfa_login(sb):
@@ -78,20 +78,20 @@ def test_mfa_login(sb):
7878
sb.save_screenshot_to_logs()
7979
```
8080

81-
<p align="left">↘️ Example test with <b>behave-BDD</b> <a href="https://behave.readthedocs.io/en/stable/gherkin.html">Gherkin</a> structure. Runs with <code>behave</code>. (<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">Learn more</a>)</p>
81+
<p align="left">🌱 An example with <b>behave-BDD</b> <a href="https://behave.readthedocs.io/en/stable/gherkin.html">Gherkin</a> structure. Runs with <code>behave</code>. (<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">Learn more</a>)</p>
8282

8383
```gherkin
8484
Feature: SeleniumBase scenarios for the RealWorld App
8585
86-
Scenario: Verify RealWorld App (log in / sign out)
87-
Given Open "seleniumbase.io/realworld/login"
88-
When Type "demo_user" into "#username"
89-
And Type "secret_pass" into "#password"
90-
And Do MFA "GAXG2MTEOR3DMMDG" into "#totpcode"
91-
Then Assert exact text "Welcome!" in "h1"
92-
And Highlight "img#image1"
93-
And Click 'a:contains("This Page")'
94-
And Save screenshot to logs
86+
Scenario: Verify RealWorld App (log in / sign out)
87+
Given Open "seleniumbase.io/realworld/login"
88+
When Type "demo_user" into "#username"
89+
And Type "secret_pass" into "#password"
90+
And Do MFA "GAXG2MTEOR3DMMDG" into "#totpcode"
91+
Then Assert exact text "Welcome!" in "h1"
92+
And Highlight "img#image1"
93+
And Click 'a:contains("This Page")'
94+
And Save screenshot to logs
9595
```
9696

9797
<p align="left">✅ An example of running a test: <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_demo_site.py">test_demo_site.py</a></p>
@@ -431,6 +431,8 @@ The code above will leave your browser window open in case there's a failure. (i
431431
--block-images # (Block images from loading during tests.)
432432
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
433433
--recorder # (Enables the Recorder for turning browser actions into code.)
434+
--rec-behave # (Same as Recorder Mode, but also generates behave-gherkin.)
435+
--rec-sleep # (If the Recorder is enabled, also records self.sleep calls.)
434436
--disable-csp # (Disable the Content Security Policy of websites.)
435437
--disable-ws # (Disable Web Security on Chromium-based browsers.)
436438
--enable-ws # (Enable Web Security on Chromium-based browsers.)
@@ -1022,11 +1024,13 @@ pytest --reruns=1 --reruns-delay=1
10221024
<img src="https://img.shields.io/badge/docs-%20%20SeleniumBase.io-11BBDD.svg" alt="SeleniumBase.io Docs" /></a></div> <div><a href="https://pepy.tech/project/seleniumbase" target="_blank"><img src="https://pepy.tech/badge/seleniumbase" alt="SeleniumBase PyPI downloads" /></a></div>
10231025
10241026
<p><div>
1025-
<span><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://seleniumbase.io/img/social/share_github.svg" title="SeleniumBase on GitHub" alt="SeleniumBase on GitHub" width="38" /></a></span>
1026-
<span><a href="https://www.facebook.com/SeleniumBase" target="_blank"><img src="https://seleniumbase.io/img/social/share_facebook.svg" title="SeleniumBase on Facebook" alt="SeleniumBase on Facebook" width="36" /></a></span>
1027-
<span><a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://seleniumbase.io/img/social/share_gitter.svg" title="SeleniumBase on Gitter" alt="SeleniumBase on Gitter" width="30" /></a></span>
1028-
<span><a href="https://instagram.com/seleniumbase" target="_blank"><img src="https://seleniumbase.io/img/social/share_instagram.svg" title="SeleniumBase on Instagram" alt="SeleniumBase on Instagram" width="32" /></a></span>
1029-
<span><a href="https://twitter.com/seleniumbase" target="_blank"><img src="https://seleniumbase.io/img/social/share_twitter.svg" title="SeleniumBase on Twitter" alt="SeleniumBase on Twitter" width="39" /></a></span>
1027+
<span><a href="https://github.com/seleniumbase/SeleniumBase"><img src="https://seleniumbase.io/img/social/share_github.svg" title="SeleniumBase on GitHub" alt="SeleniumBase on GitHub" width="40" /></a></span>
1028+
<span><a href="https://www.facebook.com/SeleniumBase" target="_blank"><img src="https://seleniumbase.io/img/social/share_facebook.svg" title="SeleniumBase on Facebook" alt="SeleniumBase on Facebook" width="37" /></a></span>
1029+
<span><a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://seleniumbase.io/img/social/share_gitter.svg" title="SeleniumBase on Gitter" alt="SeleniumBase on Gitter" width="32" /></a></span>
1030+
<span><a href="https://instagram.com/seleniumbase" target="_blank"><img src="https://seleniumbase.io/img/social/share_instagram.svg" title="SeleniumBase on Instagram" alt="SeleniumBase on Instagram" width="33" /></a></span>
1031+
<span><a href="https://twitter.com/seleniumbase" target="_blank"><img src="https://seleniumbase.io/img/social/share_twitter.svg" title="SeleniumBase on Twitter" alt="SeleniumBase on Twitter" width="40" /></a></span>
10301032
</div></p>
10311033
10321034
<a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/super_logo_sb.png" alt="SeleniumBase" title="SeleniumBase" width="200" /></a>
1035+
1036+
<p><b>Build all the automation you want, with SeleniumBase.</b></p>

examples/behave_bdd/ReadMe.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Took 0m1.672s
7676

7777
<img src="https://seleniumbase.io/cdn/img/sb_behave_dashboard.png" title="SeleniumBase" width="600">
7878

79-
### 🐝 Understanding Behave files:
79+
### 🐝 Behave-Gherkin files:
8080

8181
🐝 The ``*.feature`` files can use any step seen from:
8282

@@ -147,48 +147,48 @@ def add_item_to_cart(context, item):
147147
```gherkin
148148
Feature: SeleniumBase scenarios for the Swag Labs App
149149
150-
Background:
151-
Given Open the Swag Labs Login Page
152-
153-
Scenario: User can order a backpack from the store
154-
When Login to Swag Labs with standard_user
155-
Then Verify that the current user is logged in
156-
And Save price of "Backpack" to <item_price>
157-
When Add "Backpack" to Cart
158-
Then Verify shopping cart badge shows 1 item(s)
159-
When Click on shopping cart icon
160-
And Click Checkout
161-
And Enter checkout info: First, Last, 12345
162-
And Click Continue
163-
Then Verify 1 "Backpack"(s) in cart
164-
And Verify cost of "Backpack" is <item_price>
165-
And Verify item total is $29.99
166-
And Verify tax amount is $2.40
167-
And Verify total cost is $32.39
168-
When Click Finish
169-
Then Verify order complete
170-
When Logout from Swag Labs
171-
Then Verify on Login page
150+
Background:
151+
Given Open the Swag Labs Login Page
152+
153+
Scenario: User can order a backpack from the store
154+
When Login to Swag Labs with standard_user
155+
Then Verify that the current user is logged in
156+
And Save price of "Backpack" to <item_price>
157+
When Add "Backpack" to Cart
158+
Then Verify shopping cart badge shows 1 item(s)
159+
When Click on shopping cart icon
160+
And Click Checkout
161+
And Enter checkout info: First, Last, 12345
162+
And Click Continue
163+
Then Verify 1 "Backpack"(s) in cart
164+
And Verify cost of "Backpack" is <item_price>
165+
And Verify item total is $29.99
166+
And Verify tax amount is $2.40
167+
And Verify total cost is $32.39
168+
When Click Finish
169+
Then Verify order complete
170+
When Logout from Swag Labs
171+
Then Verify on Login page
172172
```
173173

174174
🐝 Here's another example of a ``*.feature`` file:
175175

176176
```gherkin
177177
Feature: SeleniumBase scenarios for the RealWorld App
178178
179-
Scenario: Verify RealWorld App (log in / sign out)
180-
Given Open "seleniumbase.io/realworld/login"
181-
And Clear Session Storage
182-
When Type "demo_user" into "#username"
183-
And Type "secret_pass" into "#password"
184-
And Do MFA "GAXG2MTEOR3DMMDG" into "#totpcode"
185-
Then Assert text "Welcome!" in "h1"
186-
And Highlight element "img#image1"
187-
And Click 'a:contains("This Page")'
188-
And Save screenshot to logs
189-
When Click link "Sign out"
190-
Then Assert element 'a:contains("Sign in")'
191-
And Assert text "You have been signed out!"
179+
Scenario: Verify RealWorld App (log in / sign out)
180+
Given Open "seleniumbase.io/realworld/login"
181+
And Clear Session Storage
182+
When Type "demo_user" into "#username"
183+
And Type "secret_pass" into "#password"
184+
And Do MFA "GAXG2MTEOR3DMMDG" into "#totpcode"
185+
Then Assert text "Welcome!" in "h1"
186+
And Highlight element "img#image1"
187+
And Click 'a:contains("This Page")'
188+
And Save screenshot to logs
189+
When Click link "Sign out"
190+
Then Assert element 'a:contains("Sign in")'
191+
And Assert text "You have been signed out!"
192192
```
193193

194194
🐝 If there's a test failure, that's easy to spot:
Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
11
Feature: SeleniumBase scenarios for the Calculator App
22

3-
Background:
4-
Given Open the Calculator App
3+
Background:
4+
Given Open the Calculator App
55

6-
Scenario: Pressing "C" outputs "0"
7-
When Press C
8-
Then Verify output is "0"
6+
Scenario: Pressing "C" outputs "0"
7+
When Press C
8+
Then Verify output is "0"
99

10-
Scenario: 1 + 2 + 3 + 4 + 5 = 15
11-
When Press C
12-
And Press 1
13-
And Press +
14-
And Press 2
15-
And Press +
16-
And Press 3
17-
And Press +
18-
And Press 4
19-
And Press +
20-
And Press 5
21-
Then Verify output is "1+2+3+4+5"
22-
When Press =
23-
Then Verify output is "15"
10+
Scenario: 1 + 2 + 3 + 4 + 5 = 15
11+
When Press C
12+
And Press 1
13+
And Press +
14+
And Press 2
15+
And Press +
16+
And Press 3
17+
And Press +
18+
And Press 4
19+
And Press +
20+
And Press 5
21+
Then Verify output is "1+2+3+4+5"
22+
When Press =
23+
Then Verify output is "15"
2424

25-
Scenario: 6 × 7 × 8 × 9 = 3024
26-
When Press C
27-
And Press 6
28-
And Press ×
29-
And Press 7
30-
And Press ×
31-
And Press 8
32-
And Press ×
33-
And Press 9
34-
Then Verify output is "6×7×8×9"
35-
When Press =
36-
Then Verify output is "3024"
25+
Scenario: 6 × 7 × 8 × 9 = 3024
26+
When Press C
27+
And Press 6
28+
And Press ×
29+
And Press 7
30+
And Press ×
31+
And Press 8
32+
And Press ×
33+
And Press 9
34+
Then Verify output is "6×7×8×9"
35+
When Press =
36+
Then Verify output is "3024"
3737

38-
Scenario: 44 - 11 = 33
39-
When Press C
40-
And Press 4
41-
And Press 4
42-
And Press -
43-
And Press 1
44-
And Press 1
45-
Then Verify output is "44-11"
46-
When Press =
47-
Then Verify output is "33"
38+
Scenario: 44 - 11 = 33
39+
When Press C
40+
And Press 4
41+
And Press 4
42+
And Press -
43+
And Press 1
44+
And Press 1
45+
Then Verify output is "44-11"
46+
When Press =
47+
Then Verify output is "33"
4848

49-
Scenario: 7.0 × (3 + 3) = 42
50-
When Press C
51-
And Press 7
52-
And Press .
53-
And Press 0
54-
And Press ×
55-
And Press (
56-
And Press 3
57-
And Press +
58-
And Press 3
59-
And Press )
60-
Then Verify output is "7.0×(3+3)"
61-
When Press =
62-
Then Verify output is "42"
49+
Scenario: 7.0 × (3 + 3) = 42
50+
When Press C
51+
And Press 7
52+
And Press .
53+
And Press 0
54+
And Press ×
55+
And Press (
56+
And Press 3
57+
And Press +
58+
And Press 3
59+
And Press )
60+
Then Verify output is "7.0×(3+3)"
61+
When Press =
62+
Then Verify output is "42"
6363

64-
Scenario: 4.5 × 68 = 306
65-
When Press C
66-
And Evaluate [4.5 × 68]
67-
Then Verify output is "306"
64+
Scenario: 4.5 × 68 = 306
65+
When Press C
66+
And Evaluate [4.5 × 68]
67+
Then Verify output is "306"
6868

69-
Scenario Outline: <First> ÷ <Second> = <Result>
70-
When Press C
71-
And Press [<First>]
72-
And Press ÷
73-
And Press [<Second>]
74-
And Press =
75-
Then Verify output is "<Result>"
76-
Examples:
77-
| First | Second | Result |
78-
| 1948 | 4 | 487 |
79-
| 21 | 0 | Error |
69+
Scenario Outline: <First> ÷ <Second> = <Result>
70+
When Press C
71+
And Press [<First>]
72+
And Press ÷
73+
And Press [<Second>]
74+
And Press =
75+
Then Verify output is "<Result>"
76+
Examples:
77+
| First | Second | Result |
78+
| 1948 | 4 | 487 |
79+
| 21 | 0 | Error |
8080

81-
Scenario: Save calculator screenshot to logs
82-
Given Press [1337]
83-
Given Save calculator screenshot to logs
81+
Scenario: Save calculator screenshot to logs
82+
Given Press [1337]
83+
Given Save calculator screenshot to logs
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Feature: SeleniumBase scenarios for the Fail Page
22

3-
Scenario: Fail test on purpose to see what happens
4-
When Open the Fail Page
5-
Then Fail test on purpose
3+
Scenario: Fail test on purpose to see what happens
4+
When Open the Fail Page
5+
Then Fail test on purpose
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Feature: SeleniumBase scenarios for the RealWorld App
22

3-
Scenario: Verify RealWorld App (log in / sign out)
4-
Given Open "seleniumbase.io/realworld/login"
5-
And Clear Session Storage
6-
When Type "demo_user" into "#username"
7-
And Type "secret_pass" into "#password"
8-
And Do MFA "GAXG2MTEOR3DMMDG" into "#totpcode"
9-
Then Assert exact text "Welcome!" in "h1"
10-
And Highlight "img#image1"
11-
And Click 'a:contains("This Page")'
12-
And Save screenshot to logs
13-
When Click link "Sign out"
14-
Then Assert element 'a:contains("Sign in")'
15-
And Assert text "You have been signed out!"
3+
Scenario: Verify RealWorld App (log in / sign out)
4+
Given Open "seleniumbase.io/realworld/login"
5+
And Clear Session Storage
6+
When Type "demo_user" into "#username"
7+
And Type "secret_pass" into "#password"
8+
And Do MFA "GAXG2MTEOR3DMMDG" into "#totpcode"
9+
Then Assert exact text "Welcome!" in "h1"
10+
And Highlight "img#image1"
11+
And Click 'a:contains("This Page")'
12+
And Save screenshot to logs
13+
When Click link "Sign out"
14+
Then Assert element 'a:contains("Sign in")'
15+
And Assert text "You have been signed out!"

0 commit comments

Comments
 (0)