View difference between Paste ID: Y1GK9nZN and Zd8f4eaq
SHOW: | | - or go back to the newest paste.
1
package com.skgcom.tutorial;
2
3
import static org.testng.Assert.*;
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.openqa.selenium.By;
14
import org.openqa.selenium.NoSuchElementException;
15
import org.openqa.selenium.WebDriver;
16
import org.openqa.selenium.firefox.FirefoxDriver;
17
import org.openqa.selenium.remote.DesiredCapabilities;
18
import org.openqa.selenium.remote.RemoteWebDriver;
19
//import org.openqa.selenium.ie.InternetExplorerDriver;
20
import org.testng.annotations.Test;
21
22
public class galdl1Test {
23
24
	static String[][] post_vars;
25
	private static int post_var_count;
26
	private static WebDriver driver;
27
	
28
	
29
30
	private static StringBuffer verificationErrors = new StringBuffer();
31
32-
		driver = new FirefoxDriver();
32+
33
	public void betaTest() throws IOException {
34
		post_vars = new String[255][255];
35
		driver = new RemoteWebDriver(new URL("http://locahost:4444/wd/hub"),
36
		DesiredCapabilities.firefox());
37
38
		// driver = new InternetExplorerDriver();
39
		String baseUrl = System.getProperty("url");
40
	//	String baseUrl = System.getenv("url");
41
		String testSite = System.getProperty("site");
42
	//	String testSite = System.getenv("site");
43
	//	System.out.format("%s=%s%n", "urlvar", System.getenv("url"));
44
	//	System.out.format("%s=%s%n", "url", baseUrl);
45
		driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
46
47
		// ERROR: Caught exception [ERROR: Unsupported command [setSpeed]]
48
		addMessage("Site", testSite);
49
		addMessage("URL", baseUrl);
50
		addMessage("ldlGA", "started...");
51
		http_post();
52
		post_vars[2][0] = null;
53
		post_vars[2][1] = null;
54
		
55
		driver.get(baseUrl + "/hotel/");
56
57
		// Thread.sleep(30000);
58
		// System.out.println(isElementPresent(By.id("close_welcome_box")));
59
60
		if (isElementPresent(By.xpath("//*[contains(.,'"
61
				+ "google-analytics.com/ga.js" + "')]"))) {
62
			addMessage("ldlGA", "success");
63
		} else {
64
			addMessage("ldlGA", "FAIL");
65
		}
66
67
		driver.quit();
68
		http_post();
69
		String verificationErrorString = verificationErrors.toString();
70
		if (!"".equals(verificationErrorString)) {
71
72
			fail(verificationErrorString);
73
		}
74
	}
75
76
	private static boolean isElementPresent(By by) {
77
		try {
78
			driver.findElement(by);
79
			return true;
80
		} catch (NoSuchElementException e) {
81
			return false;
82
		}
83
	}
84
85
	public static void http_post() throws IOException {
86
87
		// Construct data
88
		String data = "";
89
		for (int n = 0; n <= post_vars.length - 1; n++) {
90
			if (post_vars[n][0] != null) {
91
				data += post_vars[n][0] + "=" + post_vars[n][1] + "&";
92
			}
93
		}
94
		// Send data
95
		URL url = new URL("http://logs.skgcom.com/UnitTest.php");
96
		URLConnection conn = url.openConnection();
97
		conn.setDoOutput(true);
98
		OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
99
		wr.write(data);
100
		wr.flush();
101
102
		// Get the response
103
		BufferedReader rd = new BufferedReader(new InputStreamReader(
104
				conn.getInputStream()));
105
		String line;
106
		while ((line = rd.readLine()) != null) {
107
			System.out.println(line);
108
		}
109
		wr.close();
110
		rd.close();
111
112
	}
113
114
	public static void addMessage(String key, String value) {
115
116
		post_vars[post_var_count][0] = key;
117
		post_vars[post_var_count][1] = value;
118
		post_var_count++;
119
	}
120
}
121
122