htmlelements icon indicating copy to clipboard operation
htmlelements copied to clipboard

Blocks as nested class throw InstantiationException

Open dmakhno opened this issue 13 years ago • 2 comments

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

dmakhno avatar Dec 01 '12 19:12 dmakhno

The quick solution is to make nested class static.

AlexanderTolmachev avatar Dec 03 '12 11:12 AlexanderTolmachev

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

dmakhno avatar Dec 14 '12 13:12 dmakhno