Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.skgcom.unitTests;
- import static org.testng.Assert.*;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.concurrent.TimeUnit;
- import org.openqa.selenium.By;
- import org.openqa.selenium.Dimension;
- import org.openqa.selenium.JavascriptExecutor;
- import org.openqa.selenium.NoSuchElementException;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.remote.DesiredCapabilities;
- import org.openqa.selenium.remote.RemoteWebDriver;
- import org.openqa.selenium.support.ui.ExpectedCondition;
- import org.openqa.selenium.support.ui.Select;
- import org.openqa.selenium.support.ui.WebDriverWait;
- import org.testng.annotations.Test;
- public class roomTest {
- static String[][] post_vars;
- private static int post_var_count;
- private static WebDriver driver;
- //String agent = "FF";
- String agent = System.getProperty("agent").trim();
- private static StringBuffer verificationErrors = new StringBuffer();
- @Test(groups = "unit")
- public void resTest() throws IOException, InterruptedException {
- post_vars = new String[255][255];
- String baseUrl = System.getProperty("url");
- String testSite = System.getProperty("site");
- //String agent = System.getProperty("agent");
- if (agent.equals("IE")) {
- //System.out.println(agent);
- driver = new RemoteWebDriver(
- new URL("http://localhost:4444/wd/hub"),
- DesiredCapabilities.internetExplorer());
- }
- if (agent.equals("FF")) {
- driver = new RemoteWebDriver(
- new URL("http://localhost:4444/wd/hub"),
- DesiredCapabilities.firefox());
- }
- driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
- addMessage("Site", testSite);
- addMessage("URL", baseUrl);
- addMessage("Room", "started...");
- http_post();
- post_vars[2][0] = null;
- post_vars[2][1] = null;
- driver.get(baseUrl);
- waitForElementVisible(driver, By.id("close_welcome_box")).click();
- driver.manage().window().setSize(new Dimension(1024, 762));
- // waitForElementVisible(driver, By.id("dashTabOverlay")).click();
- while ((Long) ((JavascriptExecutor) driver)
- .executeScript("return animationQueue;") == 0) {
- ((JavascriptExecutor) driver)
- .executeScript("window.dashboardApp.behaviors.toggle();");
- }
- waitForElementVisible(driver, By.id("obRoom")).click();
- if (isElementPresent(By.xpath("//form[@id='roomsStep1']/div[7]"))) {
- driver.findElement(By.xpath("//form[@id='roomsStep1']/div[7]"))
- .click();
- }
- if (isElementPresent(By
- .cssSelector("button.button_large_white.dashboard_button_padding"))) {
- driver.findElement(
- By.cssSelector("button.button_large_white.dashboard_button_padding"))
- .click();
- }
- waitForElementVisible(driver, By.name("name0")).click();
- if (isElementPresent(By
- .linkText("No thank you, continue with original selection"))) {
- driver.findElement(
- By.linkText("No thank you, continue with original selection"))
- .click();
- }
- Thread.sleep(10000);
- if (isElementPresent(By.id("firstname"))) {
- } else {
- ((JavascriptExecutor) driver)
- .executeScript("(function(self) { echo('click');"
- + "var data = 'cart=' + $(self).data('cart') + '&checkin=' + $(self).data('checkin')"
- + "+ '&checkout=' + $(self).data('checkout') + '&adults=' + $(self).data('adults');"
- + "var $form = $('form#roomsStep2'); dashboardApp.openPanel('/dashboard/cart?type=room&template=cart&' + data,'',1,'single', function(){"
- + "dashboardApp.openPanel('/dashboard/rooms/billing',$form.serialize(),2,'triple',window.loadTotals);"
- + "});isBooking = true;$(self).unmodal(); })($('.skipupgrade'));");
- Thread.sleep(15000);
- }
- // ((JavascriptExecutor)driver).executeScript(" $('.selectRoomOption').click();");
- // waitForElementVisible(driver, By.id("acceptUpsell")).click();
- driver.findElement(By.id("firstname")).clear();
- driver.findElement(By.id("firstname")).sendKeys("Scott");
- driver.findElement(By.id("lastname")).clear();
- driver.findElement(By.id("lastname")).sendKeys("Miller");
- driver.findElement(By.id("email1")).clear();
- driver.findElement(By.id("email1")).sendKeys("scott.miller@skgadv.com");
- driver.findElement(By.id("email2")).clear();
- driver.findElement(By.id("email2")).sendKeys("scott.miller@skgadv.com");
- driver.findElement(By.id("phone")).clear();
- driver.findElement(By.id("phone")).sendKeys("7024600705");
- driver.findElement(By.id("address")).clear();
- driver.findElement(By.id("address")).sendKeys("3491 Sego Glen");
- driver.findElement(By.id("city")).clear();
- driver.findElement(By.id("city")).sendKeys("Las Vegas");
- driver.findElement(By.id("state")).clear();
- driver.findElement(By.id("state")).sendKeys("NV");
- driver.findElement(By.id("payZip")).clear();
- driver.findElement(By.id("payZip")).sendKeys("89121");
- driver.findElement(By.id("creditcardfield")).clear();
- driver.findElement(By.id("creditcardfield")).sendKeys(
- "4111111111111111");
- //driver.findElement(By.name("LRESYC")).click();
- driver.findElement(By.name("LRESYC")).sendKeys("22");
- // ERROR: Caught exception [ERROR: Unsupported command [select]]
- /*if (isElementPresent(By.name("LRESYC"))) {
- Select select = new Select(driver.findElement(By.name("LRESYC")));
- select.selectByVisibleText("2015");
- }*/
- driver.findElement(By.id("tccheck")).click();
- if (isElementPresent(By
- .cssSelector("div.submitReservation.simpleSprite"))) {
- driver.findElement(
- By.cssSelector("div.submitReservation.simpleSprite"))
- .click();
- }
- if (isElementPresent(By.id("roomSubmitBtn"))) {
- // System.out.format("I am executing the right code.");
- driver.findElement(By.id("roomSubmitBtn")).click();
- }
- Thread.sleep(30000);
- if (isElementPresent(By.xpath("//*[contains(.,'" + "Congratulations!"
- + "')]"))) {
- addMessage("Room", "success");
- } else {
- if (isElementPresent(By.xpath("//*[contains(.,'" + "successful"
- + "')]"))) {
- addMessage("Room", "success");
- } else {
- addMessage("Room", "FAIL");
- }
- }
- driver.quit();
- http_post();
- String verificationErrorString = verificationErrors.toString();
- if (!"".equals(verificationErrorString)) {
- fail(verificationErrorString);
- }
- }
- @Test(groups = "unit")
- public void golfTest() throws IOException, InterruptedException {
- post_vars = new String[255][255];
- String baseUrl = System.getProperty("url");
- String testSite = System.getProperty("site");
- // String agent = System.getProperty("agent");
- if (agent.equals("FF")) {
- driver = new RemoteWebDriver(
- new URL("http://localhost:4444/wd/hub"),
- DesiredCapabilities.firefox());
- }
- if (agent.equals("IE")) {
- driver = new RemoteWebDriver(
- new URL("http://localhost:4444/wd/hub"),
- DesiredCapabilities.internetExplorer());
- }
- driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
- // ERROR: Caught exception [ERROR: Unsupported command [setSpeed]]
- addMessage("Site", testSite);
- addMessage("URL", baseUrl);
- addMessage("Golf", "started...");
- http_post();
- post_vars[2][0] = null;
- post_vars[2][1] = null;
- driver.get(baseUrl);
- driver.manage().window().setSize(new Dimension(1024, 762));
- // Thread.sleep(30000);
- // System.out.println(isElementPresent(By.id("close_welcome_box")));
- if (isElementPresent(By.id("close_welcome_box")))
- driver.findElement(By.id("close_welcome_box")).click();
- Thread.sleep(15000);
- driver.findElement(By.id("dashTabOverlay")).click();
- // Thread.sleep(30000);
- if (isElementPresent(By.id("obGolf"))) {
- driver.findElement(By.id("obGolf")).click();
- }
- // Thread.sleep(30000);
- if (isElementPresent(By.id("time"))) {
- Select select = new Select(driver.findElement(By.id("time")));
- select.selectByVisibleText("12:00PM");
- }
- if (isElementPresent(By.id("checkAvailability"))) {
- driver.findElement(By.id("checkAvailability")).click();
- }
- // Thread.sleep(30000);
- // if
- // (isElementPresent(By.id("booking_0"))){addMessage("bltgolf","success");}else{addMessage("bltgolf",
- // "FAIL");}
- if (isElementPresent(By.id("booking_0"))) {
- driver.findElement(By.id("booking_0")).click();
- }
- // Thread.sleep(30000);
- driver.findElement(By.id("firstname")).click();
- driver.findElement(By.id("firstname")).clear();
- driver.findElement(By.id("firstname")).sendKeys("Scott");
- driver.findElement(By.id("lastname")).clear();
- driver.findElement(By.id("lastname")).sendKeys("Miller");
- driver.findElement(By.id("email")).clear();
- driver.findElement(By.id("email")).sendKeys("scott.miller@skgadv.com");
- driver.findElement(By.id("confirm_email")).clear();
- driver.findElement(By.id("confirm_email")).sendKeys(
- "scott.miller@skgadv.com");
- driver.findElement(By.id("phone")).clear();
- driver.findElement(By.id("phone")).sendKeys("7024600705");
- driver.findElement(By.id("address")).clear();
- driver.findElement(By.id("address")).sendKeys("3491 Sego Glen Circ");
- driver.findElement(By.id("city")).clear();
- driver.findElement(By.id("city")).sendKeys("Las Vegas");
- driver.findElement(By.id("state")).clear();
- driver.findElement(By.id("state")).sendKeys("NV");
- driver.findElement(By.id("zip")).clear();
- driver.findElement(By.id("zip")).sendKeys("89121");
- driver.findElement(By.id("antibot_answer")).clear();
- driver.findElement(By.id("antibot_answer")).sendKeys("c@ptch@oVeRride");
- driver.findElement(By.id("submit_reservation")).click();
- // Thread.sleep(30000);
- if (isElementPresent(By.xpath("//*[contains(.,'" + "Congratulations!"
- + "')]"))) {
- addMessage("Golf", "success");
- } else {
- if (isElementPresent(By.xpath("//*[contains(.,'" + "successful"
- + "')]"))) {
- addMessage("Golf", "success");
- } else {
- addMessage("Golf", "FAIL");
- }
- }
- driver.quit();
- http_post();
- String verificationErrorString = verificationErrors.toString();
- if (!"".equals(verificationErrorString)) {
- fail(verificationErrorString);
- }
- }
- @Test(groups = "unit")
- public void gaTest() throws IOException, InterruptedException {
- post_vars = new String[255][255];
- String baseUrl = System.getProperty("url");
- String testSite = System.getProperty("site");
- // String agent = System.getProperty("agent");
- if (agent.equals("FF")) {
- driver = new RemoteWebDriver(
- new URL("http://localhost:4444/wd/hub"),
- DesiredCapabilities.firefox());
- }
- if (agent.equals("IE")) {
- driver = new RemoteWebDriver(
- new URL("http://localhost:4444/wd/hub"),
- DesiredCapabilities.internetExplorer());
- }
- driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
- // ERROR: Caught exception [ERROR: Unsupported command [setSpeed]]
- addMessage("Site", testSite);
- addMessage("URL", baseUrl);
- addMessage("GA", "started...");
- http_post();
- post_vars[2][0] = null;
- post_vars[2][1] = null;
- driver.get(baseUrl);
- driver.manage().window().setSize(new Dimension(1024, 762));
- // Thread.sleep(30000);
- // System.out.println(isElementPresent(By.id("close_welcome_box")));
- if (isElementPresent(By.xpath("//*[contains(.,'"
- + "google-analytics.com/ga.js" + "')]"))) {
- addMessage("GA", "success");
- } else {
- addMessage("GA", "FAIL");
- }
- driver.quit();
- http_post();
- String verificationErrorString = verificationErrors.toString();
- if (!"".equals(verificationErrorString)) {
- fail(verificationErrorString);
- }
- }
- @Test(groups = "unit")
- public void spaTest() throws IOException, InterruptedException {
- post_vars = new String[255][255];
- String baseUrl = System.getProperty("url");
- String testSite = System.getProperty("site");
- // String agent = System.getProperty("agent");
- if (agent.equals("FF")) {
- driver = new RemoteWebDriver(
- new URL("http://localhost:4444/wd/hub"),
- DesiredCapabilities.firefox());
- }
- if (agent.equals("IE")) {
- driver = new RemoteWebDriver(
- new URL("http://localhost:4444/wd/hub"),
- DesiredCapabilities.internetExplorer());
- }
- driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
- // ERROR: Caught exception [ERROR: Unsupported command [setSpeed]]
- addMessage("Site", testSite);
- addMessage("URL", baseUrl);
- addMessage("Spa", "started...");
- http_post();
- post_vars[2][0] = null;
- post_vars[2][1] = null;
- driver.get(baseUrl);
- driver.manage().window().setSize(new Dimension(1024, 762));
- // Thread.sleep(30000);
- // System.out.println(isElementPresent(By.id("close_welcome_box")));
- if (isElementPresent(By.id("close_welcome_box")))
- driver.findElement(By.id("close_welcome_box")).click();
- Thread.sleep(15000);
- driver.findElement(By.id("dashTabOverlay")).click();
- // Thread.sleep(30000);
- if (isElementPresent(By.id("obSpa"))) {
- driver.findElement(By.id("obSpa")).click();
- }
- // Thread.sleep(30000);
- // if
- // (isElementPresent(By.xpath(".//*[@id='category']/option[6]"))){addMessage("bltspa","success");}else{addMessage("bltspa",
- // "FAIL");}
- // ERROR: Caught exception [ERROR: Unsupported command [select]]
- if (isElementPresent(By.id("category")))
- driver.findElement(By.id("category")).click();
- driver.findElement(By.id("category")).sendKeys("h");
- driver.findElement(By.id("num_of_people")).click();
- // driver.findElement(By.id("time")).click();
- Thread.sleep(15000);
- // ERROR: Caught exception [ERROR: Unsupported command [select]]
- if (isElementPresent(By.id("subcategory")))
- driver.findElement(By.id("subcategory")).click();
- driver.findElement(By.id("subcategory")).sendKeys("m");
- driver.findElement(By.id("num_of_people")).click();
- // driver.findElement(By.id("time")).click();
- Thread.sleep(15000);
- // ERROR: Caught exception [ERROR: Unsupported command [select]]
- if (isElementPresent(By.id("time"))) {
- Select select = new Select(driver.findElement(By.id("time")));
- select.selectByVisibleText("9am - 12pm");
- }
- driver.findElement(By.id("createSpaReservation")).click();
- // Thread.sleep(30000);
- driver.findElement(By.id("spa_firstname")).click();
- driver.findElement(By.id("spa_firstname")).clear();
- driver.findElement(By.id("spa_firstname")).sendKeys("Scott");
- driver.findElement(By.id("spa_lastname")).clear();
- driver.findElement(By.id("spa_lastname")).sendKeys("Miller");
- driver.findElement(By.id("spa_email")).clear();
- driver.findElement(By.id("spa_email")).sendKeys(
- "scott.miller@skgadv.com");
- driver.findElement(By.id("spa_confirm_email")).clear();
- driver.findElement(By.id("spa_confirm_email")).sendKeys(
- "scott.miller@skgadv.com");
- driver.findElement(By.id("spa_phone")).clear();
- driver.findElement(By.id("spa_phone")).sendKeys("7024600705");
- driver.findElement(By.id("spa_address")).clear();
- driver.findElement(By.id("spa_address")).sendKeys("3491 Sego Glen");
- driver.findElement(By.id("spa_city")).clear();
- driver.findElement(By.id("spa_city")).sendKeys("Las Vegas");
- driver.findElement(By.id("spa_state")).clear();
- driver.findElement(By.id("spa_state")).sendKeys("NV");
- driver.findElement(By.id("spa_zip")).clear();
- driver.findElement(By.id("spa_zip")).sendKeys("89121");
- driver.findElement(By.id("spa_comments")).clear();
- driver.findElement(By.id("spa_comments")).sendKeys("test");
- driver.findElement(By.id("antibot_answer")).clear();
- driver.findElement(By.id("antibot_answer")).sendKeys("c@ptch@oVeRride");
- driver.findElement(By.id("submit_spa_request")).click();
- // Thread.sleep(30000);
- if (isElementPresent(By.xpath("//*[contains(.,'"
- + "Thank you for requesting a spa treatment." + "')]"))) {
- addMessage("Spa", "success");
- } else {
- addMessage("Spa", "FAIL");
- }
- driver.quit();
- http_post();
- String verificationErrorString = verificationErrors.toString();
- if (!"".equals(verificationErrorString)) {
- fail(verificationErrorString);
- }
- }
- private static boolean isElementPresent(By by) {
- try {
- driver.findElement(by);
- return true;
- } catch (NoSuchElementException e) {
- return false;
- }
- }
- public static void http_post() throws IOException {
- // Construct data
- String data = "";
- for (int n = 0; n <= post_vars.length - 1; n++) {
- if (post_vars[n][0] != null) {
- data += post_vars[n][0] + "=" + post_vars[n][1] + "&";
- }
- }
- // Send data
- URL url = new URL("http://logs.skgcom.com/UnitTest.php");
- ;
- URLConnection conn = url.openConnection();
- conn.setDoOutput(true);
- OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
- wr.write(data);
- wr.flush();
- // Get the response
- BufferedReader rd = new BufferedReader(new InputStreamReader(
- conn.getInputStream()));
- String line;
- while ((line = rd.readLine()) != null) {
- System.out.println(line);
- }
- wr.close();
- rd.close();
- }
- public static void addMessage(String key, String value) {
- post_vars[post_var_count][0] = key;
- post_vars[post_var_count][1] = value;
- post_var_count++;
- }
- private static WebElement waitForElementVisible(WebDriver driver,
- final By by) {
- return (new WebDriverWait(driver, 60))
- .until(new ExpectedCondition<WebElement>() {
- @Override
- public WebElement apply(WebDriver d) {
- WebElement el = d.findElement(by);
- if (el != null && el.isDisplayed()) {
- return el;
- }
- return null;
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement