0

When trying to make the assertion "Does the current url equal homepage url?", should the current url logic be put directly into the test method. Like so, let currentUrl = browser.getCurrentUrl(); or can this logic be put into a page object like a home page.

To me it feels uncomfortable to ask a page object about the current url, if that url doesn't have anything to do with the page object itself. At the same time it is discouraged to put webdriver api calls directly in the test methods. How should I go about testing this type of logic?

m..
  • 329
  • 1
  • 2
  • 11

2 Answers2

0

If you feel uncomfortable with putting the logic about the url in a page object like a Hompage you can make a sperate page object for the URL field itself. It's what I also do for things like Headers wich appears on more than one page.

Frank
  • 831
  • 1
  • 11
  • 23
0

You can create a new function within the PageObject to get the current url through :

currentUrl = browser.getCurrentUrl();

But for Assertion it's better to create a new module and pass the currentUrl as a parameter.

You can find a detailed discussion in Selenium Java PageFactory Design : Where do I write my Assertions following Page Object Model

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • The linked answer was useful but it doesn't quite answer this. See updated post above. – m.. Mar 19 '18 at 01:10
  • @m.. Of-coarse you have changed your question and added 1) _Cucumber_ related code trials 2) _cucmber_ `` to your question after receiving effective Answers as per your actual Question which is against all the best practices on StackOverflow. Please consider reverting back your question and Accept if any Answer have catered to your actual Question and feel free to raise a new Question as per your new requirement. StackOverflow volunteers will be happy to help you out. – undetected Selenium Mar 19 '18 at 05:30
  • I will a make new question about that, as I wasn't aware of the best practices. – m.. Mar 19 '18 at 15:57