如何在 Eclipse 中为 Appium Server 修复 URL 定义
How to fix URL definitions in Eclipse for Appium Server
我是 eclipse 新手。我正在尝试在 Android 设备上启动 Appium 测试。我的偏好:
- Appium 1.8.2
- jre1.8.0_191
- jdk1.8.0_191
- 日食 4.9.0
- TestNG
- Android工作室 3.2.1
- Android开发者工具
所以在安装之后,配置 Appiumserver,Android SDK,Android 设备管理器 - 下一步是在 Eclipse 中开始测试 IDE 我在定义 URL 并且不知道该怎么办。
jar 文件:
- java-client-6.1.0.jar
- gson-2.8.5.jar
- client-combined-3.9.0-sources.jar
- client-combined-3.9.0.jar
- seleium-3.9.0-nodeps-sources.jar
- seleium-3.9.0-nodeps.jar
- seleium-html-runner-3.9.0.jar
- seleium-server-standalone-3.9.0.jar
- TestNG
- JRE 系统库
就这些了
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class FirstScript {
private URL serverUrl;
public static AndroidDriver driver;
public String APPIUM_PORT = "4723";
@BeforeClass
public void setUp() throws MalformedURLException{
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Samsung S7");
caps.setCapability("udid", "******************"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.0");
caps.setCapability("appPackage", "com.***.***");
caps.setCapability("appActivity", "com.***.***.MainActivity");
caps.setCapability("noReset", "true");
try {
serverUrl = new URL("http://127.0.0.1:4723/wd/hub");
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver = new AndroidDriver (serverUrl,caps);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
@Test
public void testExample() {***}
@AfterClass
public void tearDown() {driver.closeApp();}
}
Running debug for this code with error
Server is working
I suggest you to use maven project and the dependencies: java-client, selenium-java and testng.
如果不想使用maven项目,需要在eclipse中导入以上库。为此,在您的 Eclipse 工作区中,右键单击左窗格中的项目 -> 属性 -> Java 构建路径 -> 添加 Jars -> 在那里添加你的 jars。
按如下方式更改您的代码:
public class FirstScript {
public static AppiumDriver<MobileElement> driver;
@BeforeClass
public void setUp() throws MalformedURLException{
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Samsung S7");
caps.setCapability("udid", "******************"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.0");
caps.setCapability("appPackage", "com.***.***");
caps.setCapability("appActivity", "com.***.***.MainActivity");
caps.setCapability("noReset", "true");
driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"),caps);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
}
您的问题的解决方案是您使用最新稳定版本的 Selenium,即 3.141.5
如果您有 Java 项目,那么在添加新的最新版本的 jar 之前,请确保首先删除所有与 selenium 相关的旧 jar,然后将新下载的 jar 版本添加到构建路径。
如果是 Maven 项目,请将 selenium 依赖项版本更新为最新版本,并在终端上更新 运行,
$ mvn clean install
我是 eclipse 新手。我正在尝试在 Android 设备上启动 Appium 测试。我的偏好:
- Appium 1.8.2
- jre1.8.0_191
- jdk1.8.0_191
- 日食 4.9.0
- TestNG
- Android工作室 3.2.1
- Android开发者工具
所以在安装之后,配置 Appiumserver,Android SDK,Android 设备管理器 - 下一步是在 Eclipse 中开始测试 IDE 我在定义 URL 并且不知道该怎么办。 jar 文件:
- java-client-6.1.0.jar
- gson-2.8.5.jar
- client-combined-3.9.0-sources.jar
- client-combined-3.9.0.jar
- seleium-3.9.0-nodeps-sources.jar
- seleium-3.9.0-nodeps.jar
- seleium-html-runner-3.9.0.jar
- seleium-server-standalone-3.9.0.jar
- TestNG
- JRE 系统库
就这些了
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class FirstScript {
private URL serverUrl;
public static AndroidDriver driver;
public String APPIUM_PORT = "4723";
@BeforeClass
public void setUp() throws MalformedURLException{
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Samsung S7");
caps.setCapability("udid", "******************"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.0");
caps.setCapability("appPackage", "com.***.***");
caps.setCapability("appActivity", "com.***.***.MainActivity");
caps.setCapability("noReset", "true");
try {
serverUrl = new URL("http://127.0.0.1:4723/wd/hub");
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver = new AndroidDriver (serverUrl,caps);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
@Test
public void testExample() {***}
@AfterClass
public void tearDown() {driver.closeApp();}
}
Running debug for this code with error
Server is working
I suggest you to use maven project and the dependencies: java-client, selenium-java and testng.
如果不想使用maven项目,需要在eclipse中导入以上库。为此,在您的 Eclipse 工作区中,右键单击左窗格中的项目 -> 属性 -> Java 构建路径 -> 添加 Jars -> 在那里添加你的 jars。
按如下方式更改您的代码:
public class FirstScript {
public static AppiumDriver<MobileElement> driver;
@BeforeClass
public void setUp() throws MalformedURLException{
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Samsung S7");
caps.setCapability("udid", "******************"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.0");
caps.setCapability("appPackage", "com.***.***");
caps.setCapability("appActivity", "com.***.***.MainActivity");
caps.setCapability("noReset", "true");
driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"),caps);
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
}
您的问题的解决方案是您使用最新稳定版本的 Selenium,即 3.141.5
如果您有 Java 项目,那么在添加新的最新版本的 jar 之前,请确保首先删除所有与 selenium 相关的旧 jar,然后将新下载的 jar 版本添加到构建路径。
如果是 Maven 项目,请将 selenium 依赖项版本更新为最新版本,并在终端上更新 运行,
$ mvn clean install