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

Selenide tries to decorate SelenideElement without @FindBy annotation even if it is already initialized in ElementsContainer #617

Closed
CaBocuk opened this Issue Oct 6, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@CaBocuk

CaBocuk commented Oct 6, 2017

The problem

Selenide tries to decorate SelenideElement without @findby annotation even if it is already initialized in ElementsContainer

Details

I have SelenideElement without @findby which is already initialized with $(...) method. It is situated inside ElementsContainer which is declared in some page object -> then try to instantiate PO using page(Page.class) or open(url, Page.class) -> Selenide tries to decorate my SelenideElement despite it is already instantiated.

Similar issue was already fixed for decorating such fields which are declared directly in PO (#443)
It was solved by using com.codeborne.selenide.SelenidePageFactory instead of default org.openqa.selenium.support.PageFactory.

But it wasn't changed for ElementsContainer's elements initializing in method
com.codeborne.selenide.impl.SelenideFieldDecorator#initElementsContainer(Class<?> type, SelenideElement self).
It still uses default PageFactory.initElements(...) instead of SelenidePageFactory.initElements(...) which checks whether field is already initialized or not

Tell us about your environment

  • Selenide Version: 4.7.1
  • Chrome\Firefox\IE Version: Chrome 61.0.3163.100 but I think it's not browser-dependent
  • Browser Driver Version: Automatically downloaded by Selenide :)
  • Selenium Version: 3.5.3
  • OS Version: Win 10

Code To Reproduce Issue

public class Tmp {

    public static void main(String... args){
        Configuration.browser = "chrome";
        Page page = Selenide.open("http://selenide.org/", Page.class);
        page.whatIsSelenideBlock.title.shouldHave(Condition.text("What is Selenide?"));
    }

    public static class Page{
        @FindBy(xpath="(//div[@class='wrapper-color-content'])[1]") // xpath is just 4 fun :)
        Block whatIsSelenideBlock;
    }

    public static class Block extends ElementsContainer{
        SelenideElement title = $("h3");
        SelenideElement arrowDown = $("img");
    }
}

Error log:

Exception in thread "main" Element not found {by id or name "title"}
Expected: text 'What is Selenide?'
Screenshot: file:/C:/Users/Artsem_Savosik/IdeaProjects/epam-events-autotests/build/reports/tests/1507303101755.0.png
Page source: file:/C:/Users/Artsem_Savosik/IdeaProjects/epam-events-autotests/build/reports/tests/1507303101755.0.html
Timeout: 4 s.
Caused by: NoSuchElementException: no such element: Unable to locate element: {"method":"name","selector":"title"}
	at com.codeborne.selenide.impl.WebElementSource.createElementNotFoundError(WebElementSource.java:31)
	at com.codeborne.selenide.impl.ElementFinder.createElementNotFoundError(ElementFinder.java:82)
	at com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:59)
	at com.codeborne.selenide.commands.Should.should(Should.java:35)
	at com.codeborne.selenide.commands.Should.execute(Should.java:29)
	at com.codeborne.selenide.commands.Should.execute(Should.java:12)
	at com.codeborne.selenide.commands.Commands.execute(Commands.java:143)
	at com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:87)
	at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:63)
	at com.sun.proxy.$Proxy4.shouldHave(Unknown Source)
	at com.epam.events.common.run.Tmp.main(Tmp.java:13)

CaBocuk pushed a commit to CaBocuk/selenide that referenced this issue Oct 8, 2017

CaBocuk pushed a commit to CaBocuk/selenide that referenced this issue Oct 8, 2017

CaBocuk pushed a commit to CaBocuk/selenide that referenced this issue Oct 8, 2017

Artsem Savosik Artsem Savosik
selenide#617: Changed PageFactory to SelenidePageFactory in ElementsC…
…ontainer's elements initialization. Added a test

@asolntsev asolntsev self-assigned this Oct 22, 2017

@asolntsev asolntsev added this to the 4.9 milestone Oct 22, 2017

asolntsev added a commit that referenced this issue Oct 22, 2017

Merge pull request #618 from CaBocuk/#617-Fix-ElementsContainer-with-…
…initialized-elements

#617 fix: Changed PageFactory to SelenidePageFactory in ElementsContainer's fields initialization

@asolntsev asolntsev added the bug 🐛 label Oct 22, 2017

@asolntsev

This comment has been minimized.

Show comment
Hide comment
@asolntsev

asolntsev Oct 22, 2017

Contributor

Fix by PR #618. Will be released in Selenide 4.9

Contributor

asolntsev commented Oct 22, 2017

Fix by PR #618. Will be released in Selenide 4.9

@asolntsev asolntsev closed this Oct 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment