我无法使我的代码正常工作...我正在使用带有TestNG和黄瓜的Appium
这是我的基地.java
public class Base {
public AndroidDriver driver;
}
这是我的钩子.java
public class Hooks extends Base{
private Base base;
public Hooks (Base base) {
this.base = base;
}
@Before("@homeScreenTest")
public void init() throws MalformedURLException {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("no",true);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
cap.setCapability("platformVersion", "9");
cap.setCapability("platformName", "Android");
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "60");
cap.setCapability("noRest", true);
cap.setCapability("autoGrantPermissions",true);
cap.setCapability("appPackage","myPackage");
cap.setCapability("appWaitActivity", "myActivity");
File f = new File("src");
File fs = new File(f, "app");
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
base.driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
base.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
}
这是我的页面对象类语言选择.java
public class LanguageSelect extends Base{
public Base base;
public LanguageSelect (Base base) {
super();
this.base= base;
PageFactory.initElements(base.driver,this);
}
@AndroidFindBy(xpath = "//android.widget.Button[@text='SET LANGUAGE']")
public WebElement setLanguage;
}
最后这是我的步骤定义文件LandingScreenTest.java
public class LandingScreenTest extends Base{
private Base base;
public LandingScreenTest(Base base){
this.base = base;
}
@Then("^I click on button $")
public void i_click_on_something(String strArg1) throws Throwable {
LanguageSelect ls = new LanguageSelect(base);
ls.setLanguage.click();
}
}
现在按钮根本不点击,它就在那里,它是可见的,如果我在 LandingScreenTest.java 中写这个,它可以工作
WebElement setLng = base.driver.findElementByXPath("//android.widget.Button[@text='SET LANGUAGE']");
setLng.click();
但是如果我尝试使用页面对象,我会得到
"org.openqa.selenium.InvalidSelectorException: Locator Strategy 'name' is not supported for this session"
有时甚至没有初始化驱动程序。我已经挖掘了整个堆栈溢出和大量教程,但我就是无法正确理解。
我之所以将 Base 中的代码与 Hooks 中的代码分开.java.java是因为 Cucumber 不允许我使用注释扩展类。
我错过了什么?请帮忙
注意:我没有发布运行器类或功能文件,除了我尝试从页面对象类中获取对象外,一切正常。
我已经设法让它工作了。所以基本上在语言选择类而不是
public class LanguageSelect extends Base{
public Base base;
public LanguageSelect (Base base) {
super();
this.base= base;
PageFactory.initElements(base.driver,this);
}
我写了这个
public class LanguageSelect extends Base{
public LanguageSelect (AndroidDriver driver) {
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver),this);
}
它工作得很好,其他类中的其他一切都完全相同