Skip to content

Commit aef9ab4

Browse files
author
admin
committed
Updates for latest selenium version and Linux testing.
1 parent b48894a commit aef9ab4

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

‎java_test_example/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>org.seleniumhq.selenium</groupId>
1818
<artifactId>selenium-java</artifactId>
19-
<version>2.44.0</version>
19+
<version>2.48.2</version>
2020
</dependency>
2121
</dependencies>
2222
<build>

‎java_test_example/src/test/java/java_example/test.java‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
// NOTE: replace USERNAME:ACCESS_KEY@SUBDOMAIN and VIDEO_URL with your credentials found in the Gridlastic dashboard
2+
// ALSO SEE https://github.com/Gridlastic/demo1 FOR JAVA TESTNG EXAMPLES WITH PARALLEL TEST EXECUTIONS
3+
// 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.
4+
15
package java_example;
26

37
import java.net.URL;
48
import java.util.Arrays;
59
import java.util.concurrent.TimeUnit;
610

11+
import org.openqa.selenium.By;
12+
import org.openqa.selenium.Dimension;
713
import org.openqa.selenium.Platform;
14+
import org.openqa.selenium.WebElement;
815
import org.openqa.selenium.chrome.ChromeOptions;
916
import org.openqa.selenium.remote.DesiredCapabilities;
1017
import org.openqa.selenium.remote.RemoteWebDriver;
@@ -14,17 +21,19 @@
1421

1522
public class test {
1623

17-
private static final String VIDEO_URL = null;
24+
// VIDEO_URL set to like "https://s3-ap-southeast-2.amazonaws.com/b2729248-ak68-6948-a2y8-80e7479te16a/9ag7b09j-6a38-58w2-bb01-17qw724ce46t/play.html?".
25+
// Find this VIDEO_URL value in your Gridlastic dashboard.
26+
private static final String VIDEO_URL = null;
1827
private RemoteWebDriver driver;
1928

2029
@BeforeMethod(alwaysRun = true)
2130
public void beforeMethod() throws Exception {
2231

2332
// Example test environment. NOTE: Gridlastic auto scaling requires all
2433
// these 3 environment variables in each request.
25-
String platform_name = "linux";
34+
String platform_name = "win7";
2635
String browser_name = "firefox";
27-
String browser_version = "36"; // for Chrome leave empty
36+
String browser_version = "41"; // for Chrome leave empty
2837

2938
// optional video recording
3039
String record_video = "True";
@@ -54,18 +63,24 @@ public void beforeMethod() throws Exception {
5463

5564
if (browser_name.equalsIgnoreCase("chrome")){
5665
ChromeOptions options = new ChromeOptions();
57-
options.addArguments(Arrays.asList("--start-maximized"));
66+
// On Linux start-maximized does not expand browser window to max screen size. Always set a window size.
67+
if (platform_name.equalsIgnoreCase("linux")) {
68+
options.addArguments(Arrays.asList("--window-size=1920,1080"));
69+
} else {
70+
options.addArguments(Arrays.asList("--start-maximized"));
71+
}
5872
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
5973
}
6074

6175

62-
63-
driver = new RemoteWebDriver(
64-
new URL(
65-
"http://USERNAME:ACCESS_KEY@SUBDOMAIN.gridlastic.com:4444/wd/hub"),
66-
capabilities);
76+
//replace USERNAME:ACCESS_KEY@SUBDOMAIN with your credentials found in the Gridlastic dashboard
77+
driver = new RemoteWebDriver(new URL("http://USERNAME:ACCESS_KEY@SUBDOMAIN.gridlastic.com:80/wd/hub"),capabilities);
6778
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
68-
driver.manage().window().maximize();
79+
80+
// On LINUX/FIREFOX the "driver.manage().window().maximize()" option does not expand browser window to max screen size. Always set a window size.
81+
if (platform_name.equalsIgnoreCase("linux") && browser_name.equalsIgnoreCase("firefox")) {
82+
driver.manage().window().setSize(new Dimension(1920, 1080));
83+
}
6984

7085

7186
if (record_video.equalsIgnoreCase("True")) {
@@ -75,11 +90,13 @@ public void beforeMethod() throws Exception {
7590
}
7691

7792
@Test(enabled = true)
78-
public void test_google() {
79-
driver.get("http://www.java.com");
80-
driver.findElementByLinkText("About Java").click();
81-
driver.findElementByLinkText("Troubleshoot Java").click();
82-
driver.findElementByLinkText("Support");
93+
public void test_site() throws Exception {
94+
driver.get("https://www.google.com/ncr");
95+
Thread.sleep(10000); //slow down for demo purposes
96+
WebElement element = driver.findElement(By.name("q"));
97+
element.sendKeys("webdriver");
98+
element.submit();
99+
Thread.sleep(5000);
83100
}
84101

85102
@AfterMethod(alwaysRun = true)

0 commit comments

Comments
 (0)