package browserhandling;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class allwithxpath {
public static WebDriver driver;
@Test(priority=1)
public void browserLaunch() throws InterruptedException{
System.setProperty("webdriver.chrome.driver","f:\\chromedriver.exe");
//Launch empty browser
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
//Open the bowser with respective Shopkio Url
driver.get("https://www.shopkio.com/");
Thread.sleep(3000);
//Click on Sarees link
WebElement ele=driver.findElement(By.id("clicked62"));
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("arguments[0].click()", driver.findElement(By.xpath("//*[@id='clicked62']")));
//Click on on Item
driver.findElement(By.xpath("//*[@id='bestselling']/div/div/div/div[1]/div/div[1]/div/div[2]/a")).click();;
Thread.sleep(3000);
}
@Test(priority=2)
public void addandcheckout() throws Exception{
//Click on Add to Cart
//driver.findElement(By.xpath("/html/body/section[2]/div[1]/div[1]/div/div/div[2]/div[6]/div[2]/div/a[1]")).click();
JavascriptExecutor js4=(JavascriptExecutor)driver;
js4.executeScript("arguments[0].click()", driver.findElement(By.xpath("//div[@class='mhide']")));
//Click on Checkout
JavascriptExecutor js1=(JavascriptExecutor)driver;
js1.executeScript("arguments[0].click()", driver.findElement(By.xpath("//*[@id='shopping-data']/div[3]/div[2]/a")));
}
@Test(priority=3)
public void guestlogindetails() throws InterruptedException{
//Click on Guest Login
driver.findElement(By.xpath("//*[@id='LoginDiv']/div[2]/a")).click();
//Enter name in name field
driver.findElement(By.xpath("//*[@id='first_name_guest']")).sendKeys("narasimha");
//Enter phonenumber in ph.no field
driver.findElement(By.xpath("//*[@id='mobile_no_guest']")).sendKeys("8688991234");
//Enter Address in Address field
driver.findElement(By.xpath("//*[@id='address_guest']")).sendKeys("hopefarm");
//Enter zipcode in zipcode field
driver.findElement(By.xpath("//*[@id='zip_code_guest']")).sendKeys("560066");
//Select DropdownBox for State
Select state=new Select(driver.findElement(By.xpath("//*[@id='state_id_guest']")));
state.selectByVisibleText("Karnataka");
Thread.sleep(3000);
//Select Dropdownbox for city
Select cityname=new Select(driver.findElement(By.xpath("//*[@id='city_id_guest']")));
cityname.selectByVisibleText("Bengaluru");
//Click on Submit Button
driver.findElement(By.xpath("//*[@id='SaveAddress']")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//Click on Next Button
JavascriptExecutor js2=(JavascriptExecutor)driver;
js2.executeScript("arguments[0].click()", driver.findElement(By.xpath("//*[@id='SaveAddress1']")));
}
@Test(priority=4)
public void placeorder(){
//Click on Place Order
driver.findElement(By.xpath("//*[@id='cod']")).click();
System.out.println("Order placed Successfuly");
}
}
Error as follows
PASSED: browserLaunch FAILED: addandcheckout java.lang.NullPointerException at browserhandling.allwithxpath.addandcheckout(allwithxpath.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:580) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
FAILED: guestlogindetails java.lang.NullPointerException at browserhandling.allwithxpath.guestlogindetails(allwithxpath.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:580) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
FAILED: placeorder java.lang.NullPointerException at browserhandling.allwithxpath.placeorder(allwithxpath.java:99) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:580) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
=============================================== Default test
Tests run: 4, Failures: 3, Skips: 0
=============================================== Default suite Total tests run: 4, Failures: 3, Skips: 0