Is there a way to perform Ctrl + click with Capybara and Poltergeist? - capybara

I'm trying to write a Capybara test which tests multi select using ctrl on Windows and command key on MacOS.
I found a solution here which works only if I use Selenium as my driver. Testing jQuery Selectable capybara or selenium (ctrl + click)
However, the solution does not work for Poltergeist driver. Does Poltergeist currently have support to perform Ctrl + Click?

No Poltergeist doesn't. If you have to use Poltergeist for the test then you're probably going to have to use execute_script to build and fire the event from JS. Note that only applies if it's a JS widget. If it's actually an HTML select with the multiple attribute you should just be able to select each option separately and it will select multiples.

Related

Unknown Format in feature testing rails capybara

I am writing capybara tests. There is a link I have in the view. When I click over the link that links open a pop-up js warning. I have configured Js. in capybara by using phantomjs and petergiest gem.
Without the requested information it's impossible to give an exact answer, but the error you are seeing means the app is requesting a non-JS response (probably HTML). This could be occurring for a couple of reasons
You're not actually running the test with a JS supporting driver. I don't see any js metadata on your scenarios so depending on how you've configured Capybara/RSpec this could by your issue. To confirm, swap from Poltergeist to using Selenium with Chrome or Firefox (non-headless while trying to debug) so you can see if the browser actually starts
You have a JS error preventing JS from running so a normal request is being made instead of XHR. This could be because you actually have a bug in your JS or because you're using Poltergeist/PhantomJS which is massively out of date in JS/CSS support. To test this, swap to using Selenium with Chrome or Firefox and look in the developer console.
Your link isn't correctly configured to make an ajax request - This is impossible to tell without the HTML of the link
Additionally, neither of the tests shown in your image are actually asserting/expecting anything so it's very unclear what exactly you're trying to test.

Does Geb support multi browser testing?

I would like to ask if Geb supports multi browser testing. i.e. testing same scenario at a time in two different browser on one execution?
geb is built on top of Selenium WebDriver which supports most browsers. See here for geb config for various browsers
I just posted and example app for this. you can create a gradel task to spin through and execute the tests for each browser in the gebconfig. Firefox is a bit of a mess at the moment. link why is provided in the sample gebconfig
https://github.com/basejump/grails3-geb-example

PhantomJS (Poltergeist) does not display twitter bootstrap label element

I am trying to click an link with twitter bootstrap label class in capybara test, however, the element is not displayed. After I remove the label class, the element is displayed and clickable.
This observation is based on using capybara's screenshot_and_open_image method when debugging the problem. Any idea for this strange behaviour?
(The page is rendered correctly in major browsers.)
PhantomJS 1.9.8 implements a pretty old browser (Safari 5ish IIRC) so it could be some kind of css issue - 2.0.0 is a much more feature complete modern browser, but has issues with file upload -- 2.0.1 (unreleased as of now) fixes the file upload issues - Try using PhantomJS 2.0.0+

How do I test to see that a custom uploader works?

I am testing a RoR app using Cucumber and Capybara with capybara-webkit as my javascript driver. I'm using jQuery on the client side.
I don't want to use the default file picker generated by my browser. This is my javascript code:
$(document).ready( function() {
$('#upload_button').click( function() {
$('#upload_file').click();
});
$('#upload_file').on( 'change', function () {
$(this).parents('form:first').submit();
});
});
This is my markup (edited to emphasize my problem):
<form action="/guests/upload_list" enctype="multipart/form-data" method="post">
<input class="invisible" id="upload_file" name="upload_file" type="file">
<button id="upload_button" name="button" type="button">Upload guest list...</button>
</form>
I can test, via Capybara, that my file uploads work, but I also need to test that my 'fake' button works. One thought was to use Capybara to click on the fake button and to check if a file dialog appears, but I don't know how to do the latter.
What are some good strategies for testing this? I've looked at poltergeist as a possible solution for a driver but it's still not clear how to test to see that this actually works. I've also looked at Jasmine as a javascript testing framework, but ideally I would like my current system to work (i.e. using Cucumber, Capybara, etc).
You could try some variation of
Make a screenshot.
Click your button
Make another screenshot
Compare them
but I'm not sure if selenium webdriver screenshots are OS level and show the picker or browser level and just show the page.
Otherwise something like sikuli that enables you to script with screenshots, could be an options. Sikuli uses Python, though I saw a gem called sikuli, but I don't know in what state that is in.
Are you sure you want to test the browser <-> OS interactions like this. Or do you just want to make sure that firing the click event on a hidden input-element of the file-type will spawn a filepicker. It is in no way defined by any HTML spec. Some browser OS combination may not even launch a picker.
If you come to the conclusion that testing the browser OS interaction is beyond the scope of your app and falls in the "testing the system" —similar to testing String—, then testing that the button.click fires a click on the input with Jasmine would be sufficient.
When the dialog opens, is there a new div or something that shows up? you could just assert that that css is there via a page.should have_css('div.fake-popup')

How can I test if a link exists with Selenium IDE?

I'm a beginner user of Selenium IDE. I need a help to create a test case that as input gets URL of Home page, and runs tests in loop on existence for both ALL links from the Home page and from all inner pages.
You can identify a link by using a very simple locator eg. link=Home
Or link=logout etc.

Resources