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

Opening a page URL optionally with query string parameters #75

Open
walterdolce opened this issue Oct 5, 2016 · 6 comments
Open

Opening a page URL optionally with query string parameters #75

walterdolce opened this issue Oct 5, 2016 · 6 comments

Comments

@walterdolce
Copy link
Contributor

walterdolce commented Oct 5, 2016

Currently, the only way I can see to open a page with query string parameters it seems to be the following:

class Homepage extends Page {
   protected $path = '/?{QS}';
}

class MyContext ... {
   public function aStep() 
   {
      $this->homepage->open(array('QS' => 'utm_source=1&utm_campaign=foo'));
   }
}

This produces the expected result:

<schema>://<hostname>/?utm_source=1&utm_campaign=foo

But this way one is always forced to pass something. By leaving the array parameter passed to the open method, this is the resulting absolute URL:

<schema>://<hostname>/?{QS}

There might be cases where the behaviour of a page (or element) might vary depending on whether something's included in the URL as a query string parameter. And both cases to be verified. Creating the same page object twice (i.e. Homepage and ParameterisedHomepage) feels wrong (even if it just extend the non-parameterised page object class).

How should one deal with optional query string parameters?

@jakzal
Copy link
Member

jakzal commented Oct 6, 2016

We could make it real simple, and append all parameters that were not part of the $path as query parameters.

@walterdolce
Copy link
Contributor Author

walterdolce commented Oct 6, 2016

Sounds like a good start. What about URL fragments?
Semantically speaking, those would be two different things.

I.e.

<schema>://<hostname>/?utm_source=1&utm_campaign=foo#the-anchor

@DonCallisto
Copy link
Contributor

I came across this today in one of my projects. @jakzal are you still interested in this feature? Maybe I can try an implementation in the next weeks.

@DonCallisto
Copy link
Contributor

We can add two more (optional) parameters to open: array $query = [], string $fragment in order to not introduct BC.
Another solution could be to use one array (as it is atm) but prepend to the param keys someting like ?<key> and #<key>.
Personally I feel that first solution is better than latter one (no validation for multiple fragment, just to mention the first issue I see).
Any thoughts?

@jakzal
Copy link
Member

jakzal commented Dec 12, 2019

Thinking about it again what's wrong with the following?

class Homepage extends Page {
   protected $path = '/?utm_source={utm_source}&utm_campaign={utm_campaign}';
}

class MyContext ... {
   public function aStep() 
   {
      $this->homepage->open(['utm_source' => 1, 'utm_campaign' => 'foo']);
   }
}

@DonCallisto
Copy link
Contributor

I have some cases where I would like to open the page without some parameters (maybe not mandatory?) and in those cases I would land in the page with placeholders instead of real parameters or without parameters at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants