Hi all,
I was trying to switch to the web view. But, it doesn’t happen due to casting problems…could you please help me out??
Below is my code.
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class mani {
AppiumDriver driver;
@BeforeTest
public void setUp() throws MalformedURLException {
DesiredCapabilities cap= new DesiredCapabilities();
System.out.println("change");
// cap.setCapability(“automationName”, “Selendroid”);
// cap.setCapability(“device”, “Selendroid”);
cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);
cap.setCapability("browserName", "Android");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4");
cap.setCapability(MobileCapabilityType.APP_PACKAGE, "gsm.eyc.com");
cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "gsm.eyc.com.GSMActivity");
driver = (AppiumDriver) new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”), cap);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
@Test
public void Sum() {
// WebDriverWait wait=new WebDriverWait(driver, 10);
// wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“gsm.eyc.com:id/username”)));
// driver.findElement(By.id(“Continue”));
WebDriverWait wait=new WebDriverWait(driver, 10);
// driver.findElement(By.name(“New Releases”)).click();
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
}
}
}
@AfterTest
public void End() {
driver.quit();
}
}
Output:
[TestNG] Running:
C:\Users\inmreddy02\AppData\Local\Temp\testng-eclipse-90740821\testng-customsuite.xml
change
FAILED CONFIGURATION: @BeforeTest setUp
java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to io.appium.java_client.AppiumDriver
at mani.setUp(mani.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
SKIPPED CONFIGURATION: @AfterTest End
SKIPPED: Sum
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@7c30a502: 87 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@7e0ea639: 10 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@3ac3fd8b: 61 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@71be98f5: 8 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@511baa65: 8 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 15 ms