use of org.openqa.selenium.chrome.ChromeDriver in project ats-framework by Axway.
the class RealHtmlFileBrowse method setValueUsingNativeDialog.
/**
* This method allows you to type in dialog windows. This option is available only for Windows OS
*
* @param path add the location of the file, you want to type in the dialog window
* @throws Exception
*/
@PublicAtsApi
public void setValueUsingNativeDialog(String path) throws Exception {
if (!OperatingSystemType.getCurrentOsType().isWindows()) {
throw new RuntimeException("This method is only available for Windows machines!");
}
// check if the file exist
if (!new File(path).exists()) {
throw new FileNotFoundException("File path \"" + path + "\" is wrong or does not exist!");
}
// ats_file_upload.exe location
String uploadFileDestination = System.getProperty("user.dir") + "\\ats_file_upload.exe";
// native window name
String windowName;
log.info("Using native " + path + " to work with native browser dialogs");
// check if the ats_file_upload.exe file is already created
if (!new File(uploadFileDestination).exists()) {
OutputStream os = null;
InputStream is = null;
try {
// get the ats_file_upload.exe file, located in the ats-uiengine.jar
is = getClass().getClassLoader().getResourceAsStream("binaries/ats_file_upload.exe");
if (is == null) {
throw new FileNotFoundException("The 'ats_file_upload.exe' file is not found in ats-uiengine.jar!");
}
File uploadFile = new File(uploadFileDestination);
os = new FileOutputStream(uploadFile);
IOUtils.copy(is, os);
} finally {
IoUtils.closeStream(is);
IoUtils.closeStream(os);
}
}
if (webDriver instanceof FirefoxDriver) {
windowName = " \"File Upload\" ";
} else if (webDriver instanceof ChromeDriver) {
windowName = " \"Open\" ";
} else {
throw new RobotException("Not Implemented for your browser! Currently Firefox and " + "Chrome are supported.");
}
// add the browse button properties
((AbstractRealBrowserDriver) super.getUiDriver()).getHtmlEngine().getElement(properties).click();
// run the ats_file_upload.exe file
IProcessExecutor proc = new LocalProcessExecutor(HostUtils.LOCAL_HOST_IPv4, uploadFileDestination + windowName + path);
proc.execute();
// check if there is any error, while executing the ats_file_upload.exe file
if (proc.getExitCode() != 0) {
log.error("AutoIT process for native browser interaction failed with exit code: " + proc.getExitCode() + ";");
log.error("Output stream data: " + proc.getStandardOutput() + ";");
log.error("Error stream data: " + proc.getErrorOutput());
throw new RobotException("AutoIT process for native browser interaction failed.");
}
}
use of org.openqa.selenium.chrome.ChromeDriver in project zeppelin by apache.
the class WebDriverManager method getWebDriver.
public static WebDriver getWebDriver() {
WebDriver driver = null;
if (driver == null) {
try {
FirefoxBinary ffox = new FirefoxBinary();
if ("true".equals(System.getenv("TRAVIS"))) {
// xvfb is supposed to
ffox.setEnvironmentProperty("DISPLAY", ":99");
// run with DISPLAY 99
}
int firefoxVersion = WebDriverManager.getFirefoxVersion();
LOG.info("Firefox version " + firefoxVersion + " detected");
downLoadsDir = FileUtils.getTempDirectory().toString();
String tempPath = downLoadsDir + "/firebug/";
downloadFireBug(firefoxVersion, tempPath);
final String firebugPath = tempPath + "firebug.xpi";
final String firepathPath = tempPath + "firepath.xpi";
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", downLoadsDir);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("app.update.auto", false);
profile.setPreference("app.update.enabled", false);
profile.setPreference("dom.max_script_run_time", 0);
profile.setPreference("dom.max_chrome_script_run_time", 0);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
profile.setPreference("network.proxy.type", 0);
profile.addExtension(new File(firebugPath));
profile.addExtension(new File(firepathPath));
driver = new FirefoxDriver(ffox, profile);
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
}
}
if (driver == null) {
try {
driver = new ChromeDriver();
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
}
}
if (driver == null) {
try {
driver = new SafariDriver();
} catch (Exception e) {
LOG.error("Exception in WebDriverManager while SafariDriver ", e);
}
}
String url;
if (System.getenv("url") != null) {
url = System.getenv("url");
} else {
url = "http://localhost:8080";
}
long start = System.currentTimeMillis();
boolean loaded = false;
driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
driver.get(url);
while (System.currentTimeMillis() - start < 60 * 1000) {
// wait for page load
try {
(new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
return d.findElement(By.xpath("//i[@tooltip='WebSocket Connected']")).isDisplayed();
}
});
loaded = true;
break;
} catch (TimeoutException e) {
LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
driver.navigate().to(url);
}
}
if (loaded == false) {
fail();
}
return driver;
}
use of org.openqa.selenium.chrome.ChromeDriver in project webmagic by code4craft.
the class WebDriverPool method configure.
/**
* Configure the GhostDriver, and initialize a WebDriver instance. This part
* of code comes from GhostDriver.
* https://github.com/detro/ghostdriver/tree/master/test/java/src/test/java/ghostdriver
*
* @author bob.li.0718@gmail.com
* @throws IOException
*/
public void configure() throws IOException {
// Read config file
sConfig = new Properties();
String configFile = DEFAULT_CONFIG_FILE;
if (System.getProperty("selenuim_config") != null) {
configFile = System.getProperty("selenuim_config");
}
sConfig.load(new FileReader(configFile));
// Prepare capabilities
sCaps = new DesiredCapabilities();
sCaps.setJavascriptEnabled(true);
sCaps.setCapability("takesScreenshot", false);
String driver = sConfig.getProperty("driver", DRIVER_PHANTOMJS);
// Fetch PhantomJS-specific configuration parameters
if (driver.equals(DRIVER_PHANTOMJS)) {
// "phantomjs_exec_path"
if (sConfig.getProperty("phantomjs_exec_path") != null) {
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, sConfig.getProperty("phantomjs_exec_path"));
} else {
throw new IOException(String.format("Property '%s' not set!", PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
}
// "phantomjs_driver_path"
if (sConfig.getProperty("phantomjs_driver_path") != null) {
System.out.println("Test will use an external GhostDriver");
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY, sConfig.getProperty("phantomjs_driver_path"));
} else {
System.out.println("Test will use PhantomJS internal GhostDriver");
}
}
// Disable "web-security", enable all possible "ssl-protocols" and
// "ignore-ssl-errors" for PhantomJSDriver
// sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new
// String[] {
// "--web-security=false",
// "--ssl-protocol=any",
// "--ignore-ssl-errors=true"
// });
ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
// Control LogLevel for GhostDriver, via CLI arguments
sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, new String[] { "--logLevel=" + (sConfig.getProperty("phantomjs_driver_loglevel") != null ? sConfig.getProperty("phantomjs_driver_loglevel") : "INFO") });
// Start appropriate Driver
if (isUrl(driver)) {
sCaps.setBrowserName("phantomjs");
mDriver = new RemoteWebDriver(new URL(driver), sCaps);
} else if (driver.equals(DRIVER_FIREFOX)) {
mDriver = new FirefoxDriver(sCaps);
} else if (driver.equals(DRIVER_CHROME)) {
mDriver = new ChromeDriver(sCaps);
} else if (driver.equals(DRIVER_PHANTOMJS)) {
mDriver = new PhantomJSDriver(sCaps);
}
}
use of org.openqa.selenium.chrome.ChromeDriver in project antlr4 by antlr.
the class SharedWebDriver method init.
public static WebDriver init() {
if (driver == null) {
String path = SharedWebDriver.class.getPackage().getName().replace(".", "/") + "/chromedriver.bin";
URL url = Thread.currentThread().getContextClassLoader().getResource(path);
// skip 'file:'
File file = new File(url.toExternalForm().substring(5));
assertTrue(file.exists());
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver = new ChromeDriver();
} else if (timer != null) {
timer.cancel();
timer = null;
}
return driver;
}
use of org.openqa.selenium.chrome.ChromeDriver in project java.webdriver by sayems.
the class Click method main.
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.navigate().to("http://www.google.com");
JavascriptExecutor jse = (JavascriptExecutor) driver;
driver.findElement(By.id("gbqfq")).sendKeys("Selenium");
jse.executeScript("document.getElementById('gbqfba').click();");
}
Aggregations