问题描述
作为练习的一部分,我尝试使用 AndroidDriver 和 startActivity()
方法切换应用活动。当我运行测试时,我在手机上看到所需的应用程序启动但随后崩溃并出现以下异常:
org.openqa.selenium.WebDriverException:未知错误(未知 发生服务器端错误。状态='假'。未能完成 内部方法:'startActivity 参数: [com.shivgadhia.android.ukMortgageCalc, com.shivgadhia.android.ukMortgageCalc.MainActivity, com.shivgadhia.android.ukMortgageCalc, com.shivgadhia.android.ukMortgageCalc.MainActivity,空,空,空, null,true,10000]',详细信息:无法启动活动。等待 com.shivgadhia.android.ukMortgageCalc/.MainActivity 失败后 超时)(警告:服务器没有提供任何堆栈跟踪 信息)
我的代码是:
protected AndroidDriver<AndroidElement> driver;
@BeforeClass
public void setUp() throws MalformedURLException {
dc.setCapability(MobileCapabilityType.UDID,"LMG710EM210b0b9a");
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,"com.example.android.apis");
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,".ApiDemos");
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"),dc);
}
@Test
public void Test03_startActivity(){
driver.tap(1,driver.findElement(By.xpath("//*[@text='Views']")),500);
driver.startActivity("com.shivgadhia.android.ukMortgageCalc",".MainActivity");
driver.tap(1,driver.findElement(By.xpath("//*[@text='Rate']")),500);
}
最后一行代码未执行,测试失败并出现上述异常。在网上搜索,找不到任何解决方案。可能是什么问题?
解决方法
您可能无法在您的设备上轻松开始任何活动。 在通过 Appium 之前,先通过 adb 试一试:
// props is just what I receive for GET post by id endpoint and it contains 'isSaved' field
const [isProductSaved,setIsProductSaved] = useState(props?.isSaved);
const isProductSavedRef = useRef(props?.isSaved);
isProductSavedRef.current = isProductSaved;
useEffect(() => {
return () => {
if (isProductSavedRef.current && product.id) {
const saveUnsaveProduct = async () => {
// Request to backend
const response = await toggleSaveUnsaveProduct(product?.id);
console.log(response);
};
saveUnsaveProduct();
}
};
},[product?.id]);
如果它不起作用,它也不会与 Appium 一起工作。
我还建议检查 docs 以解决问题