Assignment 5: Automate "Buy Product" Functionality for E-commerce Website using Selenium

Assignment 5: Automate Buy Product Functionality for dummy E-Commerce Website

Automation Level - Expert

Steps to Automate:


2. Login to the website.

3. Move your cursor over Women's link.

4. Click on sub menu 'T-shirts'.

5. Mouse hover on the second product displayed.

6. 'More' button will be displayed, click on 'More' button.

7. Increase quantity to 2.

8. Select size 'L'

9. Select color.

10. Click 'Add to Cart' button.

11. Click 'Proceed to checkout' button.

12. Complete the buy order process till payment.

13. Make sure that Product is ordered.

If you find it difficult to automate above steps, then follow the reference link.




Reference Links for Solution:

Join Telegram channel at https://t.me/techlistic
Feel free to ask queries or share your thoughts in comments or email me.

Comments

  1. Please send me Selenium Script of all Assignments.
    At my mail ID sonali.selokar@yahoo.com

    Thanks,
    Sonali

    ReplyDelete
  2. Hi, Could you please tell me how to switch to alerts or windows in this assignment. After "Add To Cart", there is a window pop-up/alert/frame in which we have to click on "Proceed to Checkout". Unable to switch windows here. Please help.

    ReplyDelete


  3. import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.support.ui.Select;

    import io.github.bonigarcia.wdm.WebDriverManager;

    public class EcomExpert {
    public static void main(String[] args)
    {
    WebDriverManager.chromedriver().setup();
    WebDriver driver=new ChromeDriver();
    String URL="http://automationpractice.com/index.php";

    driver.get(URL);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(3000, TimeUnit.MILLISECONDS);
    //Click on Sign in
    driver.findElement(By.linkText("Sign in")).click();
    //Login
    driver.findElement(By.id("email")).sendKeys("test1249@test.com");
    driver.findElement(By.id("passwd")).sendKeys("PKR@PKR");
    driver.findElement(By.id("SubmitLogin")).click();
    //Click on Women
    driver.findElement(By.linkText("WOMEN")).click();

    WebElement SecondImg=driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[3]/div[2]/ul/li[2]/div/div[1]/div/a[1]/img"));
    WebElement MoreBtn=driver.findElement(By.xpath("/html/body[1]/div[1]/div[2]/div[1]/div[3]/div[2]/ul/li[2]/div[1]/div[2]/div[2]/a[2]"));
    Actions actions=new Actions(driver);
    actions.moveToElement(SecondImg).moveToElement(MoreBtn).click().perform();

    //Change quantityby 2
    driver.findElement(By.id("quantity_wanted")).clear();
    driver.findElement(By.id("quantity_wanted")).sendKeys("2");

    //Select size as L
    WebElement Sizedrpdwn=driver.findElement(By.xpath("//*[@id='group_1']"));
    Select oSelect=new Select(Sizedrpdwn);
    oSelect.selectByVisibleText("M");

    //Select Color
    driver.findElement(By.id("color_11")).click();

    //click on add to cart
    driver.findElement(By.xpath("//p[@id='add_to_cart']//span[.='Add to cart']")).click();

    //click on proceed
    driver.findElement(By.xpath("/html//div[@id='layer_cart']//a[@title='Proceed to checkout']/span")).click();
    //Checkout page Proceed
    driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[3]/div/p[2]/a[1]/span")).click();
    driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[3]/div/form/p/button/span")).click();
    //Agree terms&Conditions
    driver.findElement(By.xpath("//*[@id=\"cgv\"]")).click();
    driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[3]/div/div/form/p/button/span")).click();

    //Click on Payby Check
    driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[3]/div/div/div[3]/div[2]/div/p/a")).click();
    //Confirm the order
    driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div[3]/div/form/p/button/span")).click();

    //COnfirmation Text
    String ConfirmationText=driver.findElement(By.xpath("//div[@id='center_column']/p[@class='alert alert-success']")).getText();
    if(ConfirmationText.contains("complete")) {
    System.out.println("Order Completed: Test Case Passed");
    }else {
    System.out.println("Order Not Successfull: Test Case Failed");
    }

    }
    }

    ReplyDelete

Post a Comment

Popular Posts

Top 10 Demo Websites to Practice Selenium Webdriver Online

How To Handle Dynamic Xpaths (Web Table) in Selenium WebDriver

How to Take Screenshot and Partial Screenshot in Selenium WebDriver

Selenium WebDriver - Browser and Navigation Commands

Automation Framework Building 1st step - Implementing Code Re-usablility