Last active
May 25, 2016 05:04
-
-
Save nhatthuyld/8384371d56ae06f03867627a7d111a61 to your computer and use it in GitHub Desktop.
oh my got! it is half day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.NoAlertPresentException; | |
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.ExpectedConditions; | |
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); | |
* | |
* } | |
*/ | |
public boolean AssertDate() throws InterruptedException { | |
try { | |
Alert alertDate = driver.switchTo().alert(); | |
alertDate.accept(); | |
System.out.println("true"); | |
return true; | |
} catch (NoAlertPresentException Ex) { | |
System.out.println("false"); | |
return false; | |
} | |
} | |
@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(1000); | |
// click place | |
driver.findElement(By.xpath(".//*[@id='choose-shop']/li[2]/label")).click(); | |
Thread.sleep(3000); | |
// choose random date | |
WebElement DE = driver.findElement(By.xpath(".//*[@id='choose-date']/div[2]/div/table/tbody/tr[1]/td[1]")); | |
DE.click(); | |
Thread.sleep(500); | |
String a, b, DateString, DateText; | |
for (Integer j = 1; !DE.isSelected(); j++) { | |
for (Integer i = 1;i<=20 && !DE.isSelected(); i++) { | |
if (i == 11) { | |
i++; | |
} | |
System.out.println("i= "+i); | |
a = Integer.toString(i); | |
b = Integer.toString(j); | |
DateString = ".//*[@id='choose-date']/div[2]/div/table/tbody/tr[" + a + "]/td[" + b + "]/div/div"; | |
DE = driver.findElement(By.xpath(DateString)); | |
DateText = DE.getText(); | |
if (DateText.equals("-") || DateText.equals("×") || DateText.equals("☎")) { | |
} else { | |
DE.click(); | |
Thread.sleep(200); | |
if(!AssertDate()) { | |
Thread.sleep(200); | |
return;} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very good ! I like it . Thank u so much