Селен - Как добавить один и тот же товар в корзину много раз - PullRequest
0 голосов
/ 27 апреля 2020

Я пытался найти способ добавить один и тот же товар в корзину 3 раза, но он не работает, вы можете сказать мне, что мне не хватает? Как видите, я получаю элементы через Шаблон объекта страницы и импортирую в тестовый класс.

    '''
        import java.util.List;
        import org.openqa.selenium.WebElement;
        import org.testng.annotations.AfterTest;
        import org.testng.annotations.BeforeTest;
        import org.testng.annotations.Test;   
        import Practice1.test1.BaseClass;
        import pageObjects.CartPageObjects;

        public class ShopPage1Test extends BaseClass {

        //to invoke WebDriver and load website
            @BeforeTest()
        public void startURL() {
                globalDriver();

            }


            @Test
            public void getBase() {

       //get the single product which you want to add to cart
    WebElement product_to_add_to_cart  = CartPageObjects.get_single_product_name();


         //Get all your products in a list
                List<WebElement> all_products = CartPageObjects.get_All_Products();

            //Get all Products count
     int products_count = CartPageObjects.get_All_Products().size();

            //iterate through products list     
                for(int i=0; i<products_count;i++) {
                    if(all_products.get(i).equals(product_to_add_to_cart)) {

  //click add to cart element if product found in index
    int a=0;
   //iterate 3 times and click element
    while(a<3){                 
    a++;
        //click add to cart element
        CartPageObjects.add_to_cart_button().get(i).click();
    a=3;
    }
                }


                }


            }

            @AfterTest
            public void aftertests(){
                System.out.println("test finished");
            }

        }     
    '''
...