在Mobile中测试计算器应用时,在通过Appium的日食中运行时出错。无法创建新的远程会话#13701我认为我已在Appium中正确设置了所有内容(当检查器启动时,设备已安装应用程序并且可以进行测试)作为项目收集者,我使用MavenUPD。我正在尝试使应用程序自动化。我在代码中指定了其他功能
包装TestCase;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;
public class CalculatorTest {
public static AppiumDriver<MobileElement> driver;
public static void main(String[] args) {
try {
openCalculator();
} catch (Exception e) {
System.out.println(e.getCause());
System.out.println(e.getMessage());
e.printStackTrace();
}
}
public static void openCalculator() throws MalformedURLException {
DesiredCapabilities caps= new DesiredCapabilities();
caps.setCapability("DEVICE_NAME", "6 Pro");
caps.setCapability("UDID", "0f74a4680405");
caps.setCapability("PLATFORM_NAME", "Android");
caps.setCapability("PLATFORM_VERSION", "9PKQ1.18");
caps.setCapability("appPackage", "com.miui.calculator");
caps.setCapability("appActivity", "com.miui.calculator.cal.CalculatorActivity");
URL url=new URL("http://127.0.0.1:4723/wd/hub");
driver=new AppiumDriver<MobileElement>(url,caps);
System.out.println("Application Started");
}
}
Error in console
java.lang.reflect.InvocationTargetException
Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: You must include a platformName capability (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 175 milliseconds
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:42:16'
System info: host: 'NAVEEN-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_221'
Driver info: driver.version: AppiumDriver
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:42:16'
System info: host: 'NAVEEN-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_221'
Driver info: driver.version: AppiumDriver
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: You must include a platformName capability (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 175 milliseconds
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:42:16'
System info: host: 'NAVEEN-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_221'
Driver info: driver.version: AppiumDriver
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:42:16'
System info: host: 'NAVEEN-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_221'
Driver info: driver.version: AppiumDriver
at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:336)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:88)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:98)
at TestCase.CalculatorTest.openCalculator(CalculatorTest.java:38)
at TestCase.CalculatorTest.main(CalculatorTest.java:18)
Caused by: java.lang.reflect.InvocationTargetException
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 io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)
... 13 more
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: You must include a platformName capability (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 175 milliseconds
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:42:16'
System info: host: 'NAVEEN-PC', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_221'
Driver info: driver.version: AppiumDriver
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:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:125)
... 18 more
您应该在camelCase中设置平台名称(android / ios):platformName
不是PLATFORM_NAME。
所以这是真正想要的功能:
caps.setCapability("deviceName", "6 Pro");
caps.setCapability("udid", "0f74a4680405");
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "9PKQ1.18");
\\ etc