-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Create Positions selenium element * Reuse Positions for Cart class * Create OrderPositions class * Adopt classes to Positions * Implement OrderPage class * Create YandexEcommerce.remove_from_order_page test. Reduce code duplication * Apply linter rules * Fix typo * Review fixes * Edit todo to fix assertion for cart clear goal * Apply linter rules
- Loading branch information
1 parent
db12eb7
commit 4ddb192
Showing
10 changed files
with
215 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,6 @@ database/ | |
.DS_store | ||
*.orig | ||
venv/ | ||
.sublime-project | ||
.sublime-workspace | ||
*.sublime-project | ||
*.sublime-workspace | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .button import Button | ||
from .exceptions import Unavailable | ||
from .button import Button | ||
from .input import Input | ||
from .product import CatalogCard, ProductCard, CartPosition | ||
from .product import * | ||
from .cart import Cart | ||
from .positions import Positions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from contextlib import contextmanager | ||
|
||
from selenium.common.exceptions import TimeoutException | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
from shopelectro.selenium import SiteDriver, elements | ||
|
||
|
||
class Positions: | ||
|
||
def __init__(self, driver: SiteDriver, position_type: elements.Product, locator): | ||
self.driver = driver | ||
self.position_type = position_type | ||
self.condition = EC.presence_of_all_elements_located(locator) | ||
|
||
@contextmanager | ||
def wait_changes(self): | ||
def are_changed(_): | ||
try: | ||
return positions_before != self.all() | ||
except TimeoutException: | ||
""" | ||
An exception can be raised from a position's equality method. | ||
In most cases this means that some positions are stale, | ||
so we continue waiting changes. | ||
""" | ||
return False | ||
|
||
positions_before = self.all() | ||
yield | ||
self.driver.wait.until(are_changed) | ||
|
||
def first(self) -> elements.Product: | ||
return self.position_type(self.driver, 0) | ||
|
||
def all(self) -> [elements.Product]: | ||
try: | ||
# use short_wait to avoid long pauses in case of the empty cart | ||
positions_count = len(self.driver.short_wait.until( | ||
self.condition | ||
)) | ||
except TimeoutException: | ||
positions_count = 0 | ||
|
||
return [self.position_type(self.driver, i) for i in range(positions_count)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,45 @@ | ||
from shopelectro.models import PaymentOptions | ||
from shopelectro.selenium.elements import Input, Button | ||
from shopelectro.selenium.pages import Page | ||
|
||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
from pages.models import CustomPage | ||
from shopelectro.models import PaymentOptions | ||
from shopelectro.selenium import elements, SiteDriver | ||
from shopelectro.selenium.pages import Page | ||
|
||
# @todo #682:120m Implement and reuse shopelectro.selenium.OrderPage for selenium tests. | ||
|
||
|
||
class OrderPage(Page): | ||
|
||
def __init__(self, driver): | ||
def __init__(self, driver: SiteDriver): | ||
super().__init__(driver) | ||
self.submit_button = Button(self.driver, (By.ID, 'submit-order')) | ||
self.submit_button = elements.Button(self.driver, (By.ID, 'submit-order')) | ||
self.positions = elements.Positions( | ||
driver, | ||
elements.OrderPosition, | ||
(By.XPATH, '//div[@id="js-order-list"]/div[2]/div'), | ||
) | ||
|
||
@property | ||
def path(self): | ||
return CustomPage.objects.get(slug='order').url | ||
|
||
def set(self, position: elements.OrderPosition, quantity: int): | ||
with self.positions.wait_changes(): | ||
position.set(quantity) | ||
|
||
def increase(self, position: elements.OrderPosition): | ||
with self.positions.wait_changes(): | ||
position.increase() | ||
|
||
def decrease(self, position: elements.OrderPosition): | ||
with self.positions.wait_changes(): | ||
position.decrease() | ||
|
||
def remove(self, position: elements.OrderPosition): | ||
with self.positions.wait_changes(): | ||
position.remove() | ||
|
||
def fill_contacts( | ||
self, name='Name', city='Санкт-Петербург', phone='2222222222', email='[email protected]', | ||
): | ||
|
@@ -31,7 +51,7 @@ def fill_contacts( | |
} | ||
|
||
for id_, value in contacts.items(): | ||
Input(self.driver, (By.ID, id_)).send_keys(value) | ||
elements.Input(self.driver, (By.ID, id_)).send_keys(value) | ||
|
||
def make_order(self): | ||
self.submit_button.click() | ||
|
@@ -44,7 +64,7 @@ def select_payment_type(self, payment_option: PaymentOptions): | |
f'It should be one of: {PaymentOptions}' | ||
) | ||
|
||
item = Button( | ||
item = elements.Button( | ||
self.driver, | ||
(By.CSS, f'input[name="payment_type"][value="{payment_option.name}"]'), | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
4ddb192
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
920-cb7dcfc8
disappeared fromshopelectro/selenium/elements/cart.py
, that's why I closed #938. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.4ddb192
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
820-7b702e9a
disappeared fromshopelectro/tests/tests_js_analytics.py
, that's why I closed #939. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.4ddb192
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
939-a904eb4b
discovered inshopelectro/tests/tests_js_analytics.py
and submitted as #944. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.