I recently started using capybara-webkit in order to speed up my acceptance tests. 90% of my tests run using the standard capybara DSL but some are slightly different.
One of the main ones that I am having trouble with is deleting cookies. Previously I used the following:
page.driver.browser.manage.delete_all_cookies
but this does not work with capybara-webkit. Receive this error:
undefined method `delete_cookie' for #<Selenium::WebDriver::Driver:0x007f86cb068b88> (NoMethodError)
Does anyone know how I can delete the cookies using capybara-webkit?
Thanks!
You can use clear_cookies method:
page.driver.browser.clear_cookies
Related
The process for writing multiple windows tests described in TestCafe documentation seems pretty straightforward:
await t.openWindow('https://url.com/addnewproperty')
or even
const initialWindow = await t.getCurrentWindow()
should do it. However, every time I use any of the Window Management methods I get the errors:
TypeError: t.openWindow is not a function and cannot do anything about it.
Does anyone know what am I doing wrong and how to solve the issue?
TestCafe version 1.9.4
The problem was in different versions of Test Cafe used between main codebase and one of the underlying packages. Alex Kamaev answer was a correct one
I am new to selenium.
I have same problem with for which you have already answered,
I have attached my code here and explained where I am getting ajax problem.
I just started building my framework, it is just a groundwork I am doing and and stuck.
I try to use your code, getting errors.
with session() method I am getting error (expecting object).
TIMEOUT
what am I need to do to run your methods.
with Selenium2 have we got any new functionalities that are dealing with Ajax?
I'm seeing an error in some integration specs, using rspec, capybara, capybara-webkit and timecop.
Capybara::FrozenInTime:
time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead
The only gem that I know that freezes time is Timecop, but I'm not using it in the test case that fails.
Since the error occurs only sometimes I can't even know if its gone or not after changing something.
The end of the error message holds the solution:
consider using time travelling instead
Just change Timecop.freeze to Timecop.travel. Timecop.freeze breaks Capybara's auto-wait feature.
In addition, I would call Timecop.return in an after block, as it will be associated with the most recent travel block:
after :each do
Timecop.return
end
The solution I found was to add
before :each do
Timecop.return
end
in spec_helper.rb.
This way we garantee that the time is not frozen before each test, although the only ones that have this problem are the ones executed in a webdriver different from rack-test. In my case capybara-webkit.
Having a bit of an oddity with some capybara webkit-driver (:js => true) tests.
Tests run fine when they run on their own, but somehow in sequence, they fail.
For example, I have a request test that looks something like
describe "A", :js => true do
# tests here run fine
end
describe "B", :js => true do
# tests here fail
end
When I split describe B section into its own file, and run it using bundle exec rspec spec/requests/b_spec.rb however - tests run fine and pass.
Debugging this, it looks like when both sections are in the same file, somehow the webkit driver loads a 'dirty' browser session. Trying things like page.driver.reset! or Capybara.reset_sessions! or Capybara.reset! doesn't seem to have any effect...
When using spectator/spork this isn't a problem, since I can split the tests into different files and run them independently, but when running the full suite of tests using bundle exec rspec - these tests fail...
How can I reset the webkit driver / session properly between tests? Or I am chasing the wrong problem?
p.s. These tests are not hitting the database or altering state in any particular way, so I'm pretty sure it's some driver related problem.
Sometime it helps just writing the question for the solution to pop up.
The key for me was:
These tests are not hitting the database or altering state in any particular way, so I'm pretty sure it's some driver related problem.
Turns out there was a state-change. In my particular case, setting OmniAuth into test_mode, which required setting it back to false after the previous test was running...
I'm using capybara, capybara-webkit, capybara-screenshot together with cucumber. (Ruby 1.9.3, Rails 3.1.3) and Capybara.javascript_driver = :webkit is also set env.rb
Unfortunately running a cucumber spec with #javascript will never succeed for some reason and the error screenshots just capture example.com.
The URL which I actually try to open is generated with a rails router result for one of my models e.g. with visit products_url
So how can I avoid that it ends up querying example.com?
Any input is very welcome.
Just because the comment is messed up - here's what I found was the solution:
Capybara.run_server = true
Capybara.server_port = 7787
Before '#javascript' do
Capybara.app_host = "http://127.0.0.1:#{Capybara.server_port}"
end
Try using visit products_path instead. They do not recommend using absolute URLs in "Gotchas" section of README.
For me, there was a much sneaker "gotcha" (and I was using Capybara with Rspec). Originally in a spec I had:
visit "foos/5"
This worked fine with Rack::Test but when I wanted to switch to the webkit driver to test js interactions, I got that exception (Unable to load URL: file:///products (Capybara::Driver::Webkit::WebkitInvalidResponseError)).
What I had to do was change the path I passed to visit, like so:
visit "/foos/5"
Succes!!
Here's another potential gotcha, posted for others that might have this issue. I was testing action caching, and the key Rails generates looks like "views/www.example.com/products". This happens even if you use products_path as the url. This can lead to the need to set your server name so you can know in advance what cache key to expect.