My app is the Hybrid App (not the Native App).So to change the context from native to Hybrid,I have created the instance of Android driver.After three swaps,I want change the context.So I used driver.context(contextList.get(1)); As far as I know ,the error is coming because of the above line only.Any alternative to this??
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
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.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class App {
@Test
public void test_1() throws MalformedURLException, InterruptedException {
// TODO Auto-generated method stub
DesiredCapabilities capa = new DesiredCapabilities();
capa.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capa.setCapability(MobileCapabilityType.DEVICE_NAME, "DeviceID");
capa.setCapability("udid", "DeviceID");
capa.setCapability("appPackage", "packagenamegiven");
capa.setCapability("appActivity", "packagenamegiven.MainActivity");
AndroidDriver driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capa);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement me = driver.findElement(By.className("android.webkit.WebView"));
int wide = me.getSize().width;
int hgt = me.getSize().height;
int startx = (int) (wide * (0.8));
int endx = (int) (wide * (0.2));
int starty = hgt / 2;
int endy = hgt / 2;
driver.swipe(startx, starty, endx, endy, 1000);
// 2nd Screen
me = driver.findElement(By.className("android.webkit.WebView"));
wide = me.getSize().width;
hgt = me.getSize().height;
startx = (int) (wide * (0.8));
endx = (int) (wide * (0.2));
starty = hgt / 2;
endy = hgt / 2;
driver.swipe(startx, starty, endx, endy, 1000);
// 3rd Screen
me = driver.findElement(By.className("android.webkit.WebView"));
wide = me.getSize().width;
hgt = me.getSize().height;
startx = (int) (wide * (0.8));
endx = (int) (wide * (0.2));
starty = hgt / 2;
endy = hgt / 2;
driver.swipe(startx, starty, endx, endy, 1000);
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
Set<String> allContexts = driver.getContextHandles();
allContexts.stream().forEach(x -> System.out.println(x));
ArrayList<String> contextList = (ArrayList<String>) allContexts.stream().collect(Collectors.toList());
driver.context(contextList.get(1));
System.out.println("Present context is :"+driver.getContext());
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.quit();
System.out.println("Test is Successful");
}
}
Output/Exception coming is
NATIVE_APP WEBVIEW_packagenamegiven FAILED: test_1 org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Failed to start Chromedriver session: A new session could not be created. (Original error: session not created exception: Chrome version must be
= 60.0.3112.0 (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.10.0-42-generic x86_64)) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 4.06 seconds Build info: version: '2.50.1', revision: 'd7fc91b29de65b790abb01f3ac5f7ea2191c88a7', time: '2016-01-29 11:11:26' System info: host: 'about-system-info', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.10.0-42-generic', java.version: '1.8.0_131' Driver info: io.appium.java_client.android.AndroidDriver Capabilities [{appPackage=packagename, deviceScreenSize=720x1280, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=EP732287GB, platform=LINUX, deviceUDID=EP732287GB, appActivity=packagename.MainActivity, desired={appPackage=packagename, appActivity=packagename.MainActivity, platformName=Android, udid=deviceId, deviceName=DeviceId}, platformVersion=5.0.2, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, javascriptEnabled=true, deviceModel=C5502, platformName=Android, udid=deviceId, deviceManufacturer=Sony}] Session ID: 02bd3479-850b-4cfb-a541-360a2117cf0f at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at io.appium.java_client.AppiumDriver.context(AppiumDriver.java:546) at package_name.App.test_1(App.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) 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:1198) at org.testng.TestNG.runSuitesLocally(TestNG.java:1123) at org.testng.TestNG.run(TestNG.java:1031) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================