Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package BLT;
- import static org.junit.Assert.fail;
- 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.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.JavascriptExecutor;
- import org.openqa.selenium.NoSuchElementException;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.support.ui.ExpectedCondition;
- import org.openqa.selenium.support.ui.Select;
- import org.openqa.selenium.support.ui.WebDriverWait;
- public class Roomblt {
- static String[][] post_vars;
- private static int post_var_count;
- private static WebDriver driver;
- private static String baseUrl="http://latest-belterracasino.skgcom.com/";
- private static StringBuffer verificationErrors = new StringBuffer();
- public static void main(String[] args) throws IOException, InterruptedException {
- post_vars = new String[255][255];
- driver = new FirefoxDriver();
- // String baseUrl=args[0];
- // String testSite=args[1];
- String testSite="BLT Tiny";
- driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
- // ERROR: Caught exception [ERROR: Unsupported command [setSpeed]]
- addMessage("Site",testSite);
- addMessage("URL",baseUrl);
- addMessage("bltRoom","started...");
- http_post();
- post_vars[2][0] = null;
- post_vars[2][1] = null;
- driver.get(baseUrl);
- //Thread.sleep(30000);
- //System.out.println(isElementPresent(By.id("close_welcome_box")));
- waitForElementVisible(driver, By.id("close_welcome_box")).click();
- // 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();
- waitForElementVisible(driver, By.cssSelector("button.button_large_white.dashboard_button_padding")).click();
- waitForElementVisible(driver, By.name("name0")).click();
- /*WebElement el = waitForElementVisible(driver, By.linkText("No thank you, continue with original selection"));
- el.click();
- Thread.sleep(2000);
- if (el.isDisplayed()) {
- el.findElement(By.xpath("..")).click();
- }*/
- /* while ((Long)((JavascriptExecutor)driver).executeScript("return animationQueue;") == 0) {
- (
- (JavascriptExecutor)driver).executeScript(" alert('skip upgrade');");
- }
- */
- Thread.sleep(10000);
- ((JavascriptExecutor)driver).executeScript(" $('.skipupgrade').click();");
- Thread.sleep(15000);
- 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();
- // 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();
- driver.findElement(By.cssSelector("div.payment_info_left.credit_comments_panel > button.button_medium_white.dashboard_button_padding")).click();
- Thread.sleep(30000);
- if (isElementPresent(By.xpath("//*[contains(.,'" + "Congratulations!" + "')]"))){addMessage("bltRoom","success");}else{addMessage("bltRoom", "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