10000 add more functions in SeMet. · python012/Solvent@e476aeb · GitHub
[go: up one dir, main page]

Skip to content

Commit e476aeb

Browse files
committed
add more functions in SeMet.
1 parent 22ab3f1 commit e476aeb

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/com/semet/SeMet.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.openqa.selenium.JavascriptExecutor;
66
import org.openqa.selenium.NoSuchElementException;
77
import org.openqa.selenium.WebElement;
8+
import org.openqa.selenium.interactions.Actions;
89
import org.openqa.selenium.remote.RemoteWebDriver;
910

1011
import com.solvent.Solvent;
@@ -224,4 +225,69 @@ public boolean isElementPresentAndVisible(String locator, int wait) {
224225
}
225226
return present;
226227
}
228+
229+
public boolean isElementPresent(String locator) {
230+
return isElementPresent(locator, 5000); // could use properties file to set this value
231+
}
232+
233+
public void moveTo(WebElement element) {
234+
Actions action = new Actions(driver);
235+
action.moveToElement(element).build().perform();
236+
pause(500);
237+
}
238+
239+
public void mouseOver(WebElement element) {
240+
StringBuilder sb = new StringBuilder();
241+
sb.append("var element = arguments[0]");
242+
sb.append("if (document.createEvent) {");
243+
sb.append("var event = document.createEvent(\"MouseEvents\");");
244+
sb.append("event.initMouseEvent(\"mouseover\", true, true, window, 0, 0," +
245+
"0, 0, 0, false, false, false, false, 0, null);");
246+
sb.append("element.dispatchEvent(event);");
247+
sb.append("}");
248+
sb.append("else if (element.fireEvent) {");
249+
sb.append("element.fireEvent(\"onmouseover\");");
250+
sb.append("}");
251+
driver.executeScript(sb.toString(), element);
252+
}
253+
254+
public void mouseOver(String locator) {
255+
mouseOver(getElementUsingXpath(locator));
256+
pause(500);
257+
}
258+
259+
public void pause(long time) {
260+
SetMetWebDriverSession.pause(time);
261+
}
262+
263+
public static void waitForContent() {
264+
log.debug("Wait for page content to be ready. Ensure all " +
265+
"ajax calls are complete before test continue.");
266+
SetMetWebDriverSession.pause(3000); // a simple way to wait for ajax
267+
}
268+
269+
public void setCheckBox(WebElement checkbox, boolean check) {
270+
if (checkbox.isSelected()) {
271+
if (!check) {
272+
checkbox.click();
273+
}
274+
} else if (check) {
275+
checkbox.click();
276+
}
277+
}
278+
279+
protected void setRadioByValue(List<WebElement> options, String value) {
280+
for (WebElement option:options) {
281+
String optionValue = option.getAttribute("value");
282+
if (optionValue.hashCode() == value.hashCode()) {
283+
log.debug("\n found radio box with value='" + value + "'");
284+
option.click();
285+
break;
286+
}
287+
}
288+
}
289+
290+
public void importFile(WebElement element, String filePath) {
291+
element.sendKeys(filePath);
292+
}
227293
}
0