Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks as nested class throw InstantiationException #8

Open
dmakhno opened this issue Dec 1, 2012 · 2 comments
Open

Blocks as nested class throw InstantiationException #8

dmakhno opened this issue Dec 1, 2012 · 2 comments
Assignees

Comments

@dmakhno
Copy link

dmakhno commented Dec 1, 2012

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
Copy link
Member

The quick solution is to make nested class static.

@dmakhno
Copy link
Author

dmakhno commented Dec 14, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants