Auto insertion of values in pop up text fields using selenium - selenium

I am trying to do auto-insertion of values to the fields inside the pop up(see attached image) using the code below. But the insertion of values to the fields is not happening using the automation code below.
Would appreciate, if someone can provide the reason and solution for the same.
Any help is appreciated:
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.fail;
public class test9 {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
private WebElement foundElement;
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://www.url.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void test9() throws Exception {
driver.get(baseUrl + "/Login.aspx");
driver.findElement(By.id("dnn_ctr362_Login_Login_DNN_txtUsername")).clear();
driver.findElement(By.id("dnn_ctr362_Login_Login_DNN_txtUsername")).sendKeys("comp-da#comp.com");//dummy username
driver.findElement(By.id("dnn_ctr362_Login_Login_DNN_txtPassword")).clear();
driver.findElement(By.id("dnn_ctr362_Login_Login_DNN_txtPassword")).sendKeys("password");//dummy password
driver.findElement(By.id("dnn_ctr362_Login_Login_DNN_cmdLogin")).click();
driver.findElement(By.xpath("//div[#id='Nav']/span/span/div[3]/a")).click();
driver.findElement(By.id("dnn_cd_Banner_Customer_b")).click();
Thread.sleep(10000);
WebElement userName = find(By.xpath("//*[#id=\"dnn_ctr384_View_CreateDealerAdmin_email\"]"),"abc#gmail.com");
find(By.id("dnn_ctr384_View_CreateDealerAdmin_firstname"),"Abc");
find(By.id("dnn_ctr384_View_CreateDealerAdmin_lastname"),"R");
find(By.id("dnn_ctr384_View_CreateDealerAdmin_firstname"),"test1");
find(By.id("dnn_ctr384_View_CreateDealerAdmin_lastname"),"abc");
find(By.id("dnn_ctr384_View_CreateDealerAdmin_password"),"password");
find(By.id("dnn_ctr384_View_CreateDealerAdmin_passwordconfirm"),"password");
search(By.id("dnn_ctr384_View_CreateDealerAdmin_create_b_input"));
driver.findElement(By.cssSelector("div.Controls")).click();
driver.findElement(By.id("dnn_dnnLogin_enhancedLoginLink")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
public WebElement find(By by,String keys){
By byy = by;
String key=keys;
System.out.println(by.toString()+keys.toString());
for (int milis=0; milis<3000; milis=milis+3000) {
try {
foundElement = driver.findElement(by);
//driver.findElement(by).clear();
driver.findElement(by).click();
Thread.sleep(5000);
foundElement.sendKeys("");
Thread.sleep(5000);
foundElement.sendKeys(keys);
Thread.sleep(5000);
foundElement.sendKeys(keys);
} catch (Exception e) {
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
return foundElement;
}
public WebElement search(By by){
By byy = by;
for (int milis=0; milis<3000; milis=milis+3000) {
try {
driver.findElement(by).click();
driver.findElement(by).click();
} catch (Exception e) {
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
return foundElement;
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alert.getText();
} finally {
acceptNextAlert = true;
}
}
}
EDIT
Including the html which contains Email, First Name, Last Name etc.
<div id="Heading">
<span id="dnn_ctr384_View_CreateDA">Create DA</span>
<span class="nyk_ButtonSpan">
</div>
<table id="dnn_ctr384_View_CreateDealerAdmin" class="nykTable" border="0">
<tbody>
<tr class="nykRow">
<td class="nykCreateLbl" style="vertical-align: top">
<td class="nykCreateEntry">
</tr>
<tr class="nykRow">
<tr class="nykRow">
<tr class="nykRow">
<tr class="nykRow">
<tr id="dnn_ctr384_View_CreateDealerAdmin_assigned2_row" class="nykRow">
<tr class="nykRow">
</tbody>
</table>

Instead of using "Alert alert = driver.switchTo().alert()" statement you will have to use "driver.switchTo().activeElement()".This is the solution of your problem.

Related

ExtentTest class throws null pointer error

Scope(This is what i want to do): Hey looking for to attached screenshot in my extent report file.
Problem: so now i have used the ExtentTest class in BaseClass file. but when i run my testsuit from testNG.xml file, it give me an below error.
java.lang.NullPointerException: Cannot invoke "org.testng.ITestResult.getStatus()" because "com.example.PageClass.BaseClass.result" is null
Here is my Code in BaseClass.
package com.example.PageClass;
import com.example.Utils.Utilities;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.ITestResult;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.Duration;
import java.util.Properties;
public class BaseClass {
public static WebDriver driver;
public static Properties prop;
public static LoginPage loginPage;
public static ExtentTest extentTest;
public static ITestResult result;
public static void properties() {
try {
FileInputStream fis = new FileInputStream("src/main/resources/generic.properties");
prop = new Properties();
prop.load(fis);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void setDriver() {
properties();
if (prop.getProperty("browser").contains("chrome")) {
System.setProperty("webdriver.chrome.driver", prop.getProperty("driverPath"));
driver = new ChromeDriver();
} else {
// FirefoxDriverManager.firefoxdriver().setup();
// driver = new FirefoxDriver();
}
driver.get(prop.getProperty("url"));
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(60));
driver.manage().window().maximize();
loginPage = PageFactory.initElements(driver, LoginPage.class);
}
public static void closeDriver() throws IOException {
if (result.getStatus() == ITestResult.FAILURE) {
extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS " + result.getName()); //to add name in extent report
extentTest.log(LogStatus.FAIL, "TEST CASE FAILED IS " + result.getThrowable()); //to add error/exception in extent report
String screenshotPath = null;
try {
screenshotPath = Utilities.getUtilities().getScreenshot(driver, "firstScreenShot");
} catch (IOException e) {
throw new RuntimeException(e);
}
extentTest.log(LogStatus.FAIL, extentTest.addScreenCapture(screenshotPath)); //to add screenshot in extent report
extentTest.log(LogStatus.PASS, extentTest.addScreenCapture(screenshotPath)); //to add screenshot in extent report
}
driver.quit();
}
}
code inside StepsDef file:
package com.example.StepDefinitions;
import com.example.PageClass.BaseClass;
import com.example.Utils.Utilities;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.testng.annotations.*;
import java.io.IOException;
public class LoginStepDefs extends BaseClass implements ITestListener {
#Before
public void setup(){
setDriver();
}
#After
public void teardown() throws IOException {
closeDriver();
}
#Then("I go to OrangeHRM Home page.")
public void iGoToOrangeHomePage() {
try {
loginPage.getOrangeHRMHome();
} catch (Exception e) {
System.out.println("Username not sent.");
}
}
#When("I enter {string} username and {string} password.")
public void iEnterUsernameAndPassword(String arg0, String arg1) {
try {
loginPage.systemLogin(arg0,arg1);
} catch (Exception e) {
System.out.println("Username not sent.");
}
}
#When("I enter username and password.")
public void iEnterUsernameAndPassword() {
try {
loginPage.systemLogin("Admin","admin123");
} catch (Exception e) {
System.out.println("Username not sent.");
}
}
#And("I navigate to PIM tab and click on add employee.")
public void iNavigateToPIMTabAndClickOnAddEmployee() {
try {
loginPage.clickOnPIM().clickOnAddEmployee();
} catch (Exception e) {
System.out.println("Username not navigate to add employee tab.");
}
}
#And("I enter employee details and save it.")
public void iEnterEmployeeDetailsAndSaveIt() {
try {
loginPage.enterFirstNameAndLastName().fileUpload().checkBoxCreateLoginDetail().enterLoginDetail().verifySuccessMessage().verifySuccessMessageForAdd();
} catch (Exception e) {
System.out.println("Username not navigate to add employee tab.");
}
}
My Folder Structure:
Can Anyone please help me out in this?

Selenium web driver and csv file

I have data in csv file and also integrate with Selenium.
The test scenario is Search the name of product and verify that the Product name, category, Brand and sub-category according to the document or not? Please Help if it is possible.
Here is my code
public class ProductVerification {
public String baseurl="https://souqofqatar.com/admin";
String driverPath="C:\\Users\\Novatore\\Desktop\\Selenium-Drivers\\chromedriver.exe";
String CSV_file="CSVdatafile\\Cat-Home Appliances and SubCat-Home Comfort (1).csv";
static WebDriver driver;
String line="";
#BeforeMethod
public void launchBrowser() throws InterruptedException {
System.setProperty("webdriver.chrome.driver",driverPath);
driver =new ChromeDriver();
driver.get(baseurl);
driver.manage().window().maximize(); driver.findElement(By.xpath("//[#id=\"admin_user_email\"]")).sendKeys("admin#example.com");
driver.findElement(By.xpath("//*[#id=\"admin_user_password\"]")).sendKeys("password");
driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div/form/fieldset[2]/ol/li/input")).click();
driver.findElement(By.xpath("/html/body/div[1]/div[1]/ul[1]/li[5]/a")).click();
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.scrollBy(450,0)", "");
Thread.sleep(3000);
}
#Test
public void search() throws InterruptedException, IOException, CsvException {
File file = new File(CSV_file);
if(file.exists()){
System.out.println("File Exists");
}
try {
BufferedReader br=new BufferedReader(new FileReader(file));
while((line=br.readLine()) !=null){
while((line=br.readLine()) !=null) {
String[] values = line.split(",");
String row= (values[1]);
for (int i=0; row!=null;i++) {
driver.findElement(By.xpath("//*[#id=\"q_name\"]")).sendKeys(""+row);
Thread.sleep(5000);
driver.findElement(By.xpath("/html/body/div[1]/div[4]/div[2]/div/div/form/div[9]/input[1]")).click();
Thread.sleep(3000);
String name=driver.findElement(By.xpath("//td[#class='col col-name']")).getText();
System.out.println(name);
if(name!=row) {
System.out.println(name+" Not find");
}
}
}
}}catch(FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}
catch(NumberFormatException e) {
e.printStackTrace();
}
}
#AfterMethod
public void CloseBrowser() {
driver.close();
}
}

Selenium- Session ID is null. Using WebDriver after calling quit()? Only one test in execution

I'm trying to execute written in Selenium with Junit. Its just one test. The test runs but I'm getting this failure message -
1) testTripPlannerJUnit(com.example.tests.TripPlannerJUnit)
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
I understand the problem is with teardown but how can i correct it.
package com.example.tests;
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import io.github.bonigarcia.wdm.ChromeDriverManager;
public class TripPlannerJUnit {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
ChromeDriverManager.getInstance().setup();
driver = new ChromeDriver();
baseUrl = "https://www.google.com.au/.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testTripPlannerJUnit() throws Exception {
driver.get("https://transportnsw.info/trip#/");
driver.findElement(By.id("search-input-From")).click();
driver.findElement(By.id("search-input-From")).clear();
driver.findElement(By.id("search-input-From")).sendKeys("North Sydney Station");
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='North Sydney Station'])[1]/following::li[1]")).click();
driver.findElement(By.id("search-input-To")).click();
driver.findElement(By.id("search-input-To")).clear();
driver.findElement(By.id("search-input-To")).sendKeys("Town Hall Station");
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='Town Hall Station'])[1]/following::ul[1]")).click();
driver.findElement(By.id("search-button")).click();
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
In the #After, you have written driver.quit() first and then you have a if condition followed by the implicit wait on the driver, however till the time your code reaches the implicit wait line, the driver instance has already been quit by the driver.quit() line.
So to correct it, please try:
#After
public void tearDown() throws Exception {
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.quit();
}
Have just moved the driver.quit() line to the end of the code and one more suggestion, in your #After, you have put an implicit wait, but you are not interacting with any webElement there, so the implicit wait line of code can be removed as it is not required.

selenium webdriver giving "unknown error: Element is not clickable at point (747, 238)" when clicking on an angular js date picker

package redbus;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Searchforbus {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.get("http://www.redbus.in/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.findElementById("src").sendKeys("Nagercoil");
driver.findElementByClassName("selected").click();
driver.findElementById("dest").sendKeys("Chennai");
driver.findElementByClassName("selected").click();
Thread.sleep(3000);
driver.findElementById("onward_cal").click();
WebElement element1= driver.findElementByXPath("//div[#id='rb-calendar_onward_cal']/table/tbody/tr[3]/td[6]");
System.out.println("Check1");
Actions builder= new Actions(driver);
builder.moveToElement(element1).click().perform();
System.out.println("Check2");
}
}
I am getting the below error:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (747, 238). Other element would receive the click: <label for="onward_cal" style="font-family:Lato" class="db text-trans-uc move-up">...</label>
(Session info: chrome=54.0.2840.99)
at redbus.Searchforbus.main(Searchforbus.java:28)
#vinu the date you are provided in locator element1 points to 3rd December which is disabled in calender since it is past date, make sure you provide enabled/available dates
Make a habit of using explicit wait condition before clicking tricky element like calender
e.g WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("element_xpath")));
ref links
Rahul is right. You selected past date which is disabled. try to select future date and let us know what is the error if it fails.
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class CommonSeleniumUtils extends Driver {
static WebDriver driver = Driver.getDriver();
public void switchToWindowByTitle(String title) {
Set<String> windows = driver.getWindowHandles();
System.out.println("Amount of windows that are currently present :: " + windows.size());
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().startsWith(title) || driver.getTitle().equalsIgnoreCase(title)) {
break;
} else {
continue;
}
}
}
public void clickWithJS(WebElement elementtoclick) {
WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(ConfigurationReader.getProperty("timeout")));
wait.until(ExpectedConditions.elementToBeClickable(elementtoclick));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", elementtoclick);
((JavascriptExecutor) driver).executeScript("arguments[0].click();", elementtoclick);
}
public void waitForPresenceOfElementByCss(String css) {
WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(ConfigurationReader.getProperty("timeout")));
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(css)));
}
public void waitForVissibilityOfElement(WebElement element) {
WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(ConfigurationReader.getProperty("timeout")));
wait.until(ExpectedConditions.visibilityOf(element));
}
public void waitForStaleElement(WebElement element) {
int i = 0;
while (i < 10) {
try {
element.isDisplayed();
break;
} catch (StaleElementReferenceException e) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
e.printStackTrace();
i++;
} catch (NoSuchElementException e) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
e.printStackTrace();
i++;
} catch (WebDriverException e) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
e.printStackTrace();
i++;
}
}
}
public boolean verifyElementIsNotPresent(String xpath) {
List<WebElement> elemetns = driver.findElements(By.xpath(xpath));
return elemetns.size() == 0;
}
public boolean verifyElementIsNotPresent(By by) {
List<WebElement> elemetns = driver.findElements(by);
return elemetns.size() == 0;
}
public void scrollToElement(WebElement element) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
}
public void hitEnterUsingRobot() {
Robot rb;
try {
rb = new Robot();
rb.keyPress(KeyEvent.VK_ENTER);
rb.keyRelease(KeyEvent.VK_ENTER);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public boolean verifyAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException Ex) {
System.out.println("Alert is not presenet");
}
return false;
}
public static void takeSnapShot() {
try {
TakesScreenshot scrShot = ((TakesScreenshot) driver);
File SrcFile = scrShot.getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir") + "\\screenshots.jpg";
System.out.println(path);
File DestFile = new File(path);
FileUtils.copyFile(SrcFile, DestFile);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void safeJavaScriptClick(WebElement element) throws Exception {
try {
if (element.isEnabled() && element.isDisplayed()) {
System.out.println("Clicking on element with using java script click");
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
} else {
System.out.println("Unable to click on element");
}
} catch (StaleElementReferenceException e) {
System.out.println("Element is not attached to the page document "+ e.getStackTrace());
} catch (NoSuchElementException e) {
System.out.println("Element was not found in DOM "+ e.getStackTrace());
} catch (Exception e) {
System.out.println("Unable to click on element "+ e.getStackTrace());
}
}
}
After this, call this method ===>>> safeJavaScriptClick
WebElement element = driver.findElement(By.xpath("YOUR XPATH"));
try {
seleniumTools.safeJavaScriptClick(element);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Selenium is unable to detect the Checkout button and add product in cart

The problem is, Selenium is unable to detect the Checkout button and add product in cart.
package automationFramework;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Checkout {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://sng.bestpricewebsitedesign.com/";
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
}
#Test
public void testNewCheckout() throws Exception {
driver.get(baseUrl + "/index.php?route=common/home");
driver.findElement(By.linkText("Home")).click();
driver.findElement(By.linkText("Login")).click();
driver.findElement(By.id("input-email")).clear();
driver.findElement(By.id("input-email")).sendKeys("leo#abc.com");
driver.findElement(By.id("input-password")).clear();
driver.findElement(By.id("input-password")).sendKeys("asdfgh");
driver.findElement(By.cssSelector("input.btn.btn-primary")).click();
driver.findElement(By.linkText("Store")).click();
driver.findElement(By.xpath("(//button[#type='button'])[14]")).click();
driver.findElement(By.cssSelector("#cart > button.dropdown-toggle")).click();
driver.findElement(By.id("button-payment-address")).click();
driver.findElement(By.id("button-shipping-address")).click();
driver.findElement(By.id("button-shipping-method")).click();
driver.findElement(By.name("agree")).click();
driver.findElement(By.id("button-payment-method")).click();
driver.findElement(By.id("button-confirm")).click();
driver.findElement(By.linkText("Continue")).click();
driver.findElement(By.linkText("Logout")).click();
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
Following is the code for adding 'Blue Tshirt' in cart and perform check out.
#Test
public void testNewCheckout() throws Exception {
driver.get(baseUrl + "/index.php?route=common/home");
driver.findElement(By.linkText("Home")).click();
driver.findElement(By.linkText("Login")).click();
driver.findElement(By.id("input-email")).clear();
driver.findElement(By.id("input-email")).sendKeys("leo#abc.com");
driver.findElement(By.id("input-password")).clear();
driver.findElement(By.id("input-password")).sendKeys("asdfgh");
//driver.findElement(By.cssSelector("input.btn.btn-primary")).click();
driver.findElement(By.xpath("//input[#value='Login']")).click();;
driver.findElement(By.linkText("Store")).click();
driver.findElement(By.xpath("//h4/a[text()='Blue Tshirt']/following::span[text()='Add to Cart'][1]")).click();
//driver.findElement(By.cssSelector("#cart > button.dropdown-toggle")).click();
driver.findElement(By.xpath("//div[#id='cart']/button[1]")).click();
driver.findElement(By.id("button-payment-address")).click();
driver.findElement(By.id("button-shipping-address")).click();
driver.findElement(By.id("button-shipping-method")).click();
driver.findElement(By.name("agree")).click();
driver.findElement(By.id("button-payment-method")).click();
driver.findElement(By.id("button-confirm")).click();
driver.findElement(By.linkText("Continue")).click();
driver.findElement(By.linkText("Logout")).click();
}
I have tested above code and it works fine for me. Please replace the existing test method with above one and let me know, if it works for you.