public class QRProductActivityPageObject {
public static void testProductDetail() throws InterruptedException {
ActivityTestRule<ProductInfoActivity> rule = new ActivityTestRule<ProductInfoActivity>(ProductInfoActivity.class, true, false);
Intent intent = new Intent();
intent.setClass(getActivity(), ProductInfoActivity.class);
rule.launchActivity(intent);
Thread.sleep(2000);
}
}
上述語法顯示您無法在靜態方法中訪問getActivity()的錯誤。 但我想通過靜態方法調用這個新的Activity(ProductInfoActivity)。任何建議?在靜態方法中使用getActivity()
添加上下文到您的功能:''testProductDetail(上下文CTX)''和使用''intent.setClass(CTX,ProductInfoActivity.class);'' –