Skip to content
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 11 commits into from
Jul 12, 2019

Conversation

ArtemijRodionov
Copy link
Contributor

Closes #938
Closes #939

@ArtemijRodionov ArtemijRodionov requested a review from duker33 July 9, 2019 18:14
@ArtemijRodionov ArtemijRodionov self-assigned this Jul 9, 2019
Copy link
Contributor

@duker33 duker33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some possible logic issues

try:
# use short_wait to avoid long pauses in case of the empty cart
positions_count = len(self.driver.short_wait.until(
self.condition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be formatted in one string

yield
self.driver.wait.until(are_changed)

def first(self) -> elements.Product:
Copy link
Contributor

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


def quantity(self):
return self.driver.short_wait.until(EC.visibility_of_element_located(
(By.XPATH, f'{self.xpath}div[4]/div[2]/input')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems it would be more good to add some class with templates.
We can prefix such classes as se-quantity or selenium-quantity. Like we do it with js- prefix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most cases xpath query optimization will be enough

Suggested change
(By.XPATH, f'{self.xpath}div[4]/div[2]/input')
(By.XPATH, f'{self.xpath}//input')

def set(self, quantity: int):
raise NotImplementedError

def increase(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe step is required (and for decrease method below too)

Suggested change
def increase(self):
def increase(self, step=1):

Up to you

@@ -100,6 +99,53 @@ def get_goals(self) -> selenium.Goals:
goals.fetch()
return goals

def assert_add(self, product: Product, goal_position: int): # Ignore CPDBear
reached_goals = self.get_goals()
self.assertTrue(reached_goals)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's object, it'll always return True. You should implement some reached_goals.not_empty() method

Checked iter if it affects on bool(MyClass()) result. Seems it's not:

In [11]: class A:
    ...:     def __iter__(self):
    ...:         for i in range(10):
    ...:             yield i
    ...:

In [12]: bool(A())
Out[12]: True

In [13]: class B:
    ...:     def __iter__(self):
    ...:         pass
    ...:

In [14]: bool(B())
Out[14]: True

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will implement __bool__ for the class

reached = reached_goals[goal_position]

self.assertIn('add', reached)
self.assertEqual(reached['currencyCode'], 'RUB')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems we should improve Goals class interface. All this dict fields is some Jedi knowledge.
Update related #940 task with the comment

reached_detail = reached['add'] # Ignore CPDBear
self.assertEqual(
len(reached_detail['products']),
1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you assume that reached goal will be only one, right?
What if we'll use the method like this?

self.assert_add(product, 0)
self.assert_add(product, 1)

The same is for remove

Copy link
Contributor Author

@ArtemijRodionov ArtemijRodionov Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reached_detail['products'] will have length greater 1 only in case if we will add/remove several products to the cart at the same time

It is possible only with clearing the cart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it in the next issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the same time

@artemiy312 , y, my code example was exactly about adding at the same time. Our you mean something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duker33 Yes, I meant at the same moment.

Adding/Removing products with individual clicks publishes separate reached goals with length of products field =1

To get length of goal's products field >1 we need to add/remove several different products in one click. Right now the only way to do it is clearing a fulfilled cart.

@ArtemijRodionov ArtemijRodionov merged commit 4ddb192 into master Jul 12, 2019
@ArtemijRodionov ArtemijRodionov deleted the 939-test-order-page-goals branch July 12, 2019 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants