Advertisement
smaction

Belterra Room

Oct 11th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.13 KB | None | 0 0
  1. package BLT;
  2.  
  3. import static org.junit.Assert.fail;
  4.  
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStreamWriter;
  9. import java.net.URL;
  10. import java.net.URLConnection;
  11. import java.util.concurrent.TimeUnit;
  12.  
  13. import org.junit.After;
  14. import org.junit.Before;
  15. import org.junit.Test;
  16. import org.openqa.selenium.By;
  17. import org.openqa.selenium.JavascriptExecutor;
  18. import org.openqa.selenium.NoSuchElementException;
  19. import org.openqa.selenium.WebDriver;
  20. import org.openqa.selenium.WebElement;
  21. import org.openqa.selenium.firefox.FirefoxDriver;
  22. import org.openqa.selenium.support.ui.ExpectedCondition;
  23. import org.openqa.selenium.support.ui.Select;
  24. import org.openqa.selenium.support.ui.WebDriverWait;
  25.  
  26. public class Roomblt {
  27.     static String[][] post_vars;
  28.     private static int post_var_count;
  29.     private static WebDriver driver;
  30.     private static String baseUrl="http://latest-belterracasino.skgcom.com/";
  31.     private static StringBuffer verificationErrors = new StringBuffer();
  32.     public static void main(String[] args) throws IOException, InterruptedException {
  33.         post_vars = new String[255][255];
  34.         driver = new FirefoxDriver();
  35.     //  String baseUrl=args[0];
  36.     //  String testSite=args[1];
  37.         String testSite="BLT Tiny";
  38.     driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
  39.    
  40.  
  41.    
  42.    
  43.         // ERROR: Caught exception [ERROR: Unsupported command [setSpeed]]
  44.         addMessage("Site",testSite);
  45.         addMessage("URL",baseUrl);
  46.         addMessage("bltRoom","started...");
  47.         http_post();
  48.         post_vars[2][0] = null;
  49.         post_vars[2][1] = null;
  50.         driver.get(baseUrl);
  51.    
  52.         //Thread.sleep(30000);
  53.         //System.out.println(isElementPresent(By.id("close_welcome_box")));
  54.         waitForElementVisible(driver, By.id("close_welcome_box")).click();
  55.  
  56.         // waitForElementVisible(driver, By.id("dashTabOverlay")).click();
  57.         while ((Long)((JavascriptExecutor)driver).executeScript("return animationQueue;") == 0) {
  58.         ((JavascriptExecutor)driver).executeScript("window.dashboardApp.behaviors.toggle();");
  59.         }
  60.  
  61.         waitForElementVisible(driver, By.id("obRoom")).click();
  62.         waitForElementVisible(driver, By.cssSelector("button.button_large_white.dashboard_button_padding")).click();
  63.  
  64.         waitForElementVisible(driver, By.name("name0")).click();
  65.  
  66.         /*WebElement el = waitForElementVisible(driver, By.linkText("No thank you, continue with original selection"));
  67.         el.click();
  68.         Thread.sleep(2000);
  69.         if (el.isDisplayed()) {
  70.         el.findElement(By.xpath("..")).click();
  71.         }*/
  72. /*      while ((Long)((JavascriptExecutor)driver).executeScript("return animationQueue;") == 0) {
  73.             (
  74.             (JavascriptExecutor)driver).executeScript(" alert('skip upgrade');");
  75.             }
  76.     */
  77.         Thread.sleep(10000);
  78.         ((JavascriptExecutor)driver).executeScript(" $('.skipupgrade').click();");
  79.         Thread.sleep(15000);
  80.         driver.findElement(By.id("firstname")).clear();
  81.         driver.findElement(By.id("firstname")).sendKeys("Scott");
  82.         driver.findElement(By.id("lastname")).clear();
  83.         driver.findElement(By.id("lastname")).sendKeys("Miller");
  84.         driver.findElement(By.id("email1")).clear();
  85.         driver.findElement(By.id("email1")).sendKeys("scott.miller@skgadv.com");
  86.         driver.findElement(By.id("email2")).clear();
  87.         driver.findElement(By.id("email2")).sendKeys("scott.miller@skgadv.com");
  88.         driver.findElement(By.id("phone")).clear();
  89.         driver.findElement(By.id("phone")).sendKeys("7024600705");
  90.         driver.findElement(By.id("address")).clear();
  91.         driver.findElement(By.id("address")).sendKeys("3491 Sego Glen");
  92.         driver.findElement(By.id("city")).clear();
  93.         driver.findElement(By.id("city")).sendKeys("Las Vegas");
  94.         driver.findElement(By.id("state")).clear();
  95.         driver.findElement(By.id("state")).sendKeys("NV");
  96.         driver.findElement(By.id("payZip")).clear();
  97.         driver.findElement(By.id("payZip")).sendKeys("89121");
  98.         driver.findElement(By.id("creditcardfield")).clear();
  99.         driver.findElement(By.id("creditcardfield")).sendKeys("4111111111111111");
  100.         driver.findElement(By.name("LRESYC")).click();
  101.         // ERROR: Caught exception [ERROR: Unsupported command [select]]
  102.         if (isElementPresent(By.name("LRESYC"))){Select select= new Select(driver.findElement(By.name("LRESYC")));select.selectByVisibleText("2015");}
  103.         driver.findElement(By.id("tccheck")).click();
  104.        
  105.         driver.findElement(By.cssSelector("div.payment_info_left.credit_comments_panel > button.button_medium_white.dashboard_button_padding")).click();
  106.         Thread.sleep(30000);
  107.         if (isElementPresent(By.xpath("//*[contains(.,'" + "Congratulations!" + "')]"))){addMessage("bltRoom","success");}else{addMessage("bltRoom", "FAIL");}
  108.        
  109.         driver.quit();
  110.         http_post();
  111.         String verificationErrorString = verificationErrors.toString();
  112.         if (!"".equals(verificationErrorString)) {
  113.        
  114.             fail(verificationErrorString);
  115.         }
  116.     }
  117.  
  118.     private static boolean isElementPresent(By by) {
  119.         try {
  120.             driver.findElement(by);
  121.             return true;
  122.         } catch (NoSuchElementException e) {
  123.             return false;
  124.         }
  125.     }
  126.     public static void http_post() throws IOException{
  127.        
  128.         // Construct data
  129.         String data = "";
  130.         for(int n=0; n <=post_vars.length-1; n++){
  131.             if( post_vars[n][0] != null){
  132.                 data += post_vars[n][0] + "="  + post_vars[n][1] +  "&";
  133.             }
  134.         }
  135.         // Send data
  136.         URL url = new URL("http://logs.skgcom.com/UnitTest.php");;
  137.         URLConnection conn = url.openConnection();
  138.         conn.setDoOutput(true);
  139.         OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  140.         wr.write(data);
  141.         wr.flush();
  142.        
  143.         // Get the response
  144.         BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  145.         String line;
  146.         while ((line = rd.readLine()) != null) {
  147.             System.out.println(line);
  148.         }
  149.         wr.close();
  150.         rd.close();
  151.    
  152. }
  153. public static void addMessage(String key, String value){
  154.        
  155.         post_vars[post_var_count][0] = key;
  156.         post_vars[post_var_count][1] = value;      
  157.         post_var_count++;
  158.     }
  159. private static WebElement waitForElementVisible(WebDriver driver, final By by) {
  160.     return (new WebDriverWait(driver, 60)).until(new ExpectedCondition<WebElement>(){
  161. @Override
  162. public WebElement apply(WebDriver d) {
  163. WebElement el = d.findElement(by);
  164. if (el != null && el.isDisplayed()) {
  165. return el;
  166. }
  167. return null;
  168. }});
  169.    }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement