guard / guard-jasmine

The Swiss Army knife for automated Jasmine specs in your console.
http://guard.github.io/guard-jasmine
MIT License
303 stars 81 forks source link

Focus test not working in PhantomJS #48

Open robotarmy opened 12 years ago

robotarmy commented 12 years ago

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 commented 12 years ago

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

netzpirat commented 12 years ago

Closing this since lack of response.

robotarmy commented 12 years ago

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: https://github.com/netzpirat/guard-jasmine/issues/48#issuecomment-4972370


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

netzpirat commented 12 years ago

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 commented 12 years ago

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

robotarmy commented 12 years ago

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: https://github.com/netzpirat/guard-jasmine/issues/48#issuecomment-4984695


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

netzpirat commented 12 years ago

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 commented 11 years ago

@netzpirat thanks for the workaround

longlostnick commented 11 years ago

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

netzpirat commented 11 years ago

No, I haven't tried it yet.

rmilesson commented 10 years ago

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

booleanbetrayal commented 10 years ago

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

kirilltitov commented 10 years ago

I confirm, not working (thru Codeception stuff).

nathanstitt commented 10 years ago

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 commented 9 years ago

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 commented 7 years ago

Passed several years. The issue wasn't gone.