package android.appium;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.annotations.AfterTest;
import io.appium.java_client.AppiumDriver;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class SimpleTestCalc {
WebDriver driver;
@BeforeTest
public void setup () throws MalformedURLException {
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability("deviceName","ZX1PC2JJPM");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
capabilities.setCapability(CapabilityType.VERSION, "5.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.calculator");
URL url1=new URL("http://127.0.0.1:4723/wd/hub");
driver=new RemoteWebDriver(url1,capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
@Test
public void sum() {
driver.findElement(By.name("2")).click();
driver.findElement(By.name("5")).click();
driver.findElement(By.name("+")).click();
driver.findElement(By.name("5")).click();
driver.findElement(By.name("=")).click();
String result=driver.findElement(By.className("android.widget.EditText")).getText();
System.out.print("Sum of values is"+result);
}
@AfterTest
public void reset() {
driver.quit();
}
}
输出:
[TestNG]正在运行:
C:\用户\ vgaarlap.ORADEV \应用程序数据\本地\ TEMP \ TestNG的-蚀 - 1070157593 \ TestNG的-customsuite.xml
FAILED CONFIGURATION:@BeforeTest设置 org.openqa.selenium.SessionNotCreatedException:一个新的会话可以 不被创造。 (原始错误:'java -version'失败。错误:产生 ENOENT)(警告:服务器未提供任何堆栈跟踪 信息)命令持续时间或超时:149毫秒构建信息: 版本:'2.53.0',修订版:'35ae25b',时间:'2016-03-15 16:57:40' 系统信息:主机:'VGAARLAP-LAP',ip:'192.168.56.1',os.name: 'Windows 7',os.arch:'amd64',os.version:'6.1',java.version: '1.8.0_31'驱动程序信息:org.openqa.selenium.remote.RemoteWebDriver at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
答案 0 :(得分:0)
您需要在环境路径变量中添加system32位置。
%SystemRoot%system32
有关详细信息,请参阅以下链接:
https://discuss.appium.io/t/original-error-java-version-failed-error-spawn-enoent/3125