yandex-qatools / htmlelements

Html Elements is a Java framework providing easy-to-use way of interaction with web-page elements in web-page tests.
Other
271 stars 116 forks source link

Blocks as nested class throw InstantiationException #8

Open dmakhno opened 12 years ago

dmakhno commented 12 years ago

Used version: 1.9-Snapshot

Sorry for scala syntax... however.

Works fine:

//First class citizen
class EnvironmentBlock extends HtmlElement {
  @FindBy(className="js-navigate")
  var nameEl:Link = null
  @FindBy(className="js-environment-item-edit")
  var editEl:Link = null
  @FindBy(className="js-environment-item-delete")
  var deleteEl:Link = null

  def Name = nameEl.getText
}

abstract class EnvironmentsPage {
  @FindBy(className="environment-item")
  var environments:java.util.List[EnvironmentBlock] = null
}

Doesn't work

abstract class EnvironmentsPage {

  //!!!here EnvironmentBlock is nested!!!
  class EnvironmentBlock extends HtmlElement {
    @FindBy(className="js-navigate")
    var nameEl:Link = null
    @FindBy(className="js-environment-item-edit")
    var editEl:Link = null
    @FindBy(className="js-environment-item-delete")
    var deleteEl:Link = null

    def Name = nameEl.getText
  }

  @FindBy(className="environment-item")
  var environments:java.util.List[EnvironmentBlock] = null
}

Throws on

val environmentsPage = {
    val page = new EnvironmentsPage { val driver = ... }
    HtmlElementLoader.populatePageObject(page, driver)
    page
  }

Log

[info]   ru.yandex.qatools.htmlelements.exceptions.HtmlElementsException: java.lang.InstantiationException: XXX.EnvironmentsPage$EnvironmentBlock
[info]   at ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementFactory.createHtmlElementInstance(HtmlElementFactory.java:37)
[info]   at ru.yandex.qatools.htmlelements.loader.decorator.proxyhandlers.HtmlElementListNamedProxyHandler.invoke(HtmlElementListNamedProxyHandler.java:40)

If this quite technical limitation for now (according to my limited knowledge of nested classes), it would be good to notice that on start page, because error log is confusing.

P.S. It would be nice to notice that on Read.me that List are supported aswell P.P.S. I didn't get when and why I should use @Name anotation

AlexanderTolmachev commented 12 years ago

The quick solution is to make nested class static.

dmakhno commented 11 years ago

ok, thanks. unfortunately scala has no native nested class static. any workaround won't reduce code amount, thus will leave as first class citizens.