Skip to main content

Automating Flipkart via selenium

                                           


Hi Folks,

we are automating a flipkart site where you will see how to search and filter the product you choose without logging in .

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

import org.testng.annotations.Test;

public class flipkart {


WebDriver driver;

@Test 

    public void test() 

    {

  System.setProperty("Webdriver.chrome.driver", "chromedriver");

   WebDriver driver = new ChromeDriver();

  driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

  driver.manage().window().maximize(); 

   

   driver.get("https://www.flipkart.com");

           driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

[For removing the popup window(check the xpath it might get changed later)]

  driver.findElement(By.xpath("//button[@class='_2KpZ6l _2doB4z']")).click();

[Entering mobile in search section]

   driver.findElement(By.xpath("//input[@type='text']")).sendKeys("Mobile");

[Clicking on search button(check the xpath it might get changed later)]

    driver.findElement(By.xpath("//*[@class='_34RNph']")).click();

           driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


[Using select method TO Select the price rang of mobile which is between 7000 to 25000(check the classanme in filter 1, it might get chnaged later)]

           Select  se= new Select(driver.findElement(By.className("_2YxCDZ")));                                  Se.selectByValue("7000");

           driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

           Select  de= new Select(driver.findElement(By.xpath("//body/div[@id='container']/div[1]/div[3]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/section[2]/div[4]/div[3]/select[1]")));

           de.selectByValue("25000");

[selecting the Ram of mobile] which os 3 GB

           driver.findElement(By.xpath("//div[@title='3 GB']")).click();

   driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

[Selecting Brand of mobile which is samsung]                  driver.findElement(By.xpath("//div[@id='container']/div[1]/div[3]/div[2]/div[1]/div/div/div/div/section[5]/div[2]/div/div[6]")).click();

   

   driver.close();

   driver.quit();


    }

}


Final Screenshot










Comments

Popular posts from this blog

Cucumber - Execution of test cases and reporting

Before going through this blog please checkout blog on   Cucumber Fundamentals Cucumber is testing tool which implements BDD(behaviour driven development).It offers a way to write tests that  anybody can understand, regardless of there technical knowledge. It users Gherkin (business readable language) which helps to  describe behaviour without going into details of implementation It's helpful for  business stakeholders who can't easily read code ( Why cucumber tool,  is  called  cucumber , I have no idea if you ask me I could have named it "Potato"(goes well with everything and easy to understand 😂) Well, According to its founder..... My wife suggested I call it  Cucumber  (for no particular reason), so that's how it got its  name . I also decided to give the Given-When-Then syntax a  name , to separate it from the  tool . That's why it's  called  Gherkin ( small variety of a cucumber that's been pickled. I...

Cucumber Datatable testing without using scenario outline and Issues

  Before going through this blog please visit blog The issue you might encounter while running cucumber project- 1.  you have created the cucumber all file in src/test/java and you are trying to  move it in another folder transition might not be smooth, It will give error one fix will led to other.(depends on the setup) 2. If on running a feature file and successfully creating a stepdef file, If application still says that  few steps are still needs to be implemented or all of them(not detecting creation of step definition) then there is a high chance you have mistakenly wrote some other annotation in stepdef when compares to you feature file eg:- feature file @And ( "^user close browser$" ) public   void  user_close_browser()  throws  Throwable { Stepdef:-             @Then ( "^user close browser$" ) public   void  user_close_browser()  throws  Throwable { driver .quit(); 3. Duplicate S...