Skip to content

Instantly share code, notes, and snippets.

@asolntsev
Last active May 1, 2020 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asolntsev/bf4b0ac648c50ed6dfdaf334a6f36912 to your computer and use it in GitHub Desktop.
Save asolntsev/bf4b0ac648c50ed6dfdaf334a6f36912 to your computer and use it in GitHub Desktop.
import com.codeborne.selenide.SelenideElement;
import org.junit.jupiter.api.Test;
import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
public class PageObjectWithoutContainersTest {
@Test
void containersUsage() {
HistoryPage page = new HistoryPage();
page.shouldHaveRecords(8);
page.record(1).status().shouldHave(text("Booked"))
page.showMore();
page.shouldHaveRecords(42);
page.record(41).status().shouldHave(text("Overbooked"))
}
static class HistoryPage {
public void showMore() {
$(byText("SHOW MORE")).click();
}
public void shouldHaveRecords(int expectedRecordsCount) {
$$("div[id^='bookingRef-']").shouldHave(size(expectedRecordsCount));
}
public BookingRecord record(int index) {
return new BookingRecord($("div[id^='bookingRef-']", index));
}
}
static class BookingRecord {
private final SelenideElement container;
public BookingRecord(SelenideElement container) {
this.container = container;
}
public SelenideElement pickupTime() {
return container.$("div[id^='bookingPickupTime-']");
}
public SelenideElement status() {
return container.$("span[id^='bookingStatusTag-'] > span");
}
public void openRecord() {
container.$("img[id^='bookingId-']").click();
}
}
}
@vinogradoff
Copy link

Nice one!
Please add smth like:

page.record(1).status().shouldHave(text("Booked"))

to make our point more clear :)

@asolntsev
Copy link
Author

done

@ansonliao
Copy link

ansonliao commented Apr 18, 2020

Hi @asolntsev, @vinogradoff

If I need to separate page and element into two classes, for Seleninde, how I can initialize the page and the element? for example:

HistoryPO.java

public class HistoryPO {
    public SelenideElement showMore = $(byText("SHOW MORE"));

    public ElementsCollection = $$("div[id^='bookingRef-']");

    static class BookingRecord {
        private final SelenideElement container;

        public BookingRecord(SelenideElement container) {
            this.container = container;
        }

        public SelenideElement pickupTime() {
            return container.$("div[id^='bookingPickupTime-']");
        }

        public SelenideElement status() {
            return container.$("span[id^='bookingStatusTag-'] > span");
        }

        public void openRecord() {
            container.$("img[id^='bookingId-']").click();
        }
    }
}

HistoryPage.java

public class HistoryPage {
   // how to integrate the HistoryPO.java and initialize the element here

}

because the so many elements in the page, if placing elements into the page, the page Java class will be hundreds and thousands line of code, so we need to separate the element and page into different classes.

Thanks very much

@ansonliao
Copy link

@asolntsev, @vinogradoff
or could you provide some contact information so that I can consult you more convenient? telegram, skype, slack of Selenide, Gitter for Selenide project, or others.

Thanks.

@asolntsev
Copy link
Author

asolntsev commented Apr 22, 2020 via email

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