Created
May 25, 2016 10:34
-
-
Save nhatthuyld/dd6371998318b4608d0fda5fe209ac59 to your computer and use it in GitHub Desktop.
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(); | |
return true; | |
} catch (NoAlertPresentException Ex) { | |
return false; | |
} | |
} | |
@Test | |
public void fisrtSelectBox() throws InterruptedException { | |
WebElement checkBoxElement = driver.findElement(By.id("list_plans_1SelectBoxItContainer")); | |
checkBoxElement.click(); | |
Thread.sleep(200); | |
// select people | |
SeLectNumberPerson(19); | |
// click next button | |
ClickButton(".//*[@id='formAddPlan']/div[1]/div/ul/li[1]/div[3]/div[2]/div[1]/a"); | |
Thread.sleep(800); | |
// click place and date | |
SeLectShopAndDate("osaka"); | |
} | |
// click date in present table | |
public Boolean ChooseRanDomDateOneTable(Integer row) throws InterruptedException { | |
WebElement DE,DateOfWeek; | |
String a, b, DateString, DateText; | |
for (Integer j = 1;; j++) { | |
for (Integer i = 1; i <= row; i++) { | |
DateOfWeek = driver.findElement(By.xpath(".//*[@id='choose-date']/div[2]/div/table/tbody/tr[@class='thead']")); | |
//thay cho nay la tim .//*[@id='choose-date']/div[2]/div/table/tbody/tr[@class='thead'] | |
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("☎") || AssertDate()) { | |
Thread.sleep(200); | |
} else { | |
DE.click(); | |
Thread.sleep(200); | |
return true; | |
} | |
} | |
} | |
} | |
// Click another week if have not select a date whole table | |
public void ChooseRanDomDate(Integer row) throws InterruptedException { | |
while (!ChooseRanDomDateOneTable(row)) { | |
ClickButton(".//*[@id='page-next']"); | |
Thread.sleep(700); | |
ChooseRanDomDateOneTable(row); | |
} | |
} | |
public void ClickButton(String idButton) throws InterruptedException { | |
WebElement itemElement = driver.findElement(By.xpath(idButton)); | |
itemElement.click(); | |
} | |
public void SeLectNumberPerson(Integer number) throws InterruptedException { | |
number++; | |
ClickButton(".//*[@id='list_plans_1SelectBoxItOptions']/li[" + Integer.toString(number) + "]/a/span[2]"); | |
Thread.sleep(500); | |
} | |
public void SeLectShop(String shopname) throws InterruptedException { | |
if (shopname.equals("kyoto")) | |
ClickButton(".//*[@id='choose-shop']/li[1]/label[@for='id-5-down']"); | |
else if (shopname.equals("gionshijo")) | |
ClickButton(".//*[@id='choose-shop']/li[2]/label[@for='id-6-down']"); | |
else if (shopname.equals("shinkyogoku")) | |
ClickButton(".//*[@id='choose-shop']/li[1]/label[@for='id-1-down']"); | |
else if (shopname.equals("kiyomizuzaka")) | |
ClickButton(".//*[@id='choose-shop']/li[2]/label[@for='id-2-down']"); | |
else if (shopname.equals("kinkakuji")) | |
ClickButton(".//*[@id='choose-shop']/li[3]/label[@for='id-4-down']"); | |
else if (shopname.equals("osaka")) | |
ClickButton(".//*[@id='choose-shop']/li[1]/label[@for='id-7-down']"); | |
else if (shopname.equals("tokyo")) | |
ClickButton(".//*[@id='choose-shop']/li[2]/label[@for='id-8-down']"); | |
else if (shopname.equals("kamakura")) | |
ClickButton(".//*[@id='choose-shop']/li[3]/label[@for='id-9-down']"); | |
Thread.sleep(2200); | |
} | |
public void SeLectShopAndDate(String shopname) throws InterruptedException { | |
SeLectShop(shopname); | |
Thread.sleep(1000); | |
if (shopname.equals("kyoto") || shopname.equals("gionshijo")) | |
ChooseRanDomDate(20); | |
else if (shopname.equals("shinkyogoku") || shopname.equals("kiyomizuzaka") || shopname.equals("tokyo") | |
|| shopname.equals("kamakura")) | |
ChooseRanDomDate(18); | |
else if (shopname.equals("kinkakuji")) | |
ChooseRanDomDate(16); | |
else if (shopname.equals("osaka")) { | |
ChooseRanDomDate(21); | |
System.out.println("vo day "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment