我是新来的蚀者。我正在尝试在Android设备上开始Appium测试。我的首选:
因此,在安装,配置Appiumserver,Android SDK,Android设备管理器后-下一步是开始在Eclipse IDE中进行测试,我在定义URL时遇到问题,不知道该怎么做。 jar文件:
仅此而已
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();}
}
答案 0 :(得分:0)
我建议您使用Maven项目及其依赖项: java-client , selenium-java 和 testng 。
如果您不想使用Maven项目,则需要在eclipse中导入上述库。为此,在Eclipse工作区中,右键单击左窗格中的项目->属性-> Java构建路径->添加jar->在此处添加jar。
按以下步骤更改代码:
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);
}
}
答案 1 :(得分:0)
解决此问题的方法是使用最新稳定的Selenium版本,即3.141.5
如果您正在使用Java项目,则在添加最新版本的jar之前,请确保首先删除所有与硒相关的旧jar,然后添加最新下载的jar版本以构建路径。
对于Maven项目,请将硒依赖版本更新为最新版本,然后在终端上运行,
$ mvn clean install