-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#938 #939 test order page remove goal #943
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
10d3c36
Create Positions selenium element
ArtemijRodionov bba10c1
Reuse Positions for Cart class
ArtemijRodionov 16dea9d
Create OrderPositions class
ArtemijRodionov c86d84a
Adopt classes to Positions
ArtemijRodionov a32c6df
Implement OrderPage class
ArtemijRodionov cbea8c2
Create YandexEcommerce.remove_from_order_page test. Reduce code dupli…
ArtemijRodionov c2d3f90
Apply linter rules
ArtemijRodionov 325d5a1
Fix typo
ArtemijRodionov fe5f0df
Review fixes
ArtemijRodionov b146b21
Edit todo to fix assertion for cart clear goal
ArtemijRodionov 016109a
Apply linter rules
ArtemijRodionov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be formatted in one string |
||
)) | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
elements.Product
is not clear returning type. Seems we can't set type here without generic types lang feature