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

switchToPage is deprecated. What should i use instead? #2131

Closed
v1-wizard opened this issue Jun 16, 2020 · 16 comments
Closed

switchToPage is deprecated. What should i use instead? #2131

v1-wizard opened this issue Jun 16, 2020 · 16 comments
Labels

Comments

@v1-wizard
Copy link
Contributor

Hi, i just decided to migrate from old Serenity-BDD version to new one. I found that switchToPage is deprecated. What should i use instead?

I also have a little proposal: could you create a comments with migration advises from deprecated methods in future?

Thanks. Have a nice day.

@ahmed-al-sadoon
Copy link

Same with me, i couldn't finde any reference on Internet

@wakaleo
Copy link
Member

wakaleo commented Jun 30, 2020

It looks like people are still using this method so I will un-deprecate it :-).

@ahmed-al-sadoon
Copy link

@wakaleo Thanks a lot :)

@mi-akram
Copy link

Has this been fixed? Seems like this is still an issue on version 2.3.4.

I have also checked this on version 2.3.12 and seems to be broken on this version too. I seem to be getting a NullPointerException when this is used:

java.lang.NullPointerException
at net.serenitybdd.core.pages.PageObject.switchToPage(PageObject.java:210)

@wakaleo
Copy link
Member

wakaleo commented Jan 21, 2021

No fix because it's intended to be deprecated.

@HajekOndrej
Copy link

No fix because it's intended to be deprecated.

Okay, but then the original question stands:) What should we use instead?

@wakaleo
Copy link
Member

wakaleo commented Feb 3, 2021

You don't need to use anything. Just use the page object (or locators) you want to use. What problem are you trying to solve?

@HajekOndrej
Copy link

You don't need to use anything. Just use the page object (or locators) you want to use. What problem are you trying to solve?

Right, I thought that may be the that. Okay, thanks :)

@Neetish1607
Copy link

Neetish1607 commented Apr 24, 2021

@wakaleo : I am using this as a workaround !
return pages.getPage(.class);
for serenity : 2.3.12 version and its working fine for me !

@wakaleo
Copy link
Member

wakaleo commented Apr 24, 2021

You can do that. But why do you need to return anything at all? Why not just use the page you expect to be displayed, rather than trying to bind your code to the structure of the application UI?

@Neetish1607
Copy link

with you on that !! I just thought that some people were looking for solution ! Had one so put it here !!
On a separate note I have one query : Trying to Run UI Tests on Jenkins on my Local with Chrome version 89 and serenity : 2.3.12!
Its not opening the Browser and its getting stuck right here :
Starting ChromeDriver 89.0.4389.23 (61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294}) on port 16121 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully.

Its gets stuck here for a long period of time and eventually i have to stop the jenkins run !
Running on windows my serenity.properties looks like this :

webdriver.driver=chrome
serenity.project.name=Demo project
webdriver.wait.for.timeout=10000
wedriver.timeouts.implicitlywait=5000
serenity.take.screenshots=FOR_EACH_ACTION
webdriver.base.url=http://localhost:8099
chrome.capabilities.acceptSslCerts = true
chrome.capabilities.handlesAlerts = true
chrome.switches=--allowed-ips

#serenity.driver.capabilities =
#serenity.use.unique.browser = false

And Serenity.conf looks like this :
drivers {
windows {
webdriver.chrome.driver = src/test/resources/drivers/windows/chromedriver.exe
webdriver.gecko.driver = src/test/resources/drivers/windows/geckodriver.exe
webdriver.ie.driver = src/test/resources/drivers/windows/IEDriverServer.exe
phantomjs.binary.path = src/test/resources/drivers/windows/phantomjs.exe
webdriver.edge.driver = src/test/resources/drivers/windows/MicrosoftWebDriver.exe
}
mac {
webdriver.chrome.driver = src/test/resources/drivers/mac/chromedriver
webdriver.gecko.driver = src/test/resources/drivers/mac/geckodriver
phantomjs.binary.path = src/test/resources/drivers/mac/phantomjs
}
linux {
webdriver.chrome.driver = src/test/resources/drivers/linux/chromedriver
webdriver.gecko.driver = src/test/resources/drivers/linux/geckodriver
}
}

Unable to find where is the gap !! Can you please help @wakaleo ?

@gigos85
Copy link

gigos85 commented Jul 27, 2021

You can do that. But why do you need to return anything at all? Why not just use the page you expect to be displayed, rather than trying to bind your code to the structure of the application UI?

Hello,
how do you manage the fact that you go from one page to another without the switchtopage or just open the destination page ? have you an example of page switching ?

Thanks for your help

@wakaleo
Copy link
Member

wakaleo commented Jul 27, 2021

Modeling navigation in your tests is a bit of an anti-pattern - what if you go to a different page? Just use the page that you expect to be visible.

@gigos85
Copy link

gigos85 commented Jul 28, 2021

Hello,

First of all, thanks for your reply. We are aligned with the fact that it's probably risky (with lik your test with sut). But in some case to validate behavior we need to go through more than one page object (more than one url). In this case, what is the best practice (and have you some examples).

thanks,

@wakaleo
Copy link
Member

wakaleo commented Jul 28, 2021

Just because you need to navigate through page objects doesn't mean your test automation code needs to hard-code this navigation. Consider the following steps (using the Action Classes pattern:

@Steps 
LoginSteps login;

@Steps  
NavigationSteps navigate;

@Steps 
ProductListSteps inTheProductList;

login.withValidCredentials()
navigate.to(TodaysDiscounts)
inTheProductList.selectTheFirstItem()
...

Each method will then access the UI elements it needs to do its job. You can group related UI locators into classes and call these Page Objects if you like. But you don't need to hard-code any navigation logic in your test code. For example:

class ProductListSteps extends UIInteractionSteps {
   
   @Step 
  public void selectTheFirstItem() {
    $(ProductList.FIRST_VISIBLE_ITEM).click();
  }

}
...
class ProductList {
    static By FIRST_VISIBLE_ITEM = By.cssSelector("...");
}

@gigos85
Copy link

gigos85 commented Aug 2, 2021

hello,

Thanks for you answer and your help.

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants