当我尝试实例化AndroidDriver类时,它会发出错误。请帮忙。
代码
import io.appium.java_client.android.AndroidDriver;
public class Testing {
@Test
public void testMethod() {
AndroidDriver driver;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "samsung-sm_g530h-5554c610");
cap.setCapability("platformVersion", "4.4.4");
cap.setCapability("platformName", "Android");
cap.setCapability(CapabilityType.BROWSER_NAME, "");
cap.setCapability("appPackage", "com.whatsapp");
cap.setCapability("appActivity", "com.whatsapp.HomeActivity");
driver = new AndroidDriver(new URL("127.0.0.1:4723"), cap);
}
}
答案 0 :(得分:1)
它给出了一个错误:AndroidDriver是Raw类型。您可以按如下方式初始化驱动程序:
var uri = '/localhost:8080////app//user/login.json?foo=bar';
var sanitizedUri = uri.replace(/\.json.*/, '');
console.log(sanitizedUri)
答案 1 :(得分:1)
我之前也遇到过这个问题,但我现在已经解决了,这个问题的原因是因为Java - client-(版本号)。 jar不兼容,所以我将Java - client-(版本号)。 jar替换成Java - 客户端 - 3.1.0。 Jar.Hope能够帮助你!
答案 2 :(得分:1)
尝试更换:
driver = new AndroidDriver(new URL("127.0.0.1:4723"), cap);
使用:
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
答案 3 :(得分:0)
您收到此错误,因为AppiumDriver现在是Generic,因此可以将其设置为返回类MobileElement或IOSElement或AndroidElement的元素而不进行强制转换。
此更改在Java客户端3.0及更高版本中引入。可以找到详细信息here
此外,应用包,应用活动和设备名称足以运行测试。因此,您可以将代码修改为:
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class Testing {
AndroidDriver<MobileElement> driver;
@Test
public void testMethod() {
DesiredCapabilities caps = new DesiredCapabilities() ;
caps.setCapability(MobileCapabilityType.DEVICE_NAME,"samsung-sm_g530h-5554c610");
caps.setCapability(MobileCapabilityType.APP_PACKAGE, "com.whatsapp");
caps.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.whatsapp.HomeActivity");
driver = new AndroidDriver<MobileElement>(new URL ("http://127.0.0.1:4723/wd/hub"),caps);
}
}
答案 4 :(得分:0)
以下是初始化Androidriver的正确方法:
import re
import csv
import time
import io
print(time.ctime())
input_name = "C:/Users/User/Desktop/File with No Extension That's Very Similar to CSV"
output_name = "C:/Users/User/Desktop/testoutput.csv"
with open(input_name, 'r') as f_input, open(output_name, 'wt') as f_output:
# Read whole file in
all_input = f_input.read()
# Extract interesting lines
ab_input = re.findall(r'Point A(.*?)Point B', all_input, re.DOTALL)[0]
# Convert into a file object and parse using the CSV reader
fab_input = io.StringIO(ab_input)
csv_input = csv.reader(fab_input)
csv_output = csv.writer(f_output)
# Iterate a row at a time from the input
for input_row in csv_input:
# Skip any empty rows
if input_row:
# Write row at a time to the output
csv_output.writerow(input_row)
print(time.ctime())
以上代码将成功在模拟器上启动amazon应用程序。