I am using below code for Firefox launch in locally and through VM machine. But I am unable to launch firefox through VM machine.
case FIREFOX:
browserType = BrowserTypes.FIREFOX;
System.setProperty("webdriver.gecko.driver", "Drivers/geckodriver.exe");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("marionette", true);
firefoxOptions.setAcceptInsecureCerts(true);
if(isRemote) {
webDriver = launchGridDriver(firefoxOptions, configProps.getNodeUrl());
Reporter.log("Running test on Grid, in browser \'Firefox\'", true);
} else {
webDriver = new FirefoxDriver(firefoxOptions);
Reporter.log("Running test in browser \'FIREFOX\'", true);
}
break;
private WebDriver launchGridDriver(Capabilities capabilities, String url){
try{
return new RemoteWebDriver(new URL(url), capabilities);
} catch(Exception e){
Reporter.log("There was an error setting up the remote WebDriver.");
e.printStackTrace();
return null;
}
}
I am able to launch firefox locally and when I just trying to launch in remote below error is getting.
org.openqa.selenium.SessionNotCreatedException: Unable to create session from {
"desiredCapabilities": {
"browserName": "firefox",
"server:CONFIG_UUID": "02c53809-74d8-4b47-95a1-fc97610ba78c",
"moz:firefoxOptions": {
"args": [
],
"prefs": {
}
},
"marionette": true,
"acceptInsecureCerts": true
},
"capabilities": {
"firstMatch": [
{
"acceptInsecureCerts": true,
"browserName": "firefox",
"moz:firefoxOptions": {
"args": [
],
"prefs": {
}
},
"server:CONFIG_UUID": "02c53809-74d8-4b47-95a1-fc97610ba78c"
}
]
}
}
Need Few more inputs.. It looks like the networking issue where your code host is unable to reach the Hub.
Please let me know that :-
Where is the hub VM located, If it is on same machine, do use the IP Bridge Configuration and not NAT.
Do your machine having code and having Hub are on same VLAN.
Where is the Node? You wont be seeing the browser launch on Hub. It will be on node.
getNodeUrl() returns the IP of hub machine.
Firewalls on the hub and node and the code host machine is off (Just to ensure it is not blocking the connection)
Rest code looks fine.
Related
I followed the solution given by #obiwankoban and #SubjectiveReality mentioned at the following link:
How to handle authentication popup in Chrome with Selenium WebDriver using Java
I performed the below steps:
Created a folder called 'Extension'
Created following two files inside Extension folder.
manifest.json
{
"name": "Webrequest API",
"version": "1.0",
"description": "Extension to handle Authentication window",
"permissions": [
"webRequest",
"webRequestBlocking",
""
],
"background": {
"scripts": [
"webrequest.js"
]
},
"manifest_version": 2
}
webrequest.js
chrome.webRequest.onAuthRequired.addListener(function(details){
console.log("chrome.webRequest.onAuthRequired event has fired");
return {
authCredentials: {username: "getestone", password: "Viacom#2020"}
};
},
{urls:["<all_urls>"]},
['blocking']);
Updated Pack extension on chrome browser, post which .crx file gets created.
My Selenium code is as follows:
Selenium code
public class openWebsite {
public static void main(String[] args) {
Properties prop = new Properties();
ChromeOptions options = new ChromeOptions();
File addonpath = new
File("C:\\Users\\10642575\\Desktop\\Work\\Automation\\AuthPopUp\\Extension.crx");
ChromeOptions chrome = new ChromeOptions();
chrome.addExtensions(addonpath);
//options.addArguments("--no-sandbox");
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\10642575\\Desktop\\Work\\Automation\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;
driver.get("https://uat.contentplatform.viacom.com/");
driver.findElement(By.xpath("//input[#type='email']")).sendKeys("getest.one#viacom.com");
driver.findElement(By.xpath("//input[#type='submit']")).click();
}
}
On following the above steps, I still get the server authentication pop up when the website is launched on chrome. Authentication bypass is not working.
PLZ HELP
I have been trying to launch the Appium Server programatically and then based on the Process output, would initialize the Android Driver and run some tests. However, everytime the Appium Server is launched from the program, the execution stalls on the initialization of the Android Driver.
Here is my method for Starting the server:
private boolean StartServer(String strCommand)
{
try
{
rtCommand = Runtime.getRuntime();
proc = rtCommand.exec(strCommand);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
//Checking output of Appium Server Initialization
String s = null;
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
if (s.contains("Console LogLevel: debug"));
return true;
}
}
catch (Exception ex)
{
System.out.println("Error in starting Appium Server. Stack Trace below:");
ex.printStackTrace();
return false;
}
return false;
}
Now, My TestNG annotation #BeforeClass holds the following code:
#BeforeClass
public void setUp() throws MalformedURLException
{
StartServer("cmd /c \"\"C:/Program Files (x86)/nodejs/node.exe\" \"C:/Program Files (x86)/Appium/node_modules/appium/lib/server/main.js\" --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color --udid 3100aeb26c6a2363\"");
FrameworkDriver objFrameworkDriver = new FrameworkDriver();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ec5bee97");
capabilities.setCapability("BROWSER_NAME", Android");
capabilities.setCapability("VERSION", "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.XX.AA");
capabilities.setCapability("appActivity", "com.XX.AA.BB");
strProjectDir = "<MyProjectLoc>";
try
{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
catch (Exception ex)
{
ex.printStackTrace();
}
System.out.println();
}
The execution halted here:
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Try using something like version 5.1.1, instead of platform-version 23 in your start server command line. (The same version as defined in capabilities in your code)
StartServer("cmd /c \"\"C:/Program Files (x86)/nodejs/node.exe\" \"C:/Program Files (x86)/Appium/node_modules/appium/lib/server/main.js\" --address 127.0.0.1 --port 4723 --platform-name Android --version 5.1.1 --automation-name Appium --log-no-color --udid 3100aeb26c6a2363\"");
Appium wants to the OS version of the Android device instead of the API level
Also, ensure that the device name used while defining capabilities is same as that defined in start server command line.
I am unable to automate my tests parallelly in an Android platform with multiple mobile devices.
If I connect 2 devices to my system and provide capabilities like mobile device Name and version, It is executing in the device which is recognized first through ADB.
If try to start the appium servers with different ports,
new AppiumServiceBuilder().usingAnyFreePort() I am getting Null pointer Exception.
[36minfo[39m: Appium REST http interface listener started on 0.0.0.0:2583
[36minfo[39m: [debug] Non-default server args: {"port":2583}
1) How to override session with AppiumServiceBuilder()
2) How to Restrict appium to execute on the device which is provided with capabilities, even 2 or more devices are connected.
My Code:
public class ApiumMain {
public static void main(String[] args) {
new Thread( new Device_Thread( "4897bb00", "6.0.1" ) ).start();
// new Thread( new Device_Thread( "TA64301YVY", "5.0.1" ) ).start();
}
}
public class Device_Thread extends ApiumMain implements Runnable {
public String mobileDeviceName;
public String androidVersion;
public Device_Thread( String mobile, String version ) {
mobileDeviceName = mobile;
androidVersion = version;
}
#Override
public void run() {
String hsotMachineIP = "127.0.0.1";
Integer seleniumProt = 4723; /*Default {"port":4723}*/
String nodeJSExecutable = "C:\\Program Files (x86)\\Appium\\node.exe";
String appiumJS = "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\bin\\appium.js";
Integer nodeJSPort = (int)( Math.random() * 8000 ) + 1000;
startAppium(nodeJSExecutable, nodeJSPort, appiumJS, mobileDeviceName, androidVersion, hsotMachineIP, seleniumProt);
}
public void startAppium(String nodeJSExecutable, int nodeJSPort, String appiumJS,
String mobileDeviceName, String androidVersion, String hsotMachineIP, int seleniumProt ) {
RemoteWebDriver driver = null;
String appURL = "http://www.w3schools.com/";
// http://appium.io/slate/en/master/?java#appium-server-capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium" );
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", androidVersion );
capabilities.setCapability("deviceName", mobileDeviceName );
capabilities.setCapability("app", "chrome");
capabilities.setCapability("browserName", "chrome");
capabilities.setCapability("newCommandTimeout", "0");
// ANDROID ONLY
/*capabilities.setCapability("appActivity", "com.android");
capabilities.setCapability("appPackage", ".ApiumMain");
*/
// Appium servers are nothing but the Node.js server
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(
new AppiumServiceBuilder()
.usingDriverExecutable( new File( nodeJSExecutable ) )
.withAppiumJS( new File( appiumJS ) )
);
service.start();
System.out.println( "Device : " + mobileDeviceName );
try {
String url = String.format("http://%s:%d/wd/hub", hsotMachineIP, seleniumProt);
System.out.println(" Server Address : " + url );
driver = new RemoteWebDriver( new URL( url ), capabilities );
driver.get( appURL );
browserActions( driver, appURL );
}catch (MalformedURLException e) {
e.printStackTrace();
} finally {
driver.quit();
service.stop();
}
}
private void browserActions(RemoteWebDriver driver, String appURL) {
try {
WebElement ele = driver.findElementByXPath("//body/div[4]/div[1]/div[1]/a[1]");
ele.click();
WebElement ele2 = driver.findElementByXPath("//*[#id='topnav']/div[1]/div[1]/a[2]");
ele2.click();
System.in.read();
System.in.read();
} catch (ElementNotVisibleException logMsg){
} catch (IOException e) {
}
}
}
Appium setup for Windows:
Installed Android SDK, Appium [Server & java-client], Add ADT pugin to Eclipse IDE and Selenium-server-standalone
set Environment Variables:
AVA_HOME~C:\Program Files (x86)\Java\jdk1.8.0_66
ANDROID_HOME~D:\Android\sdk
Path~D:\Android\sdk;D:\Android\sdk\platform-tools - ADB Debugger
Running multiple Appium sessions with different Server flags for Parallel Android Tests
Appium is an open-source tool for automating native, mobile web, and hybrid applications on IOS and Android platforms.
Appium client libraries wraps around Selenium client libraries with some extra commands added to controlling mobile devices
Client: The machine on which the WebDriver[HTTP Client] API is being used to communicate with server through commands.
Appium Client implements the "Mobile JSONWP" to extend "JSONWP". The Mobile JSONWP is for automation of native and hybrid mobile applications and JSONWP is for automating web-browser applications.
Commands:Each HTTP request with a method and template defined in this specification represents a single command and therefore each command produces a single HTTP response. Client initiates a session with server using desired capabilities via JSON. Based on the browser session ID and Selenium remoteServerAddress the communication takes place through Http Rest API.
Selenium Source of HTTP Client:
HttpClient.Factory httpClientFactory = new ApacheHttpClient.Factory();
HttpClient client = httpClientFactory.createClient(remoteServerAddress);
HttpRequest httpRequest = commandCodec.encode(command);
HttpResponse httpResponse = client.execute(httpRequest, true);
Response response = responseCodec.decode(httpResponse);
Server: Before starting any mobile tests you must start the servers like RemoteWebDriver & Appium|NodeJS.
AppiumServer - REST API written in Node.js
SeleniumRCServer - The Selenium server receives Selenium commands from your test program using HTTP GET/POST requests, interprets and executes those commands, and reports back the results to your program.
Connect couple of android devices to the system and run below adb shell commands
D:\Yash>adb devices
List of devices attached
TA64301YVY device
4897bb00 device
D:\Yash>adb -s TA64301YVY shell getprop ro.build.version.release
5.1
D:\Yash>adb -s TA64301YVY shell getprop > D:\Yash\cmdOUT.txt
+----------------------------+------------+--------------+
|[net.bt.name]: | [Android] | [Android] |
|[ro.boot.serialno]: | [4897bb00] | [TA64301YVY] |
|[ro.product.brand]: | [samsung] | [motorola] |
|[ro.product.model]: | [SM-G900F] | [XT1052] |
|[ro.build.version.release]: | [6.0.1] | [5.1] |
+----------------------------+------------+--------------+
Q1 - Ans: To override a session with AppiumServiceBuilder use this argument "GeneralServerFlag.SESSION_OVERRIDE". presence of an arguments means "true"
Q2 - Ans: If we are not providing UDID (OR) RemoteAddress then Driver will connect to first device which is detected by ADB. If we want to restrict appium to connect specific named physical device in the list of connected devices use UDID-Unique device identifier.
JAVA Parallel Android Tests to automate mobile web apps [java-client-4.1.1.jar]:
nodeJSExec « [C:\Program Files (x86)\Appium\node.exe]
nodeJSArgs « [C:\Program Files (x86)\Appium\node_modules\appium\bin\appium.js, --port, 1750, --address, 127.0.0.1, --log, D:\Yash\MyAppiumConsole_4897bb00.txt, --chromedriver-port, 7115, --bootstrap-port, 7119, --session-override]
public void startAppium(String nodeJSExecutable, int nodeJSPort, String appiumJS, String mobileDeviceName,
String androidVersion, String hsotMachineIP ) {
RemoteWebDriver driver = null;
String appURL = "http://www.w3schools.com/";
File logFile = new File("D:/Yash/MyAppiumConsole_"+mobileDeviceName+".txt");
File javaConsole = new File("D:/Yash/MyJavaConsole_"+mobileDeviceName+".txt");
systemConsole2File( javaConsole );
/*The hub only reads browserName, version, platform and applicationName.
The other capabilities (deviceName, platformVersion, platformName, ...) are Appium capabilities, not used by the hub.*/
// Proxying straight through to Chromedriver
DesiredCapabilities capabilities = DesiredCapabilities.android();
/* Appium - io.appium.java_client.remote */
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium" );
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, androidVersion );
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, mobileDeviceName );
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "chrome"); // "Browser"
capabilities.setCapability(MobileCapabilityType.UDID, mobileDeviceName);
/* Selenium - org.openqa.selenium.remote */
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, "true");
// Appium servers are nothing but the Node.js server
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(
new AppiumServiceBuilder()
.withAppiumJS( new File( appiumJS ) )
.usingDriverExecutable( new File( nodeJSExecutable ) )
.usingPort( nodeJSPort )
.withIPAddress( hsotMachineIP )
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER, nextFreePort().toString())
.withArgument(AndroidServerFlag.CHROME_DRIVER_PORT, nextFreePort().toString())
.withLogFile(logFile)
);
service.start();
System.out.println(" Appium Server Address [Local]: " + service.getUrl() );
driver = new RemoteWebDriver( service.getUrl(), capabilities );
...
}
public static final int HIGHEST_PORT = 65535;
public static final int LEAST_PORT = 1024;
public static Integer nextFreePort() {
Integer port = (int)( Math.random() * 8000 ) + LEAST_PORT;
while (true) {
try ( ServerSocket endpoint = new ServerSocket(port) ) {
System.out.println("Local Port on which this socket is listening :"+port);
return port;
} catch (IOException e) {
port = ThreadLocalRandom.current().nextInt();
}
}
}
public static void systemConsole2File( File logFile ) {
try ( FileOutputStream fos = new FileOutputStream( logFile );
PrintStream system_console = new PrintStream( fos )
) {
System.setOut( system_console ); // output stream.
System.setErr( system_console ); // error output stream.
} catch (IOException e) {
e.printStackTrace();
}
}
Appium log with endpoints from the node where script is executed:
<?-- APPIUM_NODEJS_LISTENING_PORT = 4723 SERVERS <--port, --callback-port 4723>
Mobile « http://127.0.0.1:4723/wd/hub
Desktop « http://localhost:4444/wd/hub
-->
[36minfo[39m: Appium REST http interface listener started on 127.0.0.1:1750
[36minfo[39m: [debug] Non-default server args:
{
"address":"127.0.0.1",
"port":1750,
"bootstrapPort":7119,
"sessionOverride":true,
"log":"D:\\Yash\\MyConsole_TA64301YVY.txt",
"chromeDriverPort":7115
}
<?-- LIST OF CONNECTED DEVICES [UDID]
Unique device identifier of the connected physical device
To connect specific named device in the list of connected devices use UDID
-->
[36minfo[39m: [debug] Trying to find a connected android device
[36minfo[39m: [debug] Getting connected devices...
[36minfo[39m: [debug] executing cmd: D:\Android\sdk\platform-tools\adb.exe devices
[36minfo[39m: [debug] 2 device(s) connected
[36minfo[39m: Found device TA64301YVY
[36minfo[39m: [debug] Setting device id to TA64301YVY
<?--
BOOTSTRAP = 4724 Socket tcp port to use on device to talk to Appium
« Forwarding system:4724 to device:4724 appium bootstrap to device
-->
[36minfo[39m: [debug] Forwarding system:7119 to device:4724
[36minfo[39m: [debug] executing cmd: D:\Android\sdk\platform-tools\adb.exe -s TA64301YVY forward tcp:7119 tcp:4724
[36minfo[39m: [debug] Pushing appium bootstrap to device...
<?--
Chrome debugger server to connect to, in the form of <hostname/ip:port>
CHROME_DRIVER = 9515 Port upon which ChromeDriver will run
-->
[36minfo[39m: Chromedriver: Spawning chromedriver with: C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=7115
[36minfo[39m: Chromedriver: [STDOUT] Starting ChromeDriver 2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a) on port 7115
APPLICATION URL:
[36minfo[39m: JSONWP Proxy: Proxying [POST /wd/hub/session/SESSION-ID/url] to [POST http://127.0.0.1:7115/wd/hub/session/SESSION-ID/url] with body: {"url":"http://www.w3schools.com/"}
[36minfo[39m: JSONWP Proxy: Got response with status 200: {"sessionId":"SESSION-ID","status":0,"value":null}
WEB ELEMENT:
[36minfo[39m: JSONWP Proxy: Proxying [POST /wd/hub/session/SESSION-ID/element] to [POST http://127.0.0.1:7115/wd/hub/session/SESSION-ID/element] with body: {"using":"xpath","value":"//body/div[4]/div[1]/div[1]/a[1]"}
[36minfo[39m: JSONWP Proxy: Got response with status 200: {"sessionId":"SESSION-ID","status":0,"value":{"ELEMENT":"0.39628730167672455-1"}}
WEB ELEMENT & ACTION:
[36minfo[39m: JSONWP Proxy: Proxying [POST /wd/hub/session/SESSION-ID/element/0.39628730167672455-1/click] to [POST http://127.0.0.1:7115/wd/hub/session/SESSION-ID/element/0.39628730167672455-1/click] with body: {"id":"0.39628730167672455-1"}
[36minfo[39m: JSONWP Proxy: Got response with status 200: {"sessionId":"SESSION-ID","status":0,"value":null}
I need help with setting up ChromeDriver in Selenium WebDriver.
I have downloaded the latest version of ChromeDriver and added the path to the exe to my PATH environment variable.
However, when I try to run any scripts they fail on the line
driver = new ChromeDriver();
An instance of Chrome opens with a black screen and the address set as "data;," and I get a popup stating:
"Chrome Automation Extension has crashed".
Continuing from that point, I get the following exception details:
unknown error: unable to discover open pages
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 61.19 seconds
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
As I say, I've got the latest version of ChromeDriver and I have checked that Chrome is currently running the latest version so I know it isn't an issue with outdated versions of either.
I'm sure it must be something simple which I'm overlooking, but I just can't think what. Does anyone have any ideas?
Edit
Here's the log for the case, where Capability is not passed as a variable:
[0.885][INFO]: COMMAND InitSession {
"desiredCapabilities": {
"browserName": "chrome",
"chromeOptions": {
"args": [ ],
"extensions": [ ]
},
"platform": "ANY",
"version": ""
}
}
[0.886][INFO]: Populating Preferences file: {
"alternate_error_pages": {
"enabled": false
},
"autofill": {
"enabled": false
},
"browser": {
"check_default_browser": false
},
"distribution": {
"import_bookmarks": false,
"import_history": false,
"import_search_engine": false,
"make_chrome_default_for_user": false,
"show_welcome_page": false,
"skip_first_run_ui": true
},
"dns_prefetching": {
"enabled": false
},
"profile": {
"content_settings": {
"pattern_pairs": {
"https://*,*": {
"media-stream": {
"audio": "Default",
"video": "Default"
}
}
}
},
"default_content_setting_values": {
"geolocation": 1
},
"default_content_settings": {
"geolocation": 1,
"mouselock": 1,
"notifications": 1,
"popups": 1,
"ppapi-broker": 1
},
"password_manager_enabled": false
},
"safebrowsing": {
"enabled": false
},
"search": {
"suggest_enabled": false
},
"translate": {
"enabled": false
}
}
[0.889][INFO]: Populating Local State file: {
"background_mode": {
"enabled": false
},
"ssl": {
"rev_checking": {
"enabled": false
}
}
}
[0.936][INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-background-networking --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --load-extension="C:\Users\Rory\AppData\Local\Temp\scoped_dir10152_5411\internal" --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12607 --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\Rory\AppData\Local\Temp\scoped_dir10152_31299" data:,
[61.070][INFO]: RESPONSE InitSession unknown error: unable to discover open pages
I want to run my selenium tests on different browsers based on the browser name set in the Properties file.
I have a method named as initiateDriver() in which I get the browser name as set in the Properties file(valid values being ff, chrome or ie) and do the necessary settings for each of the web driver type. This method will return a WebDriver object to my methods.
public WebDriver initiateDriver()
{
// Created webdriver instance
WebDriver _drv = null;
String IEDriverPath, ChromeDriverPath;
try
{
//Get the Browser Name set in the properties file
String browserType = loadPropertiesFile("BrowserName");
Log4j.logger.warn("Browser name-----------"+browserType);
//Test if the browser is IE
if (browserType.equalsIgnoreCase("ie"))
{
//Currently, IEDriverServer.exe is copied on to Drivers folder of framework
IEDriverPath= "\\Drivers\\IEDriverServer.exe";
//Set the required properties to instantiate IE driver. Place any latest IEDriverServer.exe files under Drivers folder
System.setProperty("webdriver.ie.driver", IEDriverPath);
DesiredCapabilities cap= new DesiredCapabilities();
cap.setCapability("ignoreProtectedModeSettings", true);
_drv = new InternetExplorerDriver(cap);
}
//Check if BrowserType is set to Firefox
else if (browserType.equalsIgnoreCase("ff") || browserType.equalsIgnoreCase("firefox"))
{
//Getting the default Firefox with some settings
FirefoxProfile fp = new FirefoxProfile();
fp.setAcceptUntrustedCertificates(false);
//setting the Firefox preference "auto upgrade browser" to false and to prevent compatibility issues
fp.setPreference("app.update.enabled", false);
_drv = new FirefoxDriver();
}
//Check if BrowserType is set to Chrome
else if (browserType.equalsIgnoreCase("chrome"))
{
//Currently, chromedriver.exe is copied on to Drivers folder of framework
ChromeDriverPath= "\\Drivers\\chromedriver.exe";
//Set the required properties to instantiate Chrome driver. Place any latest Chromedriver.exe files under Drivers folder
System.setProperty("webdriver.chrome.driver", ChromeDriverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
_drv= new ChromeDriver(options);
}
else
{
Reporter.log("Invalid browser name. Please check the Resources/PropertiesLocation.properties file.");
System.out.println("Invalid browser name. Please check the Resources/PropertiesLocation.properties file.");
System.exit(0);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
Reporter.log("Enter valid browser name---");
System.exit(0);
}
return _drv;
}`
I am calling this method in the following class.
public class SmokeTest1
{
WebDriver d;
#BeforeClass
public void setUp() throws Exception
{
d = gm.initiateDriver();
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void firstSmokeTest() throws Exception
{
loginTest(d);
}
}
I am running my tests via ant build.xml file. However I am getting error as -
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure."
Can somebody suggest what is going wrong or am I missing anything?