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

No support for subdomains #31

Open
iamnader opened this issue Aug 26, 2010 · 35 comments
Open

No support for subdomains #31

iamnader opened this issue Aug 26, 2010 · 35 comments
Labels

Comments

@iamnader
Copy link

Details described in this thread: http://groups.google.com/group/ruby-capybara/browse_thread/thread/69e85fa4bbc40cb1

Here is a simple test that passes using selenium, but fails using envjs: http://gist.github.com/551764

Thanks

@smparkes
Copy link
Owner

Thanks. I'll try to look at it this weekend.

@smparkes
Copy link
Owner

smparkes commented Sep 2, 2010

This doesn't seem to be a free standing test. It's got a minor syntax error which is easy to fix, but I'm not sure the context is should be placed in. Did you have one?

@iamnader
Copy link
Author

iamnader commented Sep 2, 2010

I just noticed the 'require "test_helper"'. You should be able to remove that. It's an integration test. So if you put in test/integration and run a rake test:integration it should run right?

@smparkes
Copy link
Owner

smparkes commented Sep 2, 2010

Nope. It's giving me some kind of error on uninitialized constant ActionController. I'm not really that familiar with rails integration tests (I use rspec) so if you could throw together whatever it wants ...

@iamnader
Copy link
Author

iamnader commented Sep 2, 2010

OK, I created a very simple app that illustrates the problem: http://github.com/iamnader/envjs-subdomain-example

From the README:
== ENVJS SUBDOMAIN EXAMPLE

This is a very simple app that illustrates this bug in capybara-envjs: http://github.com/smparkes/capybara-envjs/issues#issue/31

Should be very straightforward to run, directions below from the README. Let me know if you have any issues.

== Getting Started

  1. Run 'bundle install' to download rails 3 and capybara-envjs (and dependencies)
  2. Run 'rake test:integration' to see a very simple test fail trying to navigate to a subdomain.
  3. In test/integration/subdomain_test.rb uncomment the Selenium driver line and see the test pass using Selenium

@smparkes
Copy link
Owner

smparkes commented Sep 2, 2010

Thanks. I appreciate the effort. I'll look at it in the morning (I already spent as much time as I can for today tracking down an envjs bug that surfaced with the newest capy changes).

@smparkes
Copy link
Owner

smparkes commented Sep 3, 2010

Okay. I've tweaked things.

First, as far as I can tell, your test isn't testing envjs, it's testing rack::test. I tweaked it and pushed to http://github.com/smparkes/envjs-subdomain-example.

Next, you have to set default_host if you want to use rack test. I'm not 100% sure if that's what you wanted. Did you want this to run a server like it does with selenium, or run within envjs? I kinda assumed the later. Was I wrong?

At this point, the envjs driver won't start a server like the selenium server does. It's possible, but I haven't needed it. It's come up once, that I'm aware of.

Next, I fixed envjs so it will actually do this. Before, it wasn't allowing default_host and app_host to be changed on the fly. I guess that's okay ... Fixed in master (which requires capy master)

Finally, rack-test does not support port numbers, as far as I can tell. envjs passes them on happily, but rack test will barf on them. That would be a rack-test issue ...

@iamnader
Copy link
Author

iamnader commented Sep 3, 2010

Excellent. I was actually testing envjs, it was just set as the default driver in the test_helper file. I would prefer to always use it, I only use Selenium right now for subdomain tests because of the limitation. Yes, you're correct I don't want to run a server, just envjs. So I want to take your updated version of my sample app, and point it at capy_envjs master to use your latest code and see if the test passes.

But it looks like the capybara-envjs github repo doesn't have a Gemfile. How would you recommend I use the version on master? Install it as a plugin?

Adding this to my Gemfile:
gem "capybara-envjs", :require => 'capybara/envjs', :git => 'git://github.com/smparkes/capybara-envjs.git', :branch => 'master'

gives me this error:
Could not find gem 'capybara-envjs (>= 0, runtime)' in git://github.com/smparkes/capybara-envjs.git (at master).

@smparkes
Copy link
Owner

smparkes commented Sep 3, 2010

I thought you were probably testing envjs ... seemed like you'd notice the difference.

Do you need the port in there? It didn't look like it'd be too terribly hard to hack rack::test to support ports.

You'll need to point at both capy_envjs master and capy master: I try to make capy_envjs master track capy and there are a number of unreleased changes in capy that capy_envjs is tied to.

