Selenium NullPointerException错误,即第二个测试类未初始化AndroidDriver,因为它';It’第一堂课考得很好
这是我的设置类: 公共类设置类{Selenium NullPointerException错误,即第二个测试类未初始化AndroidDriver,因为它';It’第一堂课考得很好,selenium,automation,nullpointerexception,appium-android,testng-eclipse,Selenium,Automation,Nullpointerexception,Appium Android,Testng Eclipse,这是我的设置类: 公共类设置类{ //AppiumDriver<MobileElement> driver; AndroidDriver<MobileElement> d; public Properties prop =null; public File file; public FileInputStream fis; @Parameters(value ="Android") @BeforeSuite public void setup(String Androi
//AppiumDriver<MobileElement> driver;
AndroidDriver<MobileElement> d;
public Properties prop =null;
public File file;
public FileInputStream fis;
@Parameters(value ="Android")
@BeforeSuite
public void setup(String Android) throws IOException, Exception{
LoadPropertiesFile();
DesiredCapabilities caps = new DesiredCapabilities();
/*caps.setCapability("plateformName", "Android");
caps.setCapability(CapabilityType.PLATFORM_NAME, "Android");*/
if (Android.equalsIgnoreCase("Moto_g4_Plus")) {
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0");
caps.setCapability(MobileCapabilityType.UDID, "ZY223WZSQ9");
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Moto G4 Plus");
}
caps.setCapability("app", "C:\\Users\\amarjeet.sharma\\eclipse-workspace\\com.asm.app\\src\\test\\resources\\app\\asmVisit.apk");
caps.setCapability("appPackage", "com.sumasoft.net.asmscheduler");
caps.setCapability("appActivity", "md5f32326382a711c73d2de951d70f3bd5e.MainActivity");
caps.setCapability("autoGrantPermissions", true);
URL url;
try {
url = new URL("http://127.0.0.1:4723/wd/hub");
//driver = new AppiumDriver<MobileElement>(url, caps);
d = new AndroidDriver<MobileElement>(url, caps);
Thread.sleep(5000);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("Cause is:" +e.getCause());
System.out.println("Message is:" +e.getMessage());
e.printStackTrace();
}
}
public void LoadPropertiesFile() throws IOException {
prop=new Properties();
file =new File(System.getProperty("user.dir")+"/src/main/resources/config.properties");
fis=new FileInputStream(file);
prop.load(fis);
//System.out.println(prop.getProperty("userId"));
}
//@AfterTest
public void TearDown() throws IOException{
System.out.println("Quit");
d.quit();
}
}
这是我的“创建新旅程”课程
公共类AddJourneyTest扩展了SetupClass{
@Test(priority = 1)
public void login() throws Exception {
LoginPage lp = new LoginPage(d);
//System.out.println(prop.getProperty("userId"));
lp.userName(prop.getProperty("userId"));
Thread.sleep(500);
lp.password(prop.getProperty("Passwd"));
Thread.sleep(500);
lp.loginButton();
}
@Test(priority=2)
public void AddNewJourney() throws Exception {
AddjourneyPage addobj = new AddjourneyPage(d);
addobj.ClicktoAdd();
addobj.SelectFromToDate();
addobj.SelectState();
addobj.SelectCity();
addobj.ClickonSubmit();
}
}
我收到AddTourney类的NullPointerException
我认为当我以TestNG的形式运行它时,驱动程序就会启动LoginTest并保持控制。这样AddTourney类就不会启动驱动程序,从而获得NullPointerException。
我正在使用Appium Server,Java+Selenium+TestNG在带有物理Android设备的Windows系统上实现Android应用程序自动化。
也许我错了。但我并没有解决这个问题。请提供帮助。您能提供异常的堆栈跟踪吗?addNewTourney java.lang.NullPointerException位于org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:103)org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:92)org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:79)在java.util.ArrayList.forEach(未知源)的tests.AddJourneyTest.AddNewTourney(AddJourneyTest.java:11)的pages.AddjourneyPage.(AddjourneyPage.java:25)。。。已删除27堆栈帧扫描您还可以显示
AddjourneyPage
。另外,请不要在注释中添加代码或异常。而是相应地更新您的问题。AddJourneyPage的对象是在AddJourneyTest中创建的。我刚刚为类public AddjourneyPage(AndroidDriver d){this.d=d;System.out.println(“Test1:=”+d);PageFactory.initElements(d,this.d);}LoginTest调用LoginPage,LoginTest扩展了SetupClass。类似地,AddJourneyTest调用AddJourneyPage,AddJourneyTest还扩展了SetupClass。在SetupClass中,setup方法被注释为@BeforeSuit,其余的则出现在上述代码中。所以我不明白我错在哪里了。