现象:
有时在第一处 driver.tap() 处报错,有时在另一处 driver.tap() 处报错,虽然报错,但是在测试机上确实执行了点击操作。不过也有几次执行成功了,这是什么原因?
测试环境:真机 LenovoA850 Android 4.2.2 + Appium v1.4.16
测试 APP:http://pan.baidu.com/s/1jHKmtJC
import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.WebElement;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
public class TestCase1 {
private AppiumDriver<WebElement> driver;
@Before
public void setup() throws Exception{
File classpathroot = new File(System.getProperty("user.dir"));
File appdir = new File(classpathroot,"apps");
File app = new File(appdir,"memory_V1.2.2_code12_RC_dsj_T_1013_1.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Lenovo A850");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app",app.getAbsolutePath());
capabilities.setCapability("appPackage","com.eeark.memory");
capabilities.setCapability("appActivity","com.eeark.memory.ui.StartActivity");
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
}
@Test
public void Login() throws Exception{
Thread.sleep(5000);
driver.findElementByName("登录/注册").click();
List<WebElement> lis_log = driver.findElementsByClassName("android.widget.EditText");
WebElement Phone_log = lis_log.get(0);
Phone_log.sendKeys("13000000002");
WebElement Phone_Password = lis_log.get(1);
Phone_Password.sendKeys("1");
List<WebElement> Lis_log_Bt = driver.findElementsByName("登录");
WebElement Log_Bt = Lis_log_Bt.get(1);
Log_Bt.click();
Thread.sleep(5000);
int click_x_0 = driver.manage().window().getSize().width;
int click_y_0 = driver.manage().window().getSize().height;
int x_click0 = 270 * click_x_0 / 540;
int y_click0 = 75 * click_y_0 / 960;
driver.tap(1, x_click0, y_click0, 1000);//一般在这里报错
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
int click_x_1 = driver.manage().window().getSize().width;
int click_y_1 = driver.manage().window().getSize().height;
int x_click1 = 270 * click_x_1 / 540;
int y_click1 = 910 * click_y_1 / 960;
driver.tap(1, x_click1, y_click1, 1000);//有时在这里报错
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
driver.findElementByName("照片故事").click();
Thread.sleep(1000);
List<WebElement> Lis_ChioceP_IV = driver.findElementsByClassName("android.widget.ImageView");
WebElement ChickPicture = Lis_ChioceP_IV.get(1);
ChickPicture.click();
Thread.sleep(1000);
List<WebElement> Lis_ChioceP_TV = driver.findElementsByClassName("android.widget.TextView");
WebElement ChioceAlbum = Lis_ChioceP_TV.get(0);
ChioceAlbum.click();
List<WebElement> Lis_ChioceAlbum = driver.findElementsByClassName("android.widget.ImageView");
WebElement Album = Lis_ChioceAlbum.get(1);
Album.click();
ChickPicture.click();
driver.findElementByName("继续").click();
Thread.sleep(1000);
driver.findElementByName("留下你的故事吧……").sendKeys("AppiumTest");
Thread.sleep(1000);
driver.findElementByName("确定").click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElementByName("android.widget.ImageView");
Thread.sleep(1000);
List<WebElement> Details = driver.findElementsByClassName("android.widget.ImageButton");
WebElement Back_Bt = Details.get(0);
Back_Bt.click();
Thread.sleep(10000);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
> org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
> Command duration or timeout: 1.05 seconds
> Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
> System info: host: 'PC-20160719GTYP', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
> Driver info: io.appium.java_client.android.AndroidDriver
> Capabilities [{app=D:\java-neon\workspace\AppiumTest\apps\memory_V1.2.2_code12_RC_dsj_T_1013_1.apk, appPackage=com.eeark.memory, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=0123456789ABCDEF, platform=LINUX, appActivity=com.eeark.memory.ui.StartActivity, desired={app=D:\java-neon\workspace\AppiumTest\apps\memory_V1.2.2_code12_RC_dsj_T_1013_1.apk, appPackage=com.eeark.memory, appActivity=com.eeark.memory.ui.StartActivity, platformVersion=4.4.2, browserName=, platformName=Android, deviceName=Lenovo A850}, platformVersion=4.2.2, webStorageEnabled=false, locationContextEnabled=false, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
> Session ID: 4cd7f431-fc5e-4c70-9d2e-814604eff68d
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
> at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
> at java.lang.reflect.Constructor.newInstance(Unknown Source)
> 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:40)
> 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.performTouchAction(AppiumDriver.java:336)
> at io.appium.java_client.MultiTouchAction.perform(MultiTouchAction.java:71)
> at io.appium.java_client.AppiumDriver.tap(AppiumDriver.java:374)
> at com.memory.appium.TestCase1.Login(TestCase1.java:64)
> 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)