2

I'm trying to click a button in my Ember-CLI integration test, and it works with Chrome, but tells me click is undefined in PhantomJS. I've seen some other posts that recommend defining your own click event for PhantomJS, but I couldn't get that to work.

$("a:contains('Next'):visible")[0].click();

That works in Chrome, but not PhantomJS. The built in click helper, in Ember-CLI, appears to not work with "a:contains('Next'):visible".

Can anyone help?

Update:

I talked to some guys on the Ember-CLI IRC and got my selectors to work with the Ember click helper in my tests, but now the clicks appear to do nothing. Any ideas?

test("Tour next, back, and cancel builtInButtons work", function(assert) {
assert.expect(6);
visit('/').then(function() {
  assert.equal(find('.shepherd-active', 'html').length, 1, "Body gets class of shepherd-active, when shepherd becomes active");
  assert.equal(find('.shepherd-enabled', 'body').length, 2, "attachTo element and tour get shepherd-enabled class");
  assert.equal(find('#shepherdOverlay', 'body').length, 1, "#shepherdOverlay should exist, since isModal=true");
  click('.next-button', '.shepherd-enabled');
  andThen(function() {
    assert.equal(find('.back-button', '.shepherd-enabled').length, 1, "Ensure that the back button appears");
  });
  click('.back-button', '.shepherd-enabled');
  andThen(function() {
    assert.equal(find('.back-button', '.shepherd-enabled').length, 0, "Ensure that the back button disappears");
  });
  click('.cancel-button', '.shepherd-enabled');
  andThen(function() {
    assert.equal(find('[class^=shepherd-button]', '.shepherd-enabled').length, 0, "Ensure that all buttons are gone, after exit");
  });
  });
});
rwwagner90
  • 360
  • 3
  • 16
  • `:contains()` is not a valid CSS selector, but is only supported in jQuery. Make sure that you use jQuery for that. – Artjom B. Mar 20 '15 at 20:55
  • Same thing: Only supported by jQuery. – Artjom B. Mar 20 '15 at 21:13
  • Right, so I need to have a way to make it work. – rwwagner90 Mar 20 '15 at 21:15
  • try this: ``$("a:contains('Next'):visible")[0].trigger('click')`` – Jeff Mar 20 '15 at 21:17
  • 2
    .click() and .trigger('click') both give me "undefined is not a function" – rwwagner90 Mar 20 '15 at 22:02
  • In that case use mouse events: [PhantomJS; click an element](http://stackoverflow.com/questions/15739263/phantomjs-click-an-element) – Artjom B. Mar 20 '15 at 23:07
  • I'm not sure if I can use that. I'm not writing PhantomJS code myself, so I don't have access to the page variable, that I know of. – rwwagner90 Mar 21 '15 at 03:38
  • I had a similiar issue (click(), text(), etc. throw "undefined is not a function" when called on jQuery) without `ember.js`. During a buildstep I somehow managed to twist jQuery served from `bower_components` so I did `rm -rf bower_components && bower cache clean && bower install` and out of the blue the error was gone.... – herom Mar 23 '15 at 15:50

0 Answers0