-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_site.py
More file actions
63 lines (39 loc) · 1.88 KB
/
test_site.py
File metadata and controls
63 lines (39 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from playwright.sync_api import Page, expect
from pytest_bdd import scenarios, given, when, then
scenarios('site.feature')
@given('We navigated to the site')
def visit_site(page: Page):
page.goto('https://www.saucedemo.com/')
@given('We are logged in')
def logged_in(page):
visit_site(page)
page.locator('//input[@id="user-name"]').fill('standard_user')
page.locator('//input[@id="password"]').fill('secret_sauce')
page.locator('//input[@data-test="login-button"]').click()
expect(page.locator('//a[@data-test="shopping-cart-link"]')).to_be_visible()
@when('We fill the login and pass fields with correct data')
def fill_login(page):
page.locator('//input[@id="user-name"]').fill('standard_user')
page.locator('//input[@id="password"]').fill('secret_sauce')
@when('We fill the login and pass fields with invalid data')
def fill_login_invalid(page):
page.locator('//input[@id="user-name"]').fill('locked_out_user')
page.locator('//input[@id="password"]').fill('secret_sauce')
@when('We press login button')
def press_login(page):
page.locator('//input[@data-test="login-button"]').click()
@when('We add product to the cart')
def add_product(page):
page.locator('//button[@data-test="add-to-cart-sauce-labs-backpack"]').click()
@when("We press on cart icon")
def press_cart(page):
page.locator('//a[@data-test="shopping-cart-link"]').click()
@then("Product appears in cart")
def product_in_cart(page):
expect(page.locator('//div[@data-test="inventory-item-name"]')).to_contain_text('Sauce Labs Backpack')
@then("We are successfully logged in")
def res_page_suc(page):
expect(page.locator('//a[@data-test="shopping-cart-link"]')).to_be_visible()
@then("We got an error message and not logged in")
def res_page_unsuc(page):
expect(page.locator('//h3[@data-test="error"]')).to_contain_text('Epic sadface: Sorry, this user has been locked out.')