Skip to content

Commit b7ff7fb

Browse files
committed
First test with facade and allure
1 parent eca294c commit b7ff7fb

File tree

14 files changed

+268
-2
lines changed

14 files changed

+268
-2
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# playwright_python_practice
2-
Just a Playwright (python) tool practice
1+
# praywright_python_practice
2+
Just a [Playwright Python](https://github.com/Microsoft/playwright-python) tool practice
3+
4+
## How to run
5+
1. Run tests `execute_tests.sh`
6+
7+
## Notes:
8+
I didn't enjoy this tool, cause it's very complicated. It totally looks like it just has been translated
9+
from JS Playwright and need to wright on Python usign JS style. So annoying. But this tools is pretty
10+
fast.
11+
###
12+
Anyway, I won't recommend this tool to young Python AQA engineers.
13+
14+
### [Video](https://drive.google.com/open?id=1P6SXIADubK4k5EXOnd5ZSPeo4n7GEG0p)
15+
16+
## Docker
17+
Execute tests - `docker-compose run tests`
18+
19+
Rebuild container - `docker-compose build --no-cache setup`

execute_tests.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
rm -r allure-results/*
3+
4+
source venv/bin/activate
5+
pip install -r requirements.txt --quiet
6+
7+
pytest -n auto tests --alluredir allure-results
8+
9+
allure serve

page_objects/__init__.py

Whitespace-only changes.

page_objects/base_page.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import allure
2+
from playwright.helper import TimeoutError as TE
3+
from playwright.page import Page
4+
5+
6+
class BasePage:
7+
def __init__(self, page: Page):
8+
self.page = page
9+
10+
@allure.step('Click locator - {locator}')
11+
async def click(self, locator):
12+
await self.page.click(locator)
13+
14+
@allure.step('Check checkbox locator - {locator}')
15+
async def check(self, locator):
16+
await self.page.check(locator)
17+
18+
@allure.step('Uncheck checkbox locator - {locator}')
19+
async def uncheck(self, locator):
20+
await self.page.check(locator)
21+
22+
@allure.step('Hover locator - {locator}')
23+
async def hover(self, locator):
24+
await self.page.hover(locator)
25+
26+
@allure.step('Go to url - {url}')
27+
async def go_to_url(self, url):
28+
await self.page.goto(url)
29+
30+
@allure.step('Type text - {text} into locator - {locator}')
31+
async def type(self, locator, text):
32+
await self.click(locator)
33+
await self.page.fill(locator, text)
34+
35+
@allure.step('Select option - {option} in locator - {locator}')
36+
async def select_option(self, locator, option):
37+
await self.page.selectOption(locator, option)
38+
39+
@allure.step('Is element - {locator} present')
40+
async def is_element_present(self, locator):
41+
try:
42+
await self.page.waitForSelector(locator)
43+
return True
44+
except TE:
45+
return False
46+
47+
@allure.step('Is element - {locator} hidden')
48+
async def is_element_present(self, locator):
49+
try:
50+
await self.page.waitForSelector(locator, {'state': 'hidden'})
51+
return True
52+
except TE:
53+
return False

page_objects/registation/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class RegistrationLocators:
2+
EMAIL_INPUT = '#email_create'
3+
CREATE_BTN = '#SubmitCreate'
4+
GENDER_OPTION = '[name="id_gender"]'
5+
CUSTOMER_FIRST_NAME_INPUT = '[name="customer_firstname"]'
6+
CUSTOMER_LAST_NAME_INPUT = '[name="customer_lastname"]'
7+
FIRST_NAME_INPUT = '[name="firstname"]'
8+
LAST_NAME_INPUT = '[name="lastname"]'
9+
PASSWORD_INPUT = '[name="passwd"]'
10+
DAYS_SELECTOR = '#days'
11+
MONTHS_SELECTOR = '#months'
12+
YEARS_SELECTOR = '#years'
13+
AGREE_CHECKBOX = '[name="optin"]'
14+
NEWSLETTER_CHECKBOX = '#newsletter'
15+
ADDRESS_INPUT = '[name="address1"]'
16+
CITY_INPUT = '#city'
17+
POSTCODE_INPUT = '#postcode'
18+
OTHER_INPUT = '#other'
19+
PHONE_INPUT = '#phone_mobile'
20+
STATE_SELECT = '#id_state'
21+
ALIAS_BTN = '#alias'
22+
SUBMIT_ACCOUNT_BTN = '#submitAccount'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from random import randint
2+
3+
from page_objects.base_page import BasePage
4+
from page_objects.registation.registration_locators import RegistrationLocators
5+
6+
7+
class RegistrationPage(BasePage):
8+
async def register_account(self):
9+
await self.type(RegistrationLocators.EMAIL_INPUT, f'goraved@{randint(1000, 99999)}.com')
10+
await self.click(RegistrationLocators.CREATE_BTN)
11+
await self.click(RegistrationLocators.GENDER_OPTION)
12+
await self.type(RegistrationLocators.CUSTOMER_FIRST_NAME_INPUT, "Test")
13+
await self.type(RegistrationLocators.CUSTOMER_LAST_NAME_INPUT, "Goraved")
14+
await self.type(RegistrationLocators.PASSWORD_INPUT, "123asd")
15+
await self.select_option(RegistrationLocators.DAYS_SELECTOR, "1")
16+
await self.select_option(RegistrationLocators.MONTHS_SELECTOR, "1")
17+
await self.select_option(RegistrationLocators.YEARS_SELECTOR, "2020")
18+
await self.click(RegistrationLocators.AGREE_CHECKBOX)
19+
await self.click(RegistrationLocators.NEWSLETTER_CHECKBOX)
20+
await self.type(RegistrationLocators.FIRST_NAME_INPUT, 'Test')
21+
await self.type(RegistrationLocators.LAST_NAME_INPUT, 'Goraved')
22+
await self.type(RegistrationLocators.ADDRESS_INPUT, "street")
23+
await self.type(RegistrationLocators.CITY_INPUT, "test")
24+
await self.select_option(RegistrationLocators.STATE_SELECT, "1")
25+
await self.type(RegistrationLocators.POSTCODE_INPUT, "11111")
26+
await self.type(RegistrationLocators.OTHER_INPUT, "123")
27+
await self.type(RegistrationLocators.PHONE_INPUT, "123")
28+
await self.click(RegistrationLocators.ALIAS_BTN)
29+
await self.click(RegistrationLocators.SUBMIT_ACCOUNT_BTN)

page_objects/shop/__init__.py

Whitespace-only changes.

page_objects/shop/shop_locators.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class ShopLocators:
2+
T_SHIRT_CATEGORY_BTN = 'li:nth-child(3) > a[title="T-shirts"]'
3+
ITEM_NAME_LBL = '[itemprop="name"]'
4+
ADD_TO_CART_BTN = '#add_to_cart'
5+
PROCEED_TO_CHECKOUT_BTN = '[title="Proceed to checkout"]'
6+
SECOND_CART_STEP_BTN = 'p > a.button.btn.btn-default.standard-checkout.button-medium'
7+
TERMS_CHECKBOX = '[name="cgv"]'
8+
PAY_WITH_BANK_BTN = '[title="Pay by bank wire"]'
9+
CONFIRM_ORDER_BTN = '#cart_navigation > button'
10+
PROFILE_BTN = '[title="View my customer account"]'
11+
ORDERS_BTN = '[title="Orders"]'
12+
ORDER_ROW = '#order-list > tbody > tr'

page_objects/shop/shop_object.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from page_objects.base_page import BasePage
2+
from page_objects.shop.shop_locators import ShopLocators
3+
4+
5+
class ShopPage(BasePage):
6+
async def open_site(self):
7+
await self.go_to_url('http://automationpractice.com/index.php')
8+
9+
async def open_t_shirt_category(self):
10+
await self.click(ShopLocators.T_SHIRT_CATEGORY_BTN)
11+
12+
async def add_item_to_cart_and_proceed(self):
13+
await self.hover(ShopLocators.ITEM_NAME_LBL)
14+
await self.click(ShopLocators.ITEM_NAME_LBL)
15+
await self.click(ShopLocators.ADD_TO_CART_BTN)
16+
await self.click(ShopLocators.PROCEED_TO_CHECKOUT_BTN)
17+
18+
async def go_to_the_second_cart_step(self):
19+
await self.click(ShopLocators.SECOND_CART_STEP_BTN)
20+
21+
async def finish_order_after_registration(self):
22+
await self.click('#center_column > form > p > button')
23+
await self.click(ShopLocators.TERMS_CHECKBOX)
24+
await self.click('#form > p > button')
25+
await self.click(ShopLocators.PAY_WITH_BANK_BTN)
26+
await self.click(ShopLocators.CONFIRM_ORDER_BTN)
27+
28+
async def open_profile_order_page(self):
29+
await self.click(ShopLocators.PROFILE_BTN)
30+
await self.click(ShopLocators.ORDERS_BTN)
31+
32+
async def is_order_present(self):
33+
return await self.is_element_present(ShopLocators.ORDER_ROW)

0 commit comments

Comments
 (0)