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

parameters in url can not be defined outside the page file #16

Closed
joyging opened this issue Feb 25, 2013 · 8 comments
Closed

parameters in url can not be defined outside the page file #16

joyging opened this issue Feb 25, 2013 · 8 comments

Comments

@joyging
Copy link

joyging commented Feb 25, 2013

We have a scenario to test the same webpage with different languages.

and we use the parameter "lng" to switch languages for the page.
e.g. www.example.com/home.php?lng=en means the english version of the page
www.example.com/home.php?lng=jp means the japanese version of the page.

with site_prism, i can define a page object for the page www.example.com/home.php. but in my test case, i need to open this same page with different languages

but page.load did not accept any parameters. it will be good if the load method will accept a group of parameters and the parameters will be added to the url

@natritmeyer
Copy link
Owner

👍 Yeah, this frustrates me from time to time. I'm thinking how best to do it. Open to ideas :)

@abotalov
Copy link
Contributor

abotalov commented Mar 5, 2013

What about methods like?

SearchResuts.load keyword: 'my search term'
set_url '/search?keyword={keyword}' # I propose {} as those symbols can't exist in url according to RFCs

In the internals it can be implemented as something like:

def self.set_url(url)
  @@url = url
end

def load(args={})
  raise SitePrism::NoUrlForPage if @@url.nil?
  url = @@url.dup
  args.each do |key, value|
    url.gsub!(/\{#{key}\}/, value)
  end
  visit url
end

@abotalov
Copy link
Contributor

abotalov commented Mar 5, 2013

Also I propose to resolve urls according to Capybara.app_host if they don't start from http. In the example above user should be navigated to 'http://www.google.com//search?keyword=my%20search%20term' if Capybara.app_host or Capybara.default_host aren't nil.

I'll prepare pull request for those 2 changes if you'll approve this feature

@natritmeyer
Copy link
Owner

@abotalov sure! Go ahead! I'm a bit behind where I should be with merging pull requests but if it's good code and has the relevant tests then I'll merge it in when I get a moment :)

@natritmeyer
Copy link
Owner

@abotalov BTW, site_prism will use Capybara.app_host if it has been set

@guiman
Copy link

guiman commented Mar 18, 2013

That feature would be great! I've been dealing with non rails application testing using app_host and it would be very useful. +1

@guiman
Copy link

guiman commented Mar 22, 2013

I've just created a Pull Request adding the Capybara.app_host feature that was being discussed here. I hope you find it as useful and I did.

@natritmeyer
Copy link
Owner

#27 covers this

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

No branches or pull requests

4 participants