I want to user driver.removeapp({bundleID}); command in my appium script BUT IDE NOT suggesting this method even I've imported io.appium.java_client.*;
You need to double check the declaration of your driver variable:
public AppiumDriver driver;
driver = new IOSDriver(appiumURL, capabilities);
driver.removeApp(bundleId);
Related
Executing simple class
Enter code here
package lesson1;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Brf {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver(); //Launches Firefox Browser with blank url
driver.get("http://www.gcrit.com/build3/admin/login.php");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin#123");
driver.findElement(By.id("tdb1")).click();
String url = driver.getCurrentUrl();
if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Login Successful -Passed");
}
else
{
System.out.println("Login Unsuccessful -Failed");
}
driver.close(); //Closes the Browser
}
}
Getting the error:
Error on simple class in selenium webdrive:
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:335)
You are getting this error because you haven't set the path of gecko driver in your code.
Please set the path of gecko driver before creating a new instance of Firefox driver.
System.setProperty("webdriver.gecko.driver"," Path to geckodriver");
WebDriver driver = new FirefoxDriver();
Need to add driver path, if you are using selenium jars above 3.0 , if you are using selenium jars below 3.0 your code is good to go, but i guess you are using selenium jars above 3.0
Public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver"," Path to geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gcrit.com/build3/admin/login.php");
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin#123");
driver.findElement(By.id("tdb1")).click();
String url = driver.getCurrentUrl();
if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Login Successful -Passed");
}
else
{
System.out.println("Login Unsuccessful -Failed");
}
driver.close(); //Closes the Browser
}
The cause of the error is that you don't have a proper setup for detection of a GeckoDriver file named "geckodriver.exe" (this prevents you from being able to open Firefox with your program). In case you don't have such a file, you can download one h̲e̲r̲e̲ (I suggest getting the latest version).
With such a file, you can carry out one of the following two procedures to rectify your problem:
Method 1
Add the path of the folder containing the "geckodriver.exe" file to your PATH environment variable value (instructions on how to modify this variable value can be seen h̲e̲r̲e̲).
Method 2
Prepend the body of your main method with the following statement (where GECKODRIVER_PATH represents the path of the "geckodriver.exe" file):
System.setProperty("webdriver.gecko.driver", "GECKODRIVER_PATH");
Set the gecko driver path which is initialise the firefox driver.
I have a maven-powered Robot-framework project in java that uses selenium 3.4.0 dependency, robotframework 3.0.2 dependency, markusbernhardt's selenium2library version 1.4.0.8, and robotframework-maven-plugin version 1.4.7.
My robot tests live in the src/main/test/robotframework/acceptance folder, while in src/main/java/mypackage I created a Customized.java file to set a system property for the browser driver path (I then import this library in my tests:
*** Settings ***
Library Selenium2Library
Library mypackage.Customized
This works perfectly. But now I'd like to implement my own keywords to extend Selenium2Library. But I'm not sure how to obtain the current WebDriver instance that is running.
I mean, if I weren't using Robot and just plain Selenium, I'd do something like this:
WebDriver driver=new ChromeDriver();
driver.doSomething();
However, in this case I don't want to instantiate a new WebDriver but instead get the one that is currently running (which Robot automatically instantiated). How can I do that?
I've so far created a Selenium2Library object and set it with the value returned by Selenium2Library.getLibraryInstance(); but that's not giving me access to selenium's methods (e.g.: getCurrentUrl() is not listed).
in python it can be done with following code
from robot.libraries.BuiltIn import BuiltIn
def _browser(self):
return BuiltIn().get_library_instance('Selenium2Library')._current_browser()
Actually, I found a solution, but I'm not sure it's the right approach:
public class Customized {
private static Selenium2Library s;
private BrowserManagement b;
private WebDriver driver;
public Customized() throws ScriptException {
try {
Customized.s = (Selenium2Library) Selenium2Library.getLibraryInstance();
} catch (javax.script.ScriptException e) {
e.printStackTrace();
}
b = s.getBrowserManagement();
driver=b.getCurrentWebDriver();
}
}
Now the selenium methods are available from the driver object. However, there might be a better way to do it, as there's this message in the javax.script.ScriptException exception: "Access restriction: The type 'ScriptException' is not API (restriction on required library 'C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar')"
For newer Selenium version (4.0) the following snippet can be used:
class SelCustomLib():
def get_browser_driver(self):
return BuiltIn().get_library_instance('SeleniumLibrary').driver
Getting the following error
Exception in thread "main" java.lang.IllegalStateException: The driver
executable does not exist:
/Users/Golcha/Desktop/Automation/geckodriver.exe
Code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class selenium{
private static WebDriver driver;
public static void main(String[]args){
System.setProperty("webdriver.gecko.driver","Users/Golcha/Desktop/Automation/geckodriver.exe");
setDriver(new FirefoxDriver());
}
public static WebDriver getDriver() {
return driver;
}
public static void setDriver(WebDriver driver) {
selenium.driver = driver;
}
}
Try below code but check the path of geckodriver properly before executing the below code or I ll suggest you to paste geckodriver in C drive or any other drives to make your path simple as below one :
System.setProperty("webdriver.firefox.marionette", "C:\\geckodriver.exe");
It should work without any problem . All the best !
I thing you have not mentioned the complete(full) path for the Geckodriver in your System.setProperty() method. you have missed the drive letter "C"
"C:/Users/Golcha/Desktop/Automation/geckodriver.exe"
Let me know if this solved your problem.
I had a similar problem but weirdly I was not able to execute the selenium script on both my drivers (chrome and firefox), I tried checking my setProperty method, my gecko driver path and chrome driver path. Lastly, I tried updating both my browser and it seems to be working now. (my current version of Chrome is 66 and my current version of my Firefox is 56.0).
I want to write couple of tests for a web page with Selenium and jUnit4, but I can't figure out how to make Firefox open the URL I need. Without System.setProperty(...) I'm getting Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. and browser never opens. Yet if I implement it the browser does open on a default start "new page", but the line driver = new FirefoxDriver(); and further never executes.
Below is the simplest code version of what I'm trying to achieve:
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Main {
static String URL = "http://www.google.com";
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
//Following code never executes
driver = new FirefoxDriver();
//I'm not sure if this is how I'm supposed to open URL, but I never had this code executed.
driver.get(URL);
driver.quit();
}
}
UPDATED:
These links were helpful to solve the problem of proper geckodriver installation.
https://github.com/mozilla/geckodriver/releases
http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3/
Actually you need to set geckodriver.exe path instead of firefox.exe in this
System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
So just replace geckodriver.exe path and try
I have added following jars in my projects build path:
java-client-2.0.0 from http://appium.io/downloads.html >> Appium Client libraries >> Java
selenium-java-2.43.1
selenium-java-2.43.1-srcs
selenium-server-standalone-2.43.1
and here's my code:
public class SampleApp{
WebDriver dr;
#Test
public void testApp() throws MalformedURLException, InterruptedException {
String apkpath = "D:\\apkdump\\sampleapp.apk";
File app = new File (apkpath);
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
capabilities.setCapability("deviceName","TestADB18");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app",app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.test");
capabilities.setCapability("appActivity", "com.sampleapp.Main");
dr = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
}
I am getting red line below new AppiumDriver which says that Cannot instantiate the type AppiumDriver. Now if remove all selenium jars the error disappears but then I can't resolve errors with webdriver.What is the conflict between jars?
I saw similar question here but that could run the code and was getting Null pointer exception but in my case I cant even run it, it is giving run on saving the code. Secondly the answer has been posted without using AppiumDriver
You don't need to downgrade or anything. There is a design change in the Java Client version 2.0.0 as they mention on their site:
AppiumDriver is now an abstract class, use IOSDriver and AndroidDriver which both extend it.
So, just change your driver line to be:
dr = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
Hope that helps...
This error can be fixed by downgrading the Appium Client(see step 1 in my question) from latest to java-client-1.5.0. You can keep rest of the jars to latest.
Downgraded version of Appium Client can be downloaded from here http://mvnrepository.com/artifact/io.appium/java-client/1.5.0
WebDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),getDesiredCapabilities("192.21.168.56:5555"));
use this. and import:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
dr=new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
proper URL to be established
for appium version 1.7 use capability
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
while for v1.8.1
its not needed