Advertisement
smaction

IEROOM

Sep 12th, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.25 KB | None | 0 0
  1. package test;
  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.NoSuchElementException;
  18. import org.openqa.selenium.WebDriver;
  19. import org.openqa.selenium.ie.InternetExplorerDriver;
  20.  
  21. public class Roomldl2IE {
  22.     static String[][] post_vars;
  23.     private static int post_var_count;
  24.     private static WebDriver driver;
  25.     private static String baseUrl="http://www.ldlcasino.com";
  26.     private static StringBuffer verificationErrors = new StringBuffer();
  27.     public static void main(String[] args) throws IOException, InterruptedException {
  28.         post_vars = new String[255][255];
  29.         driver = new InternetExplorerDriver();
  30.     driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  31.    
  32.  
  33.    
  34.    
  35.         // ERROR: Caught exception [ERROR: Unsupported command [setSpeed]]
  36.         addMessage("Site","LDL Production");
  37.         addMessage("URL",baseUrl);
  38.         driver.get(baseUrl);
  39.    
  40.         Thread.sleep(30000);
  41.         //System.out.println(isElementPresent(By.id("close_welcome_box")));
  42.         if (isElementPresent(By.id("close_welcome_box")))driver.findElement(By.id("close_welcome_box")).click();
  43.        
  44.  
  45.         driver.findElement(By.id("dashTabOverlay")).click();
  46.         Thread.sleep(30000);
  47.         if (isElementPresent(By.id("obRoom"))){driver.findElement(By.id("obRoom")).click();}
  48.            
  49.         Thread.sleep(30000);
  50.        
  51.         if (isElementPresent(By.xpath("//form[@id='roomsStep1']/div[7]"))){driver.findElement(By.xpath("//form[@id='roomsStep1']/div[7]")).click();}
  52.        
  53.         // ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]] By.VisibleText might be wrong
  54.        
  55.              
  56.              if (isElementPresent(By.cssSelector("span.dashboardprice"))){addMessage("ldlroomIE","success");}else{addMessage("ldlroomIE ", "FAIL");}
  57.        
  58.    
  59.        
  60.         driver.quit();
  61.         http_post();
  62.         String verificationErrorString = verificationErrors.toString();
  63.         if (!"".equals(verificationErrorString)) {
  64.        
  65.             fail(verificationErrorString);
  66.         }
  67.     }
  68.  
  69.     private static boolean isElementPresent(By by) {
  70.         try {
  71.             driver.findElement(by);
  72.             return true;
  73.         } catch (NoSuchElementException e) {
  74.             return false;
  75.         }
  76.     }
  77.     public static void http_post() throws IOException{
  78.        
  79.         // Construct data
  80.         String data = "";
  81.         for(int n=0; n <=post_vars.length-1; n++){
  82.             if( post_vars[n][0] != null){
  83.                 data += post_vars[n][0] + "="  + post_vars[n][1] +  "&";
  84.             }
  85.         }
  86.         // Send data
  87.         URL url = new URL("http://logs.skg-i.com/UnitTest.php");
  88.         URLConnection conn = url.openConnection();
  89.         conn.setDoOutput(true);
  90.         OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  91.         wr.write(data);
  92.         wr.flush();
  93.        
  94.         // Get the response
  95.         BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  96.         String line;
  97.         while ((line = rd.readLine()) != null) {
  98.             System.out.println(line);
  99.         }
  100.         wr.close();
  101.         rd.close();
  102.    
  103. }
  104. public static void addMessage(String key, String value){
  105.        
  106.         post_vars[post_var_count][0] = key;
  107.         post_vars[post_var_count][1] = value;      
  108.         post_var_count++;
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement