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

Focus test not working in PhantomJS #48

Open
robotarmy opened this issue Mar 29, 2012 · 16 comments
Open

Focus test not working in PhantomJS #48

robotarmy opened this issue Mar 29, 2012 · 16 comments

Comments

@robotarmy
Copy link
Contributor

I have keydown tests that seem to work fine in the browser with jasminerice

I am trying to get guard-jasmine working.

I need some assistance.

here is one of the tests that works in firefox and safari via jasmine rice and fails in phantomjs

it("is focused",function() {
  expect($(selector).filter(':focus').size()).toBe(0)
  $(selector).filter(':first').trigger('click.editable')
  expect($(selector).filter(':focus').size()).toBe(1)
})
@netzpirat
Copy link
Contributor

Did you attach the elements to the DOM? Visibility tests won't work in-memory, the elements must be attached to the document.

@netzpirat
Copy link
Contributor

Closing this since lack of response.

@robotarmy
Copy link
Contributor Author

yes - they were attatched via jquery fixture in jasmine

On Thu, Apr 5, 2012 at 2:28 AM, Michael Kessler
reply@reply.github.com
wrote:

Closing this since lack of response.


Reply to this email directly or view it on GitHub:
#48 (comment)


Modern Yoga vs Traditional Yoga
http://swamij.com/traditional-yoga.htm#swamirama

@netzpirat netzpirat reopened this Apr 5, 2012
@netzpirat
Copy link
Contributor

I can confirm this bug, here's a PhantomJS script to reproduce:

page = require('webpage').create()
page.onConsoleMessage = (msg) -> console.log msg

page.open 'http://www.google.com/', (status) ->
  console.log 'Google loaded'
  page.includeJs 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', ->
    console.log 'jQuery injected'
    page.evaluate ->
      console.log "Is search focused? #{ $('input[name=q]').is ':focus' }"
      $('input[name=q]').focus()
      console.log "Is search focused? #{ $('input[name=q]').is ':focus' }"
    phantom.exit()   

@netzpirat
Copy link
Contributor

I has already been reported to the PhantomJS issue tracker, see Issue 427 and vote for it!

@robotarmy
Copy link
Contributor Author

thank you fro your help!

On Thu, Apr 5, 2012 at 1:13 PM, Michael Kessler
reply@reply.github.com
wrote:

I has already been reported to PhantomJS issue tracker, see Issue 427 and vote for it!


Reply to this email directly or view it on GitHub:
#48 (comment)


Modern Yoga vs Traditional Yoga
http://swamij.com/traditional-yoga.htm#swamirama

@netzpirat
Copy link
Contributor

This issue is still present in PhantomJS 1.6.0.

As workaround you can check the active document element:

$('input[name=q]').get(0) == document.activeElement

so you can write your own matcher in spec.js.coffee like:

beforeEach ->
  @addMatchers {
    toBeFocused: -> @actual.get(0) is @actual.get(0).ownerDocument.activeElement
  }

@ronen
Copy link
Contributor

ronen commented Feb 12, 2013

@netzpirat thanks for the workaround

@longlostnick
Copy link

Has anyone tried any of the newer versions of phantomjs? 1.9.0 seems to fix a lot of problems for me.

@netzpirat
Copy link
Contributor

No, I haven't tried it yet.

@rmilesson
Copy link

I just tried this. Doesn't work unfortunately. Will be checking the activeElement property workaround for now.

@booleanbetrayal
Copy link

+1 ... currently requires mocking around :focus checks in tests which is less than ideal

@kirilltitov
Copy link

I confirm, not working (thru Codeception stuff).

@nathanstitt
Copy link
Member

Thanks for the reports.

I'm not sure we'll be able to fix this in guard-jasmine since it seems like a phantomjs issue. I'll investigate it further and see if we can figure out a workaround, but I don't see any way we can do so at the moment.

@daniel-aranda
Copy link

I'm running latest version of Grunt, Grunt Jasmine, jQuery and this is still an issue. However the document.activeElement shared by @netzpirat makes the trick.

expect(defaultView.$('.some').get(0)).toBe(document.activeElement);

@Gennady77
Copy link

Passed several years. The issue wasn't gone.

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

10 participants