-
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
#690 #498 #497 Make the check_purchase work #695
Changes from 13 commits
7fe193f
e58655e
9b94132
a333d77
2ec22a0
351387a
cb301ee
0010a5d
6057aca
24ae611
d4c59ed
d0daa04
46d2773
de9a7ad
d44644a
4e7fce1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from selenium.common.exceptions import StaleElementReferenceException | ||
|
||
|
||
def alphanumeric(text: str) -> str: | ||
return ''.join(filter(lambda c: c.isalnum(), text)) | ||
|
||
|
||
class AlnumPresentedInValue: | ||
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. it's not good name because of not good semantic. So, i suggest this design:
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. @duker33 ,
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. @artemiy312 , imho selenium conditions have not the best arch in the world =) |
||
""" | ||
Check if the given text is present in the element's locator, text. | ||
|
||
Remove all non-alphanumeric characters before checking. | ||
""" | ||
|
||
def __init__(self, locator, text): | ||
self.locator = locator | ||
self.text = text | ||
|
||
def __call__(self, driver): | ||
try: | ||
text = driver.find_element(*self.locator).get_attribute('value') | ||
return alphanumeric(self.text) in alphanumeric(text) | ||
except StaleElementReferenceException: | ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from .input import Input | ||
from .button import Button | ||
from .product_card import ProductCard |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from shopelectro.selenium.driver import SiteDriver | ||
|
||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
|
||
class Button: | ||
|
||
def __init__(self, driver: SiteDriver, locator): | ||
self.driver = driver | ||
self.locator = locator | ||
|
||
def click(self): | ||
self.driver.wait.until(EC.element_to_be_clickable( | ||
self.locator | ||
)).click() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import re | ||
|
||
from shopelectro.selenium.conditions import AlnumPresentedInValue | ||
from shopelectro.selenium.driver import SiteDriver | ||
|
||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
|
||
class Input: | ||
|
||
def __init__(self, driver: SiteDriver, locator): | ||
self.driver = driver | ||
self.locator = locator | ||
|
||
def send_keys(self, keys: str): | ||
keys = str(keys) | ||
if not re.match(r'[\w\d\s\-_]+', keys, re.I | re.U): | ||
raise ValueError('Remove special symbols from text') | ||
el = self.driver.wait.until(EC.element_to_be_clickable(self.locator)) | ||
el.clear() | ||
el.send_keys(keys) | ||
self.driver.wait.until(AlnumPresentedInValue(self.locator, keys)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .page import Page | ||
|
||
from .category import CategoryPage | ||
from .order import OrderPage | ||
from .page import Page |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,9 @@ | ||||||
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 pages.models import CustomPage | ||||||
|
||||||
# @todo #682:120m Implement and reuse shopelectro.selenium.OrderPage for selenium tests. | ||||||
|
@@ -9,16 +13,37 @@ class OrderPage(Page): | |||||
|
||||||
def __init__(self, driver): | ||||||
super().__init__(driver) | ||||||
self.submit_button = Button(self.driver, (By.ID, 'submit-order')) | ||||||
|
||||||
@property | ||||||
def path(self): | ||||||
return CustomPage.objects.get(slug='order').url | ||||||
|
||||||
def fill_contacts(self, contacts): | ||||||
raise NotImplementedError | ||||||
def fill_contacts( | ||||||
self, name='Name', city='Санкт-Петербург', phone='2222222222', email='test@test.test', | ||||||
): | ||||||
contacts = { | ||||||
'id_name': name, | ||||||
'id_city': city, | ||||||
'id_phone': phone, | ||||||
'id_email': email, | ||||||
} | ||||||
|
||||||
def make_order(self): | ||||||
raise NotImplementedError | ||||||
for id_, value in contacts.items(): | ||||||
Input(self.driver, (By.ID, id_)).send_keys(value) | ||||||
|
||||||
def select_payment_type(self): | ||||||
raise NotImplementedError | ||||||
def make_order(self): | ||||||
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.
Suggested change
Maybe it's taste, up to you 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. It seems something went wrong and i can see the suggested change 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. @artemiy312 , sorry, fixed my comment above 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.
|
||||||
self.submit_button.click() | ||||||
|
||||||
def select_payment_type(self, payment_option: PaymentOptions): | ||||||
if payment_option not in PaymentOptions: | ||||||
raise ValueError( | ||||||
'An invalid payment type provided.' | ||||||
f'It should be one of: {PaymentOptions}' | ||||||
) | ||||||
|
||||||
item = Button( | ||||||
self.driver, | ||||||
(By.CSS, f'input[name="payment_type"][value="{payment_type.name}"]'), | ||||||
) | ||||||
item.click() |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -61,9 +61,8 @@ def update_catalog(): | |||||
collect_static() | ||||||
] | ||||||
|
||||||
# @todo #682:60m Implement check_purchase. | ||||||
# Handle errors. Report failed attempts. | ||||||
# Schedule it in the celery beat. | ||||||
# @todo #690:60m Handle errors in check_purchase. | ||||||
# Report failed attempts. Schedule it in the celery beat. | ||||||
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.
Suggested change
Maybe we'll write new functionality throw asyncio? This will allow us to move all functionality to asyncio bit by bit. 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. this code is too low related to check_purchase, i suppose. 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.
I believe, this PR is related to May be 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. @artemiy312 , seems interesting case here =) So, we should rename your PR to some sort of 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. I just have renamed names of issue and PR. Now it looks fine |
||||||
|
||||||
|
||||||
@app.task | ||||||
|
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.
so, let's implement
keys()
andvalues()
?Up to you
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.
Right now these methods aren't needed anywhere, so it will be redundant