-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Pytest-bdd integration with selenium base #1200
-
Hello Team,
I need your help in knowing how to integrate pytest-bdd level with selenium base.
My feature file is
`@speedtest
Feature: Test Internet Speed
As a user I want to test the internet speed
Background:
Given Bell Speed test page shows up
Scenario: Speed Test
When User clicks on check speed button
Then Speed details are saved
`
Step Defs is
`from seleniumbase import BaseCase
import time
import pytest
from pytest_bdd import scenarios, given, when, then, parsers
scenarios('../features/speedtest.feature')
class SpeedTest(BaseCase):
@given('Bell Speed test page shows up')
def open_bell_speed_test(self):
self.open("https://support.bell.ca/internet/internet-speed-test")
@when('User clicks on check speed button')
def start_speed_test(self):
self.click('button[id="skst-enh-init-test-btn"]')
@then('Speed details are saved')
def test_bell_internet(self):
time.sleep(120)
self.save_screenshot("speedtest.png", folder="./downloaded_files")
self.assert_downloaded_file("speedtest.png")
`
When I run pytest it opens the browser but does nothing . If I run the code without pytest-bdd using following it works
class SpeedTest(BaseCase): def open_bell_speed_test(self): self.open("https://support.bell.ca/internet/internet-speed-test") self.click('button[id="skst-enh-init-test-btn"]') self.save_screenshot("speedtest.png", folder="./downloaded_files") self.assert_downloaded_file("speedtest.png")
Folder structure
CleanShot 2022年02月04日 at 18 57 04@2x
Beta Was this translation helpful? Give feedback.
All reactions
Hi @taruntechno, when using https://github.com/pytest-dev/pytest-bdd with SeleniumBase, you may need to use the SeleniumBase sb
fixture format for compatibility. (Numbers 3 and 4 of syntax_formats)
Here's what the sb
fixture format looks like, shown below: (pytest-bdd can be added onto that separately)
# "sb" pytest fixture test in a method with no class def test_sb_fixture_with_no_class(sb): sb.open("https://google.com/ncr") sb.type('input[title="Search"]', "SeleniumBase GitHub\n") sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]') sb.click('a[title="seleniumbase"]') # "sb" pytest fixture test in a method inside a class class Test_SB_Fixture: def test_sb_fix...
Replies: 2 comments 9 replies
-
Hi @taruntechno, when using https://github.com/pytest-dev/pytest-bdd with SeleniumBase, you may need to use the SeleniumBase sb
fixture format for compatibility. (Numbers 3 and 4 of syntax_formats)
Here's what the sb
fixture format looks like, shown below: (pytest-bdd can be added onto that separately)
# "sb" pytest fixture test in a method with no class def test_sb_fixture_with_no_class(sb): sb.open("https://google.com/ncr") sb.type('input[title="Search"]', "SeleniumBase GitHub\n") sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]') sb.click('a[title="seleniumbase"]') # "sb" pytest fixture test in a method inside a class class Test_SB_Fixture: def test_sb_fixture_inside_class(self, sb): sb.open("https://google.com/ncr") sb.type('input[title="Search"]', "SeleniumBase GitHub\n") sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]') sb.click('a[title="examples"]')
Beta Was this translation helpful? Give feedback.
All reactions
-
Even after matching the version both are on 98 same behaviour. I am on macos btw. @mdmintz
Beta Was this translation helpful? Give feedback.
All reactions
-
@taruntechno Did you make any local changes to seleniumbase/core/browser_launcher.py? If there's an issue, you'd be able to track it down there via breakpoints. Likely a Chrome option wasn't valid, so it reverted to no special options (and then you would see a message such as "this browser is being controlled by automated test software", etc. Did that message appear when your test finally ran on Chrome in the second browser?
Beta Was this translation helpful? Give feedback.
All reactions
-
@mdmintz No local changes were made to this . I am not seeing this message "this browser is being controlled by automated test software" I am attaching the screenrecording of this
chromebrowserissue.mov
.
Beta Was this translation helpful? Give feedback.
All reactions
-
@taruntechno It appears you ran a very short test that first time.
Run with pytest -v
to see if you can see the name.
Beta Was this translation helpful? Give feedback.
All reactions
-
@mdmintz it seems to be running two tests and i dont think its respecting bdd
As first test method it ran is part of "then" statement which should run in the end.
collected 2 items
tests/step_defs/test_speed.py::test_bell_internet PASSED [ 50%]
tests/step_defs/test_speed.py::test_speed_test PASSED [100%]
Beta Was this translation helpful? Give feedback.
All reactions
-
@mdmintz it seems to be running two tests and i dont think its respecting bdd
As first test method it ran is part of "then" statement which should run in the end.
collected 2 items
tests/step_defs/test_speed.py::test_bell_internet PASSED [ 50%]
tests/step_defs/test_speed.py::test_speed_test PASSED [100%]
Beta Was this translation helpful? Give feedback.
All reactions
-
@mdmintz Was able to fix it finally as i had my step_Defs methods have test in there name which was confusing pytest. After removing test from the name it was able to run properly. Thanks a lot for all your help really appreciated.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Awesome!
Beta Was this translation helpful? Give feedback.