serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
722 stars 518 forks source link

[Question] Difference of methods in Open class #2750

Open ldt0589 opened 2 years ago

ldt0589 commented 2 years ago

I use Serenity-screenplay-webdriver 3.1.1 I see that Open class has a lot method like: ` public static OpenPage browserOn(PageObject targetPage) { return new OpenPage(targetPage); }

public static Open browserOn() {
    return new Open();
}

public static OpenUrl url(String targetUrl) {
    return new OpenUrl(targetUrl);
}

public static OpenAt relativeUrl(String targetUrl) {
    return new OpenAt(targetUrl);
}

public Interaction the(PageObject targetPage) {
    return new OpenPage(targetPage);
}

public Interaction thePageNamed(String pageName) {
    return new OpenPageWithName(pageName);
}

public Interaction the(Class<? extends PageObject> targetPageClass) {
    return new OpenPageFromClass(targetPageClass);
}`

I'm confused about methods. Could you tell me the differentce of methods:

Thanks in advance

globalworming commented 2 years ago

afaik Open.browserOn() is for giving you a fluent API when using Page Objects Open.browserOn().the(...). There are different ways to definde the url of a page, see https://serenity-bdd.github.io/theserenitybook/latest/page-objects.html#_opening_the_page Open.url and relativeUrl do what it says. They will open a url (using webdriver.get). One takes an absolute url, the other one relative to the current url.

ldt0589 commented 2 years ago

afaik Open.browserOn() is for giving you a fluent API when using Page Objects Open.browserOn().the(...). There are different ways to definde the url of a page, see https://serenity-bdd.github.io/theserenitybook/latest/page-objects.html#_opening_the_page Open.url and relativeUrl do what it says. They will open a url (using webdriver.get). One takes an absolute url, the other one relative to the current url.

Thanks for answer. Could you give the more detail for relativeUrl. How to use this method ?

globalworming commented 2 years ago

given you are on https://example.com/ you could open Open.url("https://example.com/about/") or Open.relativeUrl("about/") to achieve the same thing

You can also move upwards the path. like given you are on https://www.iana.org/domains/root, and open relative url ../reserved, the resulting url would be https://www.iana.org/domains/reserved

ldt0589 commented 2 years ago

given you are on https://example.com/ you could open Open.url("https://example.com/about/") or Open.relativeUrl("about/") to achieve the same thing

You can also move upwards the path. like given you are on https://www.iana.org/domains/root, and open relative url ../reserved, the resulting url would be https://www.iana.org/domains/reserved

So using Open.relativeUrl("about/") to open page. But i don't know how to call the host https://example.com OR where do we save host?

globalworming commented 2 years ago

check https://serenity-bdd.github.io/theserenitybook/latest/page-objects.html#_opening_the_page @DefaultUrl or just hard code the host public static String HOST = "https://example.com"