How to validate?

Answered

Hi,

I was trying to select few products and adding them to cart/Bag and I want to verify the selected Products are same in the cart/Bag. Please let me know how to do it.

URL is: http://store.demoqa.com/products-page/product-category/

Note: What all items you are selecting those items should be in your shopping cart.

Doctor Asked on September 6, 2014 in Selenium WebDriver.
Add Comment
  • 5 Answer(s)
    Best answer

    HI Rocky,

    First of all thanks for aksing using ForumsQA, second many thanks for supporting us by giving solutions on asked questions, third congrats as i can pick up that you have learned alot in last few days and trying different scenarios & fourth good luck for your future.

    Coming back to you question:
    I think you got confused with Modular Driven  & Page Object Model, as the above example you have given us is a part of Page Object model (POM). POM helps us to identify objects. Where as Modular Driven Framework (MDF) is something in which we combine the series of steps and rather calling the each of the steps one by one we just call that modular part.

    Now, if we take the same example of our Framework, you can see that in the POM class of Product Listing Page ,  we are selecting product with the location of the product. Right, it is not with the product name. Means, what so ever is the first product, we will select that and like this we will select second as well. So that is the use of dynamic Page Objects.

    I am happy to see that what you are trying to do here is something very userfull in test, which is verifying the product on Add to cart page. So to handle this you just need a simple trick or the way to handle the situation. There can two possible solutions to that:

    First: Get the name of the first and second product by using some element.getText() or anything and store it in the same Excel file from which you are passing your other data. Once you add those product in to your cart, go to cart page, again get the name of the products from the cart page and compare the text name of the products from the Excel. Hope you get it what I am trying to say here.

    Second: Create String variables on your main test script and store the name of the products on those variables and later you can easily compare the text of the variables with text of the Add to Cart page products name.

    I am not intrested in giving you the code for it, as I know you would love to do this by your self.

    Best Regards,
    Lakshay Sharma

    Professor Answered on September 9, 2014.

    @Lakshay: Yes, learning many things from this forum.

    Many thanks for your suggestions and I will work on these.

    on September 9, 2014.

    As Per Second Suggestion:Suppose, if there are more than 500 items then? any particular logic for this?.Toolsqa demo site is having less product so we can store the values, if we see in other shopping applications then we can see more products. Here need to know how to handle multiple data.Please let me know.

    on September 13, 2014.
    Add Comment

    Virender I am working on MDF and I am pasting screenshot may you can understand (Hopefully).

    Function is below:

    
    public static WebElement productCategory_Accessories(WebDriver driver){
    
    WebElement element = driver.findElement(By.linkText("Product Category"));
    
    Actions action = new Actions(driver);
    
    action.moveToElement(element).perform();
    
    WebElement subElement = driver.findElement(By.linkText("Accessories"));
    
    action.moveToElement(subElement);
    
    action.click();
    
    action.perform();
    
    return element;
    
    }
    
    

    Called above function:
    HomeActs.productCategory_Accessories(driver);

    1st step: Selected the items

    RE: How to validate?

    2nd Step: In the cart page, selected items are displayed and verify the Selected items are same as above (Step no 1). How to do this? 

    RE: How to validate?

    Hope all is well 🙂

    Doctor Answered on September 6, 2014.
    Add Comment

    Can you show us what all you have written by now to validate the products in your cart? What you are requesting is for code, better thing would be you tell us what you have done and where you are facing the problem. We might help you there.

    Thanks
    Virender

    Professor Answered on September 6, 2014.
    Add Comment

    Need a simple logic (Not MDF) to verify selected items are same as in the Cart .

    Doctor Answered on September 6, 2014.
    Add Comment

    hi Rocky
    I Would Suggest You to Write a Method With Webelement in  Parameter
    And inside Method Find Element  in Try Block and in case Method Runs Successfully Element is Present Else Catch Null Pointer Exception
    and Write a Message Element not Present
    i Hope it Will Work

    thanks
    ankit

    Vice Professor Answered on September 8, 2014.

    Hi Ankit,

    Thanks for your time and suggestion on the above query. I tried with different logic but didn’t get success. The same data in two different pages and code should be generic (Because dealing with ecommerce application).

    For simple ex:
    1.Open the myntra.com
    2.Select 2 products
    3.Go to the Shopping bag/Cart
    4.Verify whether selected products in 2 steps are exists in Shopping bag/Cart (Step 3).

    But  above using different methods (Step 2 and 3 should be in different methods) and code should be generic.

    Just I am trying to compare text of selected items.

    on September 8, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.