Actually I need to use RemoteWebDriver Method only as new RemoteWebDriver(new URL(āhttp://127.0.0.1:4723/wd/hub/ā), capabilities);
as working on a framework which can be used to run both Android and IOS apps using RemoteWebDriver is only way to make it generic is there a way to type cast RemoteWebDriver as AndroidDriver
@BeforeClass setUp
java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to io.appium.java_client.android.AndroidDriver
Hello, Iām facing the same issue. Here is what Iām doing in my code.
Creating a page in which declaring driver as RemoteDriver.
Calling a function where again Iām declaring a driver as RemoteDriver.
Running a test where Iām declaring driver as RemoteDriver.
Trying to access the AppiumDriver method in my test method.
My question is, where should I cast this method? My driver initialization is in common function. Also where should I declare androiddriver publicly and where should I declare remotedriver privately.
This is Java. If you initialize something (using the ānewā keyword to call a classās constructor to initialize the object), the type of that object will always be whatever class whose constructor you used to initialize the object. That is, if you use RemoteWebDriverās constructor, then the driver object will always be a RemoteWebDriver object.
You can always cast up the class inheritance tree. e.g. casting the RemoteWebDriver object reference into a WebDriver or Object reference. Casting down the inheritance tree will require that the type youāre casting to be the same type or a parent type of the object. If you initialize something as a RemoteWebDriver, then you can not cast it down to an AndroidDriver, IOSDriver, nor AppiumDriver, as the object was not initialized as one of the child types.
If you want to use an AndroidDriver, IOSDriver, or AppiumDriver, then you have to set up your driver object at the very beginning during its construction. You can not change an object type once the object is already created (at least not in Java). If you want generality for both your Android and iOS tests, then you will also have to determine whether youāll be running on an iOS or Android test at the beginning of your test runs. If this can not be done with your current framework, then youāll have to redesign your framework.
Now I want to use Tap method which serve by AppiumDriver*******
But here below code not work with Remote web driver so I need to create the driver for AppiumDriver or iOSDriver
Thanks for detailed answer. Currently Iām designing framework and still has below queries, can you please clarify
which scenario do you use RemoteWebDriver or AppiumDriver ?
Once device OS is found as Android or iOS then we can directly create respective driver type. Iām not sure if there is any particular need for step 1 driver types.
I am facing the same issue so i tried with your code. But for me it is not working simply throwing null pointer exception at very 1st Remote WebElement it self.
Could you please review my code and guide me in proper way.
@Test
public void setUp() throws Exception {
DesiredCapabilities Capabilities = new DesiredCapabilities();
Capabilities.setCapability("deviceName", "Android");
Capabilities.setCapability("browserName", "Android");
Capabilities.setCapability("platformVersion", "6.0");
Capabilities.setCapability("platformName", "Android");
Capabilities.setCapability("appPackage", "PATH");
Capabilities.setCapability("appActivity", "PATH");
androidDriver = new AndroidDriver(new URL("http://127.0.0.1:4444/wd/hub"), Capabilities);
driver = androidDriver;
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.xpath("//*[@text='Skip to find your library or school now']"));
Error Line => driver.findElement(By.xpath("//*[@text='Skip to find your library or school now']")).click();
WebDriverWait Wait = new WebDriverWait(driver, 10);
Wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='Welcome to Axis 360!']")));
WebElement input = driver.findElement(By.xpath("//*[@text='Search for My Library']"));
You can try it
1:-First of all Initialize this variable as
private AndroidDriver androidDriver;
2:-then cast the RemoteWebDriver as
androidDriver=(AndroidDriver) new RemoteWebDriver(new URL(āhttp://127.0.0.1:4723/wd/hubā),
capabilities);