Assignment 7: Automate "Search Product" Functionality for E-Commerce Website using Selenium

Assignment 7: Automate Search Product Functionality on Dummy E-Commerce Website

Automation Level - Intermediate

Steps to Automate:


2. Move your cursor over Women's link.

3. Click on sub menu 'T-shirts'

4. Get Name/Text of the first product displayed on the page.

5. Now enter the same product name in the search bar present on top of page and click search button.

6. Validate that same product is displayed on searched page with same details which were displayed on T-Shirt's page.

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



Reference Links for Solution :

Read - Selenium Webdriver Tutorials Series


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

    Comments

    1. package com.testUKR;

      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 io.github.bonigarcia.wdm.WebDriverManager;

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

      driver.get(URL);
      driver.manage().window().maximize();
      Actions actions=new Actions(driver);
      driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS);
      WebElement womenTab=driver.findElement(By.linkText("WOMEN"));
      WebElement TshirtTab=driver.findElement(By.xpath("//div[@id='block_top_menu']/ul/li[1]/ul/li[1]/ul//a[@title='T-shirts']"));
      actions.moveToElement(womenTab).moveToElement(TshirtTab).click().perform();
      Thread.sleep(2000);
      String ProductName=driver.findElement(By.xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/div[3]/div[2]/ul[1]/li[1]/div[1]/div[2]/h5[1]/a[1]")).getText();
      System.out.println(ProductName);
      driver.findElement(By.id("search_query_top")).sendKeys(ProductName);
      driver.findElement(By.name("submit_search")).click();
      String SearchResultProductname=driver.findElement(By.xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/div[3]/div[2]/ul[1]/li[1]/div[1]/div[2]/h5[1]/a[1]")).getText();

      if(ProductName.equalsIgnoreCase(SearchResultProductname)) {
      System.out.println("Results Matched;Test Case Passed");
      }else
      {
      System.out.println("Results NotMatched;Test Case Failed");
      }
      driver.close();
      }

      }

      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