我正在尝试使用junitcumber建立框架,但是每次我在页面类中扩展以使用driver.findelements时,每次驱动程序都返回null
。
package core;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
public class DriverFactory {
protected static AndroidDriver<MobileElement> driver;
public void createdriver() throws MalformedURLException
{
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "MS OnePlus7");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9");
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
cap.setCapability(MobileCapabilityType.APP, "C:\\framework\\src\\test\\Resources\\APK\\Telegram.apk");
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);
cap.setCapability(MobileCapabilityType.NO_RESET, true);
cap.setCapability(MobileCapabilityType.UDID, "62afbd2d");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}
}
package pages;
import org.openqa.selenium.By;
import core.DriverFactory;
public class telegrampage extends DriverFactory {
public void openhome()
{
System.out.println("driver is returning "+driver);
driver.findElement(By.xpath("//android.widget.FrameLayout[@content-desc='New Message']"));
}
}
有人可以指导我为什么我从DriverFactory继承时得到“空”
答案 0 :(得分:0)
使用createdriver()
方法之前,您需要先调用driver.findElement()
方法。
将您的openhome()
方法更改为:
public void openhome()
{
DriverFactory driverFactory = new DriverFactory();
driverFactory.createdriver();
System.out.println("driver is returning "+driver);
driver.findElement(By.xpath("//android.widget.FrameLayout[@content-desc='New Message']"));
}