Sunday 14 February 2016

Sample automation testcase on flipkart application

Automate the following testcase:
=========================

1.Open a browser
2.Enter url as www.flipkart.com
3.Check whether flipkart page is opened or not
4.If it is opened perform the required operations and display on the console that flipkart page is opened.
5.Perform mouse over electronics
6.Click on Mobiles
7.Click on samsung
8.Select the price range
9.Select the first mobile
10.Close the browser

Automation script:
-------------------------
FlipKartTestCase.java
----------------------------

package assignments;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class FlipKartTestCaseOne {

WebDriver webDriver;

String expecteTitle = "";
String actualValue;

@BeforeSuite
public void launchingIEBrowser() {

System.setProperty("webdriver.chrome.driver","D:\\Ramesh\\ChromeDriver.exe");
  webDriver = new ChromeDriver();
webDriver.manage().window().maximize();
webDriver.manage().deleteAllCookies();
webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

}

@AfterSuite
public void closeBrowser() {
webDriver.quit();

}

@Test
public void testScript() throws InterruptedException {

webDriver.get("https://www.flipkart.com");
actualValue = webDriver.getTitle();
if (actualValue.equalsIgnoreCase(expecteTitle)) {

Actions a = new Actions(webDriver);
a.moveToElement(
webDriver.findElement(By
.xpath("//span[text()='Electronics']"))).build()
.perform();
Thread.sleep(2000);

// clcik on mobiles
webDriver
.findElement(
By.xpath("//*[@id='submenu_electronics']/div[2]/div[1]/ul[1]/li[1]/a"))
.click();
Thread.sleep(2000);

// click on samsung
webDriver.findElement(
By.xpath("//*[@data-tracking-id='Top Brands_Samsung']"))
.click();
Thread.sleep(2000);

// select the price range
webDriver.findElement(
By.xpath("//*[@id='price_range']/li[2]/a/span[1]")).click();
Thread.sleep(3000);

// click on moblie
webDriver.findElement(
By.xpath("//*[@class='pu-visual-section']/a[1]")).click();
;
Thread.sleep(3000);
}

}

}

No comments:

Post a Comment