Launching application using Appium - selenium

I have used the following code to launch an app. I didn't get any error log in Appium but application has not been launched.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.whatsapp");
capabilities.setCapability("appActivity", "com.whatsapp.Main");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.quit();
Please advice

at the start you need to add this it is path of apk file
File app=new File("C:/Users/Administrator/Downloads/Appium/Appium/node_modules/appium/apk/app-release-2.0.apk");

Related

How to launch IE browser using selenium webdriver 3.4.0

How to launch IE browser using selenium webdriver 3.4.0? I have tried, but unable to open an IE browser. I have downloaded IE Driver and followed the same like launching firefox driver.
Launching of Firefox browser is working fine, below are command lines
System.setProperty("webdriver.gecko.driver","C:\\Users\\vidhya.r\\Desktop\\Automation\\Jars\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver(options);
Download IEDriverServer, put it to path or use
System.setProperty("webdriver.ie.driver", ieDriverPath);
launch via
driver = new InternetExplorerDriver();
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capability.setCapability(InternetExplorerDriver.ELEMENT_SCROLL_BEHAVIOR, 1);
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
System.setProperty("webdriver.ie.driver", ieDriverPath);
WebDriver driver = new InternetExplorerDriver(capability);
First download IEDriver from this Link
Use this:
System.setProperty("webdriver.ie.driver", "Path of IE driver");
WebDriver driver = new InternetExplorerDriver();
If you want to add some capabilities then use DesiredCapabilities

How to handle untrusted certificate in firefox using Selenium Web Driver?

I'm facing some issues while handling "Untrusted Certificate" in firefox.
We can't use FirefoxDriver(new FirefoxProfile) as it is deprecated
I used the following code but couldn't achieve it.
FirefoxProfile profile=new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
FirefoxOptions options=new FirefoxOptions().setProfile(new FirefoxProfile());
WebDriver driver=new FirefoxDriver(options);
driver.get("Web Link");
Could anyone suggest me the solution to achieve in Selenium 3.
Try this in Firefox
DesiredCapabilities handlSSLErr = DesiredCapabilities.firefox ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new FirefoxDriver (handlSSLErr);
driver.get("Your URL link");
For chrome
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ();
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new ChromeDriver (handlSSLErr);
driver.get("Your URL link");
Below works fine for me
DesiredCapabilities cap = new DesiredCapabilities().merge(DesiredCapabilities.firefox());
cap.acceptInsecureCerts();
FirefoxDriver driverF = new FirefoxDriver(cap);
driverF.get("https://expired.badssl.com/");

Relaunch browser via Selenium remote webdriver after remote VM reboot

I'm running selenium scripts on remote VM via selenium remote webdriver where for each test i will be rebooting the VM. Below is the sample program used where the browser launch fails for the second after VM reboot.
WebDriver driver;
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability("platformVersion", "40.0.2");
capabilities.setCapability("platformName", "WINDOWS");
capabilities.setCapability("browserName", "firefox");
driver= new RemoteWebDriver(new URL("http://10.86.101.217:4444/wd/hub"), capabilities);
driver.quit();
// Rebooting the VM, Selenium server started after rebooting
Thread.sleep(200000);
System.out.println("end");
driver= new RemoteWebDriver(new URL("http://10.86.101.217:4444/wd/hub"), capabilities);
Thread.sleep(3000);
System.out.println("end 2");

getting error with chromedriver using RemoteWebdriver

Getting error:
FAILED CONFIGURATION: #BeforeMethod setUp
org.openqa.selenium.WebDriverException: The path to the driver
executable must be set by the webdriver.chrome.driver system property;
for more information, see
http://code.google.com/p/selenium/wiki/ChromeDriver. The latest
version can be downloaded from
http://chromedriver.storage.googleapis.com/index.html
My code :
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
+ "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On the above code chromedriver it self is not getting invoked.
Then i tried with code:
ChromeDriverService chromeService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
.usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On executing above code the executable is launched but chrome is not invoked. It throws the same error. Code is working fine for firefox. Any help please?
Download the relevant Chrome driver as per your system(32-bit/64-bit), from here . Try setting the property of ChromeDriver first, like this:
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Then use this code:-
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);
If there is no need of using "RemoteWebDriver", you can code just use this below :
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
Try below :
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");
driver = new ChromeDriver();
driver.get("www.google.com");
Put chrome driver in properties folder.

Unable to add desired capabilities for remote web driver

I am unable to compile my code when I try to add the following to enable selenium node on my machine.
URL hubUrl = new URL("");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setPlatform(Platform.LINUX);
RemoteWebDriver driver = new RemoteWebDriver(hubUrl, capabilities);
probably you forgot to add the Hub url.
Try this:
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
or another variant:
URL hubUrl = new URL("http://hubIP:hubPort/wd/hub");
DesiredCapabilities capability = DesiredCapabilities.firefox();
capabilities.setPlatform(Platform.LINUX);
RemoteWebDriver driver = new RemoteWebDriver(hubUrl, capabilities);