Skip to content

Instantly share code, notes, and snippets.

@nhatthuyld
Created May 19, 2016 10:10
Show Gist options
  • Save nhatthuyld/19c061aa3121a227e25277c1ae475060 to your computer and use it in GitHub Desktop.
Save nhatthuyld/19c061aa3121a227e25277c1ae475060 to your computer and use it in GitHub Desktop.
package com.examples.seleniumrc;
import java.util.function.Predicate;
import javax.swing.plaf.synth.SynthStyleFactory;
import org.hamcrest.core.Is;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By.ByXPath;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.events.WebDriverEventListener;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.thoughtworks.selenium.webdriven.commands.WaitForPageToLoad;
public class KyotokimonoRentalTest {
private static final com.google.common.base.Predicate<WebDriver> Is = null;
WebDriver driver;
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "D:\\DEV\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://kyotokimono-rental.com/reserve");
}
@After
public void tearDown() throws Exception {
// driver.quit();
}
/*
* @Test public void alertMessage() throws InterruptedException {
*
* // click next button driver.findElement(By.xpath(
* ".//*[@id='formAddPlan']/div[1]/div/ul/li[1]/div[3]/div[2]/div[1]/a")).
* click(); Thread.sleep(500); // throw alert Alert alert =
* driver.switchTo().alert(); alert.getText();
* System.out.println(alert.getText()); alert.accept(); Thread.sleep(500);
*
* }
*/
@Test
public void fisrtSelectBox() throws InterruptedException {
WebElement checkBoxElement = driver.findElement(By.id("list_plans_1SelectBoxItContainer"));
checkBoxElement.click();
Thread.sleep(500);
// select 3 people
WebElement itemElement3 = driver
.findElement(By.xpath(".//*[@id='list_plans_1SelectBoxItOptions']/li[4]/a/span[2]"));
itemElement3.click();
Thread.sleep(500);
// click next button
driver.findElement(By.xpath(".//*[@id='formAddPlan']/div[1]/div/ul/li[1]/div[3]/div[2]/div[1]/a")).click();
Thread.sleep(700);
// click place
driver.findElement(By.xpath(".//*[@id='choose-shop']/li[2]/label")).click();
Thread.sleep(3000);
// choose random date
WebElement Date = driver
.findElement(By.xpath(".//*[@id='choose-date']/div[2]/div/table/tbody/tr[1]/td[1]/div/div"));
Thread.sleep(1000);
System.out.println(Date.getText());
Integer i = 1, j = 1;
String DateText, a, b, DateString;
for (; Date.isSelected(); j++) {
for (; i <= 20 || Date.isSelected(); i++) {
if (i == 11) {
i++;
}
a = Integer.toString(i);
b = Integer.toString(j);
Thread.sleep(1000);
DateString = ".//*[@id='choose-date']/div[2]/div/table/tbody/tr[" + a + "]/td[" + b + "]/div/div";
Thread.sleep(200);
Date = driver.findElement(By.xpath(DateString));
Thread.sleep(500);
DateText = Date.getText();
System.out.println(DateText);
if (DateText == "-" || DateText == "×") {
} else {
Date.click();
}
i = Integer.parseInt(a);
j = Integer.parseInt(b);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment