Repository navigation
Expand file tree
/
Copy pathtest.java
More file actions
122 lines (101 loc) · 4.84 KB
/
Copy pathtest.java
File metadata and controls
122 lines (101 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// NOTE: replace USERNAME:ACCESS_KEY@YOUR_SUBDOMAIN and VIDEO_URL with your credentials found in the Gridlastic dashboard
// ALSO SEE https://github.com/Gridlastic/demo1 FOR JAVA TESTNG EXAMPLES WITH PARALLEL TEST EXECUTIONS
// NOTE: THE FIRST TEST ON A GRID NODE AFTER BEING LAUNCHED CAN BE SLOW, FOLLOWING TESTS ARE MUCH FASTER AFTER THE NODE IS "WARMED" UP.
package java_example;
import java.net.URL;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class test {
// VIDEO_URL set to like "https://s3-ap-southeast-2.amazonaws.com/b2729248-ak68-6948-a2y8-80e7479te16a/9ag7b09j-6a38-58w2-bb01-17qw724ce46t/play.html?".
// Find this VIDEO_URL value in your Gridlastic dashboard.
private static final String VIDEO_URL = null;
private RemoteWebDriver driver;
@BeforeMethod(alwaysRun = true)
public void beforeMethod() throws Exception {
// Example test environment. NOTE: Gridlastic auto scaling requires all
// these 3 environment variables in each request.
String platform_name = "win7";
String browser_name = "firefox";
String browser_version = "47"; // for Chrome leave empty
// optional video recording
String record_video = "True";
DesiredCapabilities capabilities = new DesiredCapabilities();
if (platform_name.equalsIgnoreCase("win7")) {
capabilities.setPlatform(Platform.VISTA);
}
if (platform_name.equalsIgnoreCase("win8")) {
capabilities.setPlatform(Platform.WIN8);
}
if (platform_name.equalsIgnoreCase("win8_1")) {
capabilities.setPlatform(Platform.WIN8_1);
}
if (platform_name.equalsIgnoreCase("win10")) {
capabilities.setPlatform(Platform.WIN10);
}
if (platform_name.equalsIgnoreCase("linux")) {
capabilities.setPlatform(Platform.LINUX);
}
capabilities.setBrowserName(browser_name);
capabilities.setVersion(browser_version);
// video record
if (record_video.equalsIgnoreCase("True")) {
capabilities.setCapability("video", "True"); // NOTE: "True" is a case sensitive string, not boolean.
} else {
capabilities.setCapability("video", "False"); // NOTE: "False" is a case sensitive string, not boolean.
}
//Chrome specifics
if (browser_name.equalsIgnoreCase("chrome")){
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars"); // starting from Chrome 57 the info bar displays with "Chrome is being controlled by automated test software."
// On Linux start-maximized does not expand browser window to max screen size. Always set a window size.
if (platform_name.equalsIgnoreCase("linux")) {
options.addArguments(Arrays.asList("--window-position=0,0"));
options.addArguments(Arrays.asList("--window-size=1920,1080"));
} else {
options.addArguments(Arrays.asList("--start-maximized"));
}
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
}
//Firefox specifics
if (browser_name.equalsIgnoreCase("firefox")){
// If you are using selenium 3 and test Firefox versions below version 48
if(Integer.parseInt(browser_version)<48){
capabilities.setCapability("marionette", false);
}
}
//replace USERNAME:ACCESS_KEY@SUBDOMAIN with your credentials found in the Gridlastic dashboard
driver = new RemoteWebDriver(new URL("http://USERNAME:ACCESS_KEY@YOUR_SUBDOMAIN.gridlastic.com:80/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().window().maximize(); // Always maximize firefox on windows
// On LINUX/FIREFOX the "driver.manage().window().maximize()" option does not expand browser window to max screen size. Always set a window size.
if (platform_name.equalsIgnoreCase("linux") && browser_name.equalsIgnoreCase("firefox")) {
driver.manage().window().setSize(new Dimension(1920, 1080));
}
if (record_video.equalsIgnoreCase("True")) {
System.out.println("Test Video: " + VIDEO_URL + ((RemoteWebDriver) driver).getSessionId());
}
}
@Test(enabled = true)
public void test_site() throws Exception {
driver.get("https://www.google.com/ncr");
Thread.sleep(10000); //slow down for demo purposes
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("webdriver");
element.submit();
Thread.sleep(5000); //slow down for demo purposes
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception {
driver.quit();
}
}