Commit 9bf87639 authored by Siva Rama Krishna's avatar Siva Rama Krishna

remote driver sample code

parent b2799486
......@@ -13,7 +13,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<selenium.version>2.53.1</selenium.version>
<selenium.version>3.141.59</selenium.version>
<testng.version>6.8</testng.version>
</properties>
<dependencies>
......
package com.example.demo;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class DemoApplication {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/home/user/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
// chromeOptions.addArguments("--headless");
public static void main(String[] args) throws MalformedURLException {
launchBrowserInNormalMode();
}
private static void launchBrowserInNormalMode() throws MalformedURLException {
// In this mode we would be connecting to remote web driver(similar to selenium
// grid) meaning the script would be executed in the remote server.
// Below is the sample code to initialize the web driver.
String remoteDriverHost = "https://pgtest.altimetrik.com/SERVICE_NAME";
// To see live execution of the script in browser please open the link
// `{remoteDriverHost}/grid/admin/live`
// To view more details of the execution Please open the link
// `{remoteDriverHost}/dashboard/`
DesiredCapabilities dc = DesiredCapabilities.chrome();
RemoteWebDriver driver = new RemoteWebDriver(new URL(remoteDriverHost + "/wd/hub"), dc);
dc.setCapability("name", "BrowserMode");
// Continue with test case scripting.
driver.navigate().to("https://www.google.com/");
System.out.println("Application title is " + driver.getTitle());
driver.quit();
}
private static void launchBrowserInHeadlessMode() {
// The browser won't be visible instead it would running in the background.
// Below is the sample code to initialize the web driver.
System.setProperty("webdriver.chrome.driver", "/home/user/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
WebDriver driver = new ChromeDriver(chromeOptions);
WebDriver driver = new ChromeDriver(chromeOptions);
// Continue with test case scripting.
driver.navigate().to("http://google.com");
System.out.println("Application title is " + driver.getTitle());
driver.quit();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment