use of org.openqa.selenium.safari.SafariDriver in project MedunnaHealthTeam75 by ElanurSelcuk.
the class Driver method getDriver.
// to initialize the driver we create a static method
public static WebDriver getDriver() {
// create the driver if and only if it is null
if (driver == null) {
String browser = ConfigurationReader.getProperty("browser");
if ("chrome".equals(browser)) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
} else if ("firefox".equals(browser)) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
} else if ("ie".equals(browser)) {
WebDriverManager.iedriver().setup();
driver = new InternetExplorerDriver();
} else if ("safari".equals(browser)) {
WebDriverManager.getInstance(SafariDriver.class).setup();
driver = new SafariDriver();
} else if ("chrome-headless".equals(browser)) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver(new ChromeOptions().setHeadless(true));
}
}
// driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().window().maximize();
return driver;
}
use of org.openqa.selenium.safari.SafariDriver in project seleniumRobot by bhecquet.
the class CustomEventFiringWebDriver method scrollToElement.
/**
* scroll to the given element
* we scroll 200 px to the left of the element so that we see all of it
* @param element
*/
public void scrollToElement(WebElement element, int yOffset) {
if (isWebTest) {
try {
WebElement parentScrollableElement = (WebElement) ((JavascriptExecutor) driver).executeScript(JS_SCROLL_PARENT, element, (driver instanceof SafariDriver) ? SAFARI_BROWSER : OTHER_BROWSER);
Long topHeaderSize = (Long) ((JavascriptExecutor) driver).executeScript(JS_GET_TOP_HEADER);
// try a second method (the first one is quicker but does not work when element is inside a document fragment, slot or shadow DOM
if ((parentScrollableElement == null || "html".equalsIgnoreCase(parentScrollableElement.getTagName())) && !(driver instanceof InternetExplorerDriver)) {
parentScrollableElement = (WebElement) ((JavascriptExecutor) driver).executeScript(JS_SCROLL_PARENT2, element, (driver instanceof SafariDriver) ? SAFARI_BROWSER : OTHER_BROWSER);
}
if (parentScrollableElement != null) {
String parentTagName = parentScrollableElement.getTagName();
// When the scrollable element is the document itself (html or body), use the legacy behavior scrolling the window itself
if ("html".equalsIgnoreCase(parentTagName) || "body".equalsIgnoreCase(parentTagName)) {
if (yOffset == Integer.MAX_VALUE) {
// equivalent to HtmlElement.OPTIMAL_SCROLLING but, for grid, we do not want dependency between the 2 classes
yOffset = (int) Math.min(-200, -topHeaderSize);
}
scrollWindowToElement(element, yOffset);
// When scrollable element is a "div" or anything else, use scrollIntoView because it's the easiest way to make the element visible
} else {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
// check if scrollbar of parent is at bottom. In this case, going upside (yOffset < 0), could hide searched element.
// scrollIntoView is configured to position scrollbar to top position of the searched element.
// in case offset is > 0, this has no impact as scrollBottom will always be < 0
// wait a bit so that scrolling is complete
WaitHelper.waitForMilliSeconds(500);
// if top header is present, scroll up so that our element is not hidden behind it (scrollIntoView scrolls so that element is at the top of the view even if header masks it)
if (topHeaderSize > 0) {
// equivalent to HtmlElement.OPTIMAL_SCROLLING but, for grid, we do not want dependency between the 2 classes
Integer scrollOffset = (int) (yOffset == Integer.MAX_VALUE ? topHeaderSize : topHeaderSize - yOffset);
((JavascriptExecutor) driver).executeScript("if((arguments[0].scrollHeight - arguments[0].scrollTop - arguments[0].clientHeight) > 0) {" + " var rootElement = arguments[1] === \"safari\" ? document.body: document.documentElement;" + " rootElement.scrollTop -= " + scrollOffset + ";" + "}", parentScrollableElement, (driver instanceof SafariDriver) ? SAFARI_BROWSER : OTHER_BROWSER);
}
// wait a bit so that scrolling is complete
WaitHelper.waitForMilliSeconds(500);
}
} else {
// go to default behavior
throw new JavascriptException("No parent found");
}
} catch (Exception e) {
// fall back to legacy behavior
if (yOffset == Integer.MAX_VALUE) {
yOffset = -200;
}
try {
scrollWindowToElement(element, yOffset);
} catch (Exception e1) {
logger.info(String.format("Cannot scroll to element %s: %s", element.toString(), e1.getMessage()));
}
}
}
}
use of org.openqa.selenium.safari.SafariDriver in project boyka-java by WasiqBhamla.
the class DriverManager method setupSafariDriver.
private WebDriver setupSafariDriver() {
LOGGER.traceEntry();
safaridriver().setup();
return LOGGER.traceExit(new SafariDriver());
}
use of org.openqa.selenium.safari.SafariDriver in project okta-idx-java by okta.
the class DriverUtil method chooseDriver.
/**
* By default to web driver will be firefox
*
* Override it by passing -Dbrowser=Chrome to the command line arguments
* @return webdriver
*/
private static WebDriver chooseDriver() {
String preferredDriver = System.getProperty("browser", "Chrome");
boolean headless = System.getProperty("headless", "false").equals("true");
switch(preferredDriver.toLowerCase()) {
case "safari":
try {
driver = new SafariDriver();
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
return driver;
case "edge":
try {
driver = new EdgeDriver();
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
return driver;
case "firefox":
FirefoxOptions options = new FirefoxOptions();
if (headless) {
options.addArguments("-headless", "-safe-mode");
}
try {
driver = new FirefoxDriver(options);
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
return driver;
default:
final ChromeOptions chromeOptions = new ChromeOptions();
if (headless) {
chromeOptions.addArguments("--headless");
}
chromeOptions.addArguments("--disable-dev-shm-usage");
if (System.getenv("TRAVIS") != null) {
chromeOptions.addArguments("--headless", "--verbose");
}
try {
driver = new ChromeDriver(chromeOptions);
ErrorHandler handler = new ErrorHandler();
handler.setIncludeServerErrors(false);
// driver.setErrorHandler(handler);
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}
return driver;
}
}
use of org.openqa.selenium.safari.SafariDriver in project selenide by selenide.
the class SafariDriverFactory method create.
@Nonnull
@CheckReturnValue
@Override
public WebDriver create(Config config, Browser browser, @Nullable Proxy proxy, @Nullable File browserDownloadsFolder) {
SafariDriverService driverService = createDriverService(config);
SafariOptions capabilities = createCapabilities(config, browser, proxy, browserDownloadsFolder);
return new SafariDriver(driverService, capabilities);
}
Aggregations