Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.skgcom.tutorial;
- 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.NoSuchElementException;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.remote.DesiredCapabilities;
- import org.openqa.selenium.remote.RemoteWebDriver;
- //import org.openqa.selenium.ie.InternetExplorerDriver;
- import org.testng.annotations.Test;
- public class galdl1Test {
- static String[][] post_vars;
- private static int post_var_count;
- private static WebDriver driver;
- private static StringBuffer verificationErrors = new StringBuffer();
- @Test(groups = "unit")
- public void betaTest() throws IOException {
- post_vars = new String[255][255];
- driver = new RemoteWebDriver(new URL("http://locahost:4444/wd/hub"),
- DesiredCapabilities.firefox());
- // driver = new InternetExplorerDriver();
- String baseUrl = System.getProperty("url");
- // String baseUrl = System.getenv("url");
- String testSite = System.getProperty("site");
- // String testSite = System.getenv("site");
- // System.out.format("%s=%s%n", "urlvar", System.getenv("url"));
- // System.out.format("%s=%s%n", "url", baseUrl);
- driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
- // ERROR: Caught exception [ERROR: Unsupported command [setSpeed]]
- addMessage("Site", testSite);
- addMessage("URL", baseUrl);
- addMessage("ldlGA", "started...");
- http_post();
- post_vars[2][0] = null;
- post_vars[2][1] = null;
- driver.get(baseUrl + "/hotel/");
- // Thread.sleep(30000);
- // System.out.println(isElementPresent(By.id("close_welcome_box")));
- if (isElementPresent(By.xpath("//*[contains(.,'"
- + "google-analytics.com/ga.js" + "')]"))) {
- addMessage("ldlGA", "success");
- } else {
- addMessage("ldlGA", "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++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement