【发布时间】:2016-01-06 03:04:26
【问题描述】:
我在执行程序以使用 Appium 向下滑动屏幕时遇到错误。
虽然代码适用于向右或向左滑动,但在向下滑动屏幕时出现错误。
这几天我几乎要撞到头了。请帮忙。我已附上代码和错误消息供您查看。
提前致谢。
代码:-
public class SwipeScreen {
AndroidDriver dr;
@Test
public void testApp() throws MalformedURLException, InterruptedException{
DesiredCapabilities capabilities = new DesiredCapabilities("appWaitActivity", null, null);
File app =new File(System.getProperty("user.dir")+"\\app\\net.one97.paytm (1).apk");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "android");
capabilities.setCapability("deviceName","samsung-gt_i9060-42035bec4397 c000");
capabilities.setCapability("PlatformVersion","4.2.2");
capabilities.setCapability("PlatformName","Android");
capabilities.setCapability("app",app.getAbsolutePath());
// capabilities.setCapability("appPackage","com.android.settings");
// capabilities.setCapability("appActivity","com.android.settings.SettingsTabActivity");
dr = new AndroidDriver(new URL("http://192.168.10.165:4723/wd/hub"),capabilities);
dr.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
Thread.sleep(50000);
System.out.println(dr.manage().window().getSize().getWidth());
System.out.println(dr.manage().window().getSize().getHeight());
int screenWidth = dr.manage().window().getSize().getWidth();
int screenHeight = dr.manage().window().getSize().getHeight();
//Swipe Right
int startx = screenWidth*8/9;
int endx = screenWidth/9;
int starty = screenHeight/2;
int endy = screenHeight/2;
dr.swipe(startx, starty, endx, endy, 5000);
Thread.sleep(50000);
//Swipe Left
startx = screenWidth/9;
endx = screenWidth*8/9;
starty = screenHeight/2;
endy = screenHeight/2;
dr.swipe(startx, starty, endx, endy, 5000);
Thread.sleep(50000);
//swipe down
startx = screenWidth/2;
endx = screenWidth/2;
starty = screenHeight*6/7;
endy = screenHeight/5;
dr.swipe(startx, starty, endx, endy, 10000);
Thread.sleep(50000);
//swipe up
startx = screenWidth/2;
endx = screenWidth/2;
starty = screenHeight/6;
endy = screenHeight*5/6;
dr.swipe(startx, starty, endx, endy, 5000);
}
}
错误:-
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session.
Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:58'
System info: host: 'Halcyon2-PC', ip: '192.168.140.172', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_67'
Driver info: driver.version: AndroidDriver
【问题讨论】:
-
你能确保你的appium服务器正在运行吗?错误说它无法访问 appium 服务器
-
> info: [debug] [BOOTSTRAP] [debug] 从 [x=240.0, y=685.0] 滑动到 [x=240.0, y=160.0] 步骤:280 > info: [debug ] [BOOTSTRAP] [debug] 返回结果:{"value":"刷卡没有成功完成","status":13} > info: [debug] 响应客户端错误:{"status":13," value":{"message":"处理命令时发生未知的服务器端错误。","origValue":"滑动未成功完成"},"sessionId":"8074bc5f-24b3-47b1-b6f8- e2343f941817"}
标签: android selenium-webdriver appium