2016-01-15 4 views
0

Я начал изучать структуру Yandex Html Elements. Я согласно руководству по началу работы https://github.com/yandex-qatools/htmlelements-examples/blob/master/htmlelements-junit-example/src/site/junit-example.mdОшибка несогласованных типов в HtmlElementDecorator (драйвер)

И останавливаться в начале

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); 

создать ошибку

Error:(26, 59) java: incompatible types: org.openqa.selenium.WebDriver cannot be converted to ru.yandex.qatools.htmlelements.pagefactory.CustomElementLocatorFactory

Это работает только так:

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

Почему?

Я использую IDEA 15 Максимальная, Java 8

ПОМ-файл:

<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> 

Благодаря передовой

ответ

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

Так в основном конструктор HtmlElementDecorator только принимает CustomElementLocatorFactory, следовательно, ошибка «несовместимых типов».

Просто FYI, вместо

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

вы также можете использовать

HtmlElementLoader.populatePageObject(this, driver); 
Смежные вопросы