-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSeleniumActions.java
66 lines (55 loc) · 2.32 KB
/
SeleniumActions.java
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
package se.ica.framework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import se.ica.utilities.LocatorObject;
import java.time.Duration;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
public class SeleniumActions {
private final WebDriver webDriver;
public SeleniumActions(WebDriver webDriver) {
try {
this.webDriver = webDriver;
this.webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
this.webDriver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
this.webDriver.manage().timeouts().setScriptTimeout(Duration.ofSeconds(10));
} catch (WebDriverException webDriverException) {
throw new WebDriverException(webDriverException);
}
}
public void click(LocatorObject locatorObjectToClick) {
try {
webDriver.findElement(locatorObjectToClick.elementValue).click();
} catch (WebDriverException webDriverException) {
throw new WebDriverException(webDriverException);
}
}
public void openURL(String applicationURL) {
try {
webDriver.get(applicationURL);
} catch (WebDriverException webDriverException) {
throw new WebDriverException(webDriverException);
}
}
public void enterTextInTextBox(LocatorObject locatorTextBox, String textToEnter) {
try {
webDriver.findElement(locatorTextBox.elementValue).sendKeys(textToEnter);
} catch (WebDriverException webDriverException) {
throw new WebDriverException(webDriverException);
}
}
public void assertTextPresentInElement(LocatorObject locatorObject, String expectedText) {
try {
assertThat(webDriver.findElement(locatorObject.elementValue).getText(), is(expectedText));
} catch (WebDriverException webDriverException) {
throw new WebDriverException(webDriverException);
}
}
public void assertElementIsDisplayed(LocatorObject locatorObject) {
try {
assertThat(webDriver.findElement(locatorObject.elementValue).isDisplayed(), is(true));
} catch (WebDriverException webDriverException) {
throw new WebDriverException(webDriverException);
}
}
}