forked from saucelabs-training/demo-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule1JunitTest.java
More file actions
51 lines (42 loc) · 1.96 KB
/
Module1JunitTest.java
File metadata and controls
51 lines (42 loc) · 1.96 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
package com.onboarding;
import com.saucelabs.saucebindings.Browser;
import com.saucelabs.saucebindings.SauceOptions;
import com.saucelabs.saucebindings.SaucePlatform;
import com.saucelabs.saucebindings.SauceSession;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import static org.junit.Assert.assertTrue;
public class Module1JunitTest {
@Test
public void shouldOpenSafari() {
/**
* Using Java 9+, we get a new and simple way to start a session
* in Sauce Labs using Sauce Bindings
* https://opensource.saucelabs.com/sauce_bindings/docs/getting-started
*/
SauceOptions sauceOptions = new SauceOptions();
sauceOptions.setPlatformName(SaucePlatform.MAC_HIGH_SIERRA);
sauceOptions.setBrowserName(Browser.SAFARI);
//set the build name of the application
sauceOptions.setBuild("Onboarding Sample App - Java-Junit4");
//set your test case name so that it shows up in Sauce Labs
sauceOptions.setName("1-first-test");
SauceSession session = new SauceSession(sauceOptions);
WebDriver driver = session.start();
//navigate to the url of the Sauce Labs Sample app
driver.navigate().to("https://www.saucedemo.com");
//Create an instance of a Selenium explicit wait
// so that we can dynamically wait for an element
WebDriverWait wait = new WebDriverWait(driver, 5);
//wait for the user name field to be visible and store that element into a variable
By userNameFieldLocator = By.cssSelector("[type='text']");
WebElement userNameField = wait.until(ExpectedConditions.visibilityOfElementLocated(userNameFieldLocator));
Boolean result = userNameField != null;
session.stop(result);
assertTrue(result);
}
}