I usually just download the repo, build the gem, and install it (which means I need to pre-bump the version in the repo, which I haven't done yet). I've heard that you should just be able to point bundler at a git clone and it should work?

@iamnader
Copy link
Author

iamnader commented Sep 3, 2010

OK, I pre-bumped the version # to 0.1.7, and installed the gem. My gemfile:

source 'http://rubygems.org'

Rails essentials

gem 'rails', '3.0.0.rc'
gem 'ruby-debug'

Testing

group :test do
gem "xpath"
gem "capybara", :git => "git://github.com/jnicklas/capybara.git", :branch => "master"
gem "capybara-envjs", '0.1.7'
end

Everything else is the same and I'm getting a new exception when running the test.

E
Finished in 3.634254 seconds.

  1. Error:
    test_simple_subdomain_test(SubdomainTest):
    Johnson::Error: document.getElementById("search-text") is null
    /test/integration/subdomain_test.rb:15:in `test_simple_subdomain_test'

1 tests, 0 assertions, 0 failures, 1 errors

Is it working for you?

@smparkes
Copy link
Owner

smparkes commented Sep 3, 2010

No, that's what I got, too. But, then, I don't actually see that id anywhere in the document. Did I miss something?

@iamnader
Copy link
Author

iamnader commented Sep 3, 2010

If you comment out the default_host line you added the test at least finishes, but the assert fails. However, the selenium version that previously passed now fails, because it requires the port.

Can you update the sample app so that the test passes? Or am I missing something? I thought you said that subdomains were now supported in the version of capy-envjs on master?

@smparkes
Copy link
Owner

smparkes commented Sep 3, 2010

If you comment out the default_host line you added the test at least finishes, but the assert fails.

Don't know what this means. Do you mean the Johnson error? Have you actually tried loading that page in a browser and looked a the Javascript console? You get the same error. So I think capy-envjs is doing the right thing ...

... as long as you add default_host == app_host without http:// and without a port. If you're adding the port simply because you can't bind to port 80, then you can just leave the port off when testing. If you need port support, somebody needs to add it to Rack::Test. This isn't a limitation of capy or capy-envjs, it's something rack test doesn't support, which both capy and capy-envjs use.

@iamnader
Copy link
Author

iamnader commented Sep 6, 2010

You were right about the Johnson error. Weird thing is the rails generator creates that. So the good news is I got basic subdomain support working with envjs! The bad news is it looks like it only works once per test. So for example if at the beginning of my test I set the default and app hosts they are set correctly and the navigation goes to the subdomains. If half way through a test I want to go to a different subdomain and I change the app_host and default_host values they don't take and requests still go to the first subdomain.

Any thoughts on how to handle that?

Thanks for the effort on this. envjs is SO much more convenient than Selenium

@smparkes
Copy link
Owner

smparkes commented Sep 7, 2010

Weird thing is the rails generator creates that.

Yeah, I didn't look at it at first for that reason, as well.

Are you saying you're hitting visit("/foo") and the changing values? I guess I'm not sure what should happen. Maybe that should work. If you're trying to hit a link on a page and have it go to a different url, I don't see that ever working: the page knows where it was loaded from and hacking that seems like a bad idea: to un-browser-like.

Doing more than one visit in a test, I'm not sure about. Is that what you're doing? Do you have an example?

@iamnader
Copy link
Author

iamnader commented Sep 7, 2010

Yep, I'm doing more than one visit. Just set the default and app hosts, visit a page, check the url. All good. Set the default and app to a different subdomain, visit a page, the url is still set to the original. My test is checking that actions I do on one subdomain, don't show up on another.

@smparkes
Copy link
Owner

smparkes commented Sep 7, 2010

If you want to push a test somewhere, I can look at it, and either make it work or tell you why it can't.

@iamnader
Copy link
Author

iamnader commented Sep 7, 2010

Hi, it's hard to bundle a test using your latest because I can't reference your head from bundler.

But if you take the same test from here: http://github.com/smparkes/envjs-subdomain-example/blob/master/test/integration/subdomain_test.rb

And just do two visits like this:

# this test passes using selenium, fails using the default envjs
Capybara.current_driver = :envjs

subdomain = "something"
Capybara.default_host = "#{subdomain}.lvh.me"
Capybara.app_host = "http://#{subdomain}.lvh.me"
visit root_path
assert current_url.include?(subdomain)

subdomain2 = "another"
Capybara.default_host = "#{subdomain2}.lvh.me"
Capybara.app_host = "http://#{subdomain2}.lvh.me"
visit root_path
assert current_url.include?(subdomain2)

@smparkes
Copy link
Owner

I'll give it a shot ...

@smparkes
Copy link
Owner

Hmm ... works for me? I've updated my version of the example. Am I testing it wrong?

Jonas says a new version of the capy should be out soon ... (though it sounds like I'm not the only one backed up ...)

@iamnader
Copy link
Author

Sorry, I just got around to testing this. Unfortunately I can't get your test to pass. The version in rubygems doesn't work. If I build a new gem from your master using the capybara rubygem I get an XHR can't connect error. If I use your master and the capy master I get this error: Capybara::DriverNotFoundError: no driver called :envjs was found, available drivers: :culerity, :celerity, :rack_test, :selenium

And this is all basically moot as I can't deploy your master as it isn't bundle friendly (vendoring doesn't work). So I guess I'm back to Selenium til there are new official envjs/capy gem versions

Thanks

@smparkes
Copy link
Owner

I'll try to get the gemspec stuff fixed ...

@smparkes
Copy link
Owner

Jonas did the hoe->bundler conversion so you should be able to use the git repo as a gem.

@geetarista
Copy link

Has this been addressed yet? I'm having issues with getting this to work.

@smparkes
Copy link
Owner

Last I checked, it worked. Do you have a failing example?

@geetarista
Copy link

I finally got it working. I had to tweak my settings before I finally got it right.

@snelson
Copy link

snelson commented Mar 24, 2011

I'm having an issue with subdomains too. When I switch the subdomain in one test, then switch it again in another test, then again in another test, in every test after the first, rails still thinks its on the first subdomain. I've created a sample app too with failing tests using rspec and steak.

This test fails: https://github.com/snelson/capybara-envjs-steak-subdomain-example/blob/master/spec/acceptance/subdomains_spec.rb

I also can't get iamnader's example to pass. Any advice would be much appreciated.

Thanks

@snelson
Copy link

snelson commented Mar 25, 2011

I was able to find a workaround for this by using multiple sessions, and opening a new session when the subdomain is switched. I wouldn't consider this a fix though as I think there should be able to do this within one session, like if to test domain-wide authentication. This may not even be a capybara-envjs issue, it might be a capybara issue.

The workaround can be found here:

snelson/capybara-envjs-steak-subdomain-example@3dc26a0

I came to this workaround when reading about a similar problem and solution at:

http://www.automation-excellence.com/blog/racking-my-brains

What's strange about his issue is that it seemed to be reverse, where selenium was working and rack test wasn't.

I'd love to help get a fix into either capybara-envjs or capybara, so any insight would be much appreciated, as the code is all still pretty unfamiliar to me.

@smparkes
Copy link
Owner

I've always had a hard time keeping track of this. If you look at the capy google group, you'll find a few threads about it. I don't use it, so I've tried to make it work now and again, but either I've never gotten it to work quite right or it gets broken again. I'm not entirely sure Jonas thinks it should be supported. I seem to remember him saying that mucking with .default_host/.app_host was evil.

@snelson
Copy link

snelson commented Mar 25, 2011

Jonas says in a number of places to use visit('http://subdomain.example.com'), that is, a FQDN, to switch the domain name, one of those places is here:

http://groups.google.com/group/ruby-capybara/browse_thread/thread/f6a109ec6d254bc8/5f9a726bc4de0b7d?lnk=gst&q=subdomain#5f9a726bc4de0b7d

That doesn't work either though. I've modified the test on another branch to show it using the default driver.

https://github.com/snelson/capybara-envjs-steak-subdomain-example/blob/fails_using_visit/spec/acceptance/subdomains_spec.rb

I'll setup an issue with Capybara and post the url here. Thanks for getting back, and thanks for all the work you've put into the envjs driver, we owe you big time.

@snelson
Copy link

snelson commented Mar 25, 2011

I've started a pull request with capybara so that we can use visit() to switch the subdomain and have it persist across subsequent requests.

teamcapybara/capybara#307

We'll see what happens with that. I'll follow up here.

@smparkes
Copy link
Owner

Thanks!

@snelson
Copy link

snelson commented Mar 25, 2011

Looks like its already in the works, hopefully we'll see it soon.

teamcapybara/capybara#307

@smparkes
Copy link
Owner

Cool. Let me know how it falls out. Depending on what the changes are, they might require driver changes.

@snelson
Copy link

snelson commented Mar 25, 2011

Absolutely, will do.

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

4 participants