Skip to content

Commit

Permalink
Merge pull request #618 from CaBocuk/#617-Fix-ElementsContainer-with-…
Browse files Browse the repository at this point in the history
…initialized-elements

#617 fix: Changed PageFactory to SelenidePageFactory in ElementsContainer's fields initialization
  • Loading branch information
asolntsev committed Oct 22, 2017
2 parents bec8497 + 24191f6 commit 5fb6350
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.ElementsContainer;
import com.codeborne.selenide.SelenideElement;
import com.codeborne.selenide.SelenidePageFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.FindBys;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.Annotations;
import org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory;
import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;
Expand Down Expand Up @@ -75,7 +75,7 @@ private ElementsContainer initElementsContainer(Class<?> type, SelenideElement s
Constructor<?> constructor = type.getDeclaredConstructor();
constructor.setAccessible(true);
ElementsContainer result = (ElementsContainer) constructor.newInstance();
PageFactory.initElements(new SelenideFieldDecorator(self), result);
SelenidePageFactory.initElements(new SelenideFieldDecorator(self), result);
result.setSelf(self);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package integration;

import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.ElementsContainer;
import com.codeborne.selenide.SelenideElement;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.support.FindBy;

import static com.codeborne.selenide.CollectionCondition.texts;
import static com.codeborne.selenide.Condition.*;
import static com.codeborne.selenide.Selenide.*;

public class ElementsContainerWithManuallyInitializedFieldsTest extends IntegrationTest {

@Before
public void openTestPage() {
openFile("page_with_selects_without_jquery.html");
}

@Test
public void canInitializeElementsContainerFieldsWithoutFindByAnnotation() {
MyPage page = page(MyPage.class);

page.container.getSelf().should(exist, visible);
page.container.headerLink.shouldHave(text("Options with 'apostrophes' and \"quotes\""));
page.container.options.shouldHave(texts("-- Select your hero --", "John Mc'Lain", "Arnold \"Schwarzenegger\"",
"Mickey \"Rock'n'Roll\" Rourke"));
}


private static class MyPage {
@FindBy (css = "#apostrophes-and-quotes")
MyContainer container;
}

private static class MyContainer extends ElementsContainer {
SelenideElement headerLink = $("h2>a");
ElementsCollection options = $$("#hero>option");
}
}

0 comments on commit 5fb6350

Please sign in to comment.