HtmlElementDecorator(驱动程序)中的不兼容类型错误

时间:2016-01-15 07:19:47

标签: java htmlelements

我开始研究Yandex Html Elements框架。我根据开始指南https://github.com/yandex-qatools/htmlelements-examples/blob/master/htmlelements-junit-example/src/site/junit-example.md

并在开始时停止

public class MainPage {

private WebDriver driver;

@FindBy(className = "b-morda-search-form")
private SearchArrow searchArrow;

public MainPage(final WebDriver driver) {
    PageFactory.initElements(new HtmlElementDecorator(driver), this);
    this.driver = driver;
}

public SearchPage searchFor(String request) {
    this.searchArrow.searchFor(request);
    return new SearchPage(driver);
}
}

线

 PageFactory.initElements(new HtmlElementDecorator(driver), this);

创建错误

  

错误:(26,59)java:不兼容的类型:org.openqa.selenium.WebDriver   无法转换为   ru.yandex.qatools.htmlelements.pagefactory.CustomElementLocatorFactory

它的作用只有这样:

PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this);

为什么呢?

我正在使用IDEA 15 Ultimate,Java 8

POM-文件:

<project xmlns="http://maven.apache.org/POM/4.0.0"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

<groupId>vasidizus</groupId>
<artifactId>Autotest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Autotest</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
</dependency>

<dependency>
  <groupId>ru.yandex.qatools.htmlelements</groupId>
  <artifactId>htmlelements-java</artifactId>
  <version>1.15</version>
</dependency>

<dependency>
  <groupId>ru.yandex.qatools.htmlelements</groupId>
  <artifactId>htmlelements-matchers</artifactId>
  <version>1.15</version>
</dependency>

<dependency>
  <groupId>ru.yandex.qatools.matchers</groupId>
  <artifactId>webdriver-matchers</artifactId>
  <version>1.2</version>
</dependency>

<dependency>
  <groupId>ru.yandex.qatools.matchers</groupId>
  <artifactId>common-matchers</artifactId>
  <version>1.2</version>
</dependency>

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>2.48.2</version>
</dependency>

</dependencies>
</project>

先谢谢

1 个答案:

答案 0 :(得分:0)

public HtmlElementDecorator(CustomElementLocatorFactory factory) {
       this.factory = factory;
}

所以基本上HtmlElementDecorator的构造函数只接受CustomElementLocatorFactory,因此&#34;不兼容的类型&#34;错误。

仅供参考,而不是

PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this);

您也可以使用

HtmlElementLoader.populatePageObject(this, driver);