akephalos icon indicating copy to clipboard operation
akephalos copied to clipboard

Undefined method `getByXPath'

Open leifbladt opened this issue 13 years ago • 12 comments

I switched from Selenium to Akephalos today. But one cucumber feature is not running.

undefined method `getByXPath' for #<:comgargoylesoftwarehtmlunit::javascriptpage:0x6d9dd520> (NoMethodError) (DRb::DRbRemoteError)
(druby://127.0.0.1:49363) -e:1

I'm getting this error only in three scenarios inside one feature. The trigger is a "Then I should see 'something'". What happens before is a AJAX call which returns JavaScript, the client should execute. This works in other scenarios, but not in this one.

When I change the "I should see" to "Then show me the page", it also results in an error (undefined method 'getXml' this time).

[... JavaScript response from AJAX call]
ThreadSafeClientConnManager - Released connection is reusable.
ConnPoolByRoute - Releasing connection [HttpRoute[{}->http://127.0.0.1:65432]][null]
ConnPoolByRoute - Pooling connection [HttpRoute[{}->http://127.0.0.1:65432]][null]; keep alive for -1 MILLISECONDS
IdleConnectionHandler - Adding connection at: 1297777311339
ConnPoolByRoute - Notifying no-one, there are no waiting threads
HtmlElement - Firing Event unload (Current Target: HTMLElement for HtmlHtml[]);
EncodingSniffer - Encoding found in HTTP headers: 'utf-8'.
WebWindowImpl - setEnclosedPage: com.gargoylesoftware.htmlunit.JavaScriptPage@759f6a57
WebWindowImpl - destroyChildren
JavaScriptJobManagerImpl - Waiting for all jobs to finish (will wait max 1000 millis).
JavaScriptJobManagerImpl - Finished waiting for all jobs to finish (final job count is 0).
JavaScriptJobManagerImpl - Waiting for all jobs that have execution time before 1000 to finish
JavaScriptJobManagerImpl - Finished waiting for all jobs that have target execution time earlier than 1297777312348, final job count is 0

leifbladt avatar Feb 15 '11 13:02 leifbladt

I'm getting this too. As far as I'm aware, there's no javascript on the page at all. It seems like the thing that causes it in my case is that the preceding step submits a login form, which sends a redirect back to the browser. This scenario works with rack-test.

When I change the step to do a save_and_open_page instead, I get another undefined method error, this time for `asXml'.

mattwynne avatar Feb 22 '11 12:02 mattwynne

Sorry if I'm hijacking this issue, but it looks like this is very relevant to my situation: http://stackoverflow.com/questions/4824028/celerity-cannot-follow-a-devise-redirect-because-celerity-doesnt-send-an-accept

mattwynne avatar Feb 22 '11 12:02 mattwynne

I get this error on local machines (OSX and Ubunto on Vagrant) and also on my hudson CI server. Sometimes the tests work fine and other times they fail.

aeseducation avatar Mar 01 '11 12:03 aeseducation

Matt: did you work out any way to set the accept header? Seems like Akephalos doesn't allow configuring this header, right?

jnicklas avatar Mar 03 '11 15:03 jnicklas

@jnicklas, no I backed out of my whole akephalos experiment because of this issue.

mattwynne avatar Mar 03 '11 17:03 mattwynne

I found one workaround, actually. The problem for me is the redirect in Devise when authentication fails. Solution: don't let authentication fail ;) So by changing:

- visit(root_path)
+ visit(new_user_session_path)
fill_in 'Email', :with => 'Foo'

That way we're going to the sign in page directly, the redirect never happens, all is good!

jnicklas avatar Mar 03 '11 22:03 jnicklas

FYI: I was able to fix the problem by changing the validate scripts setting. My application is Rails3 with prototype.js

Capybara.register_driver :akephalos do |app| Capybara::Driver::Akephalos.new(app, :validate_scripts => false) end

aeseducation avatar Mar 31 '11 15:03 aeseducation

Unfortunately, this doesn't work for me...

leifbladt avatar Apr 01 '11 08:04 leifbladt

leifbladt: Did you ever solve this? We're having the same issue.

jwhardcastle avatar May 01 '11 14:05 jwhardcastle

No, unfortunately not. My workaround is to let these failing scenarios run with the selenium driver (which means they are not covered by our CI server...).

leifbladt avatar May 02 '11 07:05 leifbladt

I'm also getting this issue while trying to use the "visit" command in Capybara within a Javascript-enabled Cucumber test in Akephalos. The Javascript being executed is attaching event handlers to clicks on page load using JQuery 1.6.

caseydreier avatar May 18 '11 01:05 caseydreier

If you're getting UnexpectedPage as part of the error then try enabling debug output in htmlunit within akephalos. lib/akephalos/htmlunit.rb if using the gem or

Capybara.register_driver :akephalos do |app|
  Capybara::Driver::Akephalos.new(app, :htmlunit_log_level => "debug")
end

in my fork. This gives you more information to see why htmlunit is throwing an UnexpectedPage.

In my case, for a login form, I was not signing in successfully and being given a 401 which htmlunit loaded up as the UnexpectedPage. Turns out I needed to change DatabaseCleaner from transaction to truncation because transaction does not work properly with @javascript turned on.

asceth avatar Jun 11 '11 18:06 asceth