Home java Avtotest on Java + Selenium. Tell me on architecture Page Object and...

Avtotest on Java + Selenium. Tell me on architecture Page Object and logic

Author

Date

Category

Have the following task:

on the website of the online store
https://shoptool.com.ua/

Write Avtotest:

  1. Go to “Discounts” section
  2. Randomno, on the 3rd pages to choose a product, fall into the product card and check availability of the promotion and old price
  3. do it for 3 products (the choice of the number of goods being checked is flexible).

Actually, as I imagine:

  • Main class. Initialization, transition to a page with discounts, main
    Test logic
  • Class for a page with discounts Find all elements of goods by XPath , choose 3 random goods and prescribe them method
    click () (random pages still miss, do everything on the first)
  • Class for the product card page Here we need to check if it is in each of 3 products such elements as a promotional and old price.
    To do this, I understand it, you need to use
    Findelements () , which returns a sheet of elements. If in it will be
    2 values, it means everything is fine. If less, it means with a commodity
    Problem.

Actually, I do not quite understand how to associate everything and how to register the main logic. I will be very grateful for detachable answers.


Answer 1

The answer is not the truth of the last instance. Just in the comments would not fit.
I would suggest another option.

Once you have found a list of WebElement, then after manipulations on the page items from the list may not be available. Then you will receive NosuchelementException. Therefore, it is better to get a list from the Discount Page, do not touch the page, open each item in a new tab, get a discount, close the tab, open another item in a new tab.

  1. Open Page Main
  2. Go to Discounts page
  3. Describe a discount page in such a way that List is filled all products. (by default they are 24) (// * [@ id = "products_on_sale_pagination_contents"] / div Here are their ways)
  4. walk along the For-Ohm list + limit the number of your dynamic value.
  5. for each item Open it in the new SwitchTotab
  6. Initialize a new class, which describes the product page, where it is described how to get the price, action, etc., New Products. WAIITFORLOAD (). GetMepriceplease ()
  7. here you can either close the tab, or just go to the first tab. Where is the list of goods
  8. make the same for another element

Total you collected a list of necessary prices.

The advantages of the approach in that, do not get nosuchelementException, in addition to this items will remain in their places and will not be moved if one of them disappeared from discounts or new added.

Cons: 24 element limit. Or before initialization you need to click on “Show more 24”, “Show another 24”, “Show another 24”

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions