I need to save a CSV file using selenium and Ruby - ruby

I'm struggling with a feature.
I have a scenario where I click a hyperlink to download a CSV. I have the command to open the csv file sorted. Once that hyperlink is pressed, a pop up box shows up in Firefox and I need to select the Save File option then press OK.
I have no idea how to tell selenium to do this. I have a test code to confirm a new webpage has opened (below)
new_window=page.driver.browser.window_handles.last
page.within_window new_window do
current_url.should eql "https://...."
end
This approach doesn't work for the download pop up. I need to move to the pop up and press those two options.
Any help would be appreciated

You are missing one important thing: Once your hyperlink is pressed, Firefox directs the underlying operating system to launch a pop up. In other words, you are no longer dealing with Firefox, and therefore Selenium is completely blind to that modal window. Generally the solution is something like Sikuli, Robot, or some other framework.
Also, have a read through this: http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/

Related

Need to re-record part of OpenScript script but don't want to re-record the whole script

We would like to fix a portion of a script in OpenScript by re-recording the part that's not working in lieu of re-recording the whole script. We can't seem to figure out how to do it. Every time we try, Open Script starts with the log in to the testing program. It seems you should be able to start recording at any point. Does anyone know?
create a test script, click on Record, once it launches, in Openscript toolbar pause the recording. Now the recording is stopped, whatever we do will not be recorded .Manually perform the sections which you don't want to record. Then click on resume on the openscript toolbar. Now it will be recorded.
Once done, copy the generated code to the actual script.
[If you are using object library add this as an asset in actual script]
Hope this helps !
Recording from opened browser is supported in Oracle Application testing suite .
1. Open OATS Tool
2. Launch IE
3. navigate to UI where you want to start recording
4. There is Globe icon top (menu Icons), select opened browser
5. Select record
6. Steps will be recorded in Editor
Image:
For more OATS related tips, visit here www.testinghive.com

How to handle File Download pop up in Firefox using AutoIT in (selenium RC)

I need to download a file from application in my selenium RC test.
When i click on the link/button to save a file, first i get a pop up which asks me to either open or save the file, when i select 'Save' and click 'OK' then i get one more pop up asking me to provide the path where file is to be saved and file name also.
I goggled and found that this could be done via AutoIT but i am facing some problems while doing that.
so could some one please provide me the .exe file for file_download in Firefox and also where i can mention the path to save that file too.
and also if you could provide me what exactly the code, i need to write in my test case.
Please let me know how to handle this.
You can achieve that without using autoit also. follow below steps.
Create new firefox profile.
Change the preferences in that profile manually before starting the automation with that profile. (Change the settings like below)
Now start the automation using that profile so that files will be downloaded to default location.
Starting selenium server using specfic profile
java -jar selenium-server.jar -firefoxProfileTemplate "C:\Users\UserName\AppData\Roaming\Mozilla\Firefox\Profiles\234saddsf.customProfile"
I found this link: http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html
Unfortunately it is for the old style dialog boxes that do not have the open vs save radio buttons. I'm searching for a solution to this part of the problem.

Problems running Ruby program with Aptana Studio

The request below is based upon an earlier version posted on the Aptana Tender site, where it didn't receive a response - presumably because the Aptana Tender site has now been deprecated in favour of StackOverflow.
I'm using Eclipse 3.6.2.r362_v20110210 with the Aptana Studio plugin version 3.0.3.201107141410 (i.e. all fully up-to-date, I believe) on Mac OS X 10.6.8 Snow Leopard on a Macbook.
I created a Ruby project, and then created a single file inside it called "item.rb", into which I wrote some Ruby code.
The file is very short: it defines an "Item" class with an initialisation method that asks the user for a value (using a "puts" followed by a "gets.chomp") and a get method that returns the value, and it also contains two more lines: one to create a new Item, and one to call that method on the newly-created Item.
When I run "ruby item.rb" from the Terminal, it works as expected: it asks the user for a value, and returns that value. No errors/warnings.
Now, I don't want to have to use the Terminal every time I want to execute the file, but I'm having trouble getting it running any other way.
Here are the steps to reproduce:
In the main Eclipse menu, go to Window > Open Perspective > Other.
In the resulting dialogue box, click "Ruby" and click "OK".
In the Script Explorer view, click the triangle next to the name of the project containing the file I want to run, so that the project's contents are shown.
In the Script Explorer view, double-click on the name of the file I want to run (item.rb).
This causes item.rb to open in an editor view, and gives that view focus (i.e. the editor view containing item.rb has a blue rather than a grey border, and there is an active cursor inside the view).
Click the "Run" button on the Eclipse toolbar (the one that looks like a green "Play") button.
THE FIRST PROBLEM: a "Run as..." dialogue box pops up (I don't know why) asking me to "Select a way to run 'item.rb'". It gives me two options (again, I don't know why): "Android Application", "Ruby Application".
Expected behaviour: because item.rb is a file ending in ".rb" and containing only valid Ruby code, Eclipse/Aptana should, by default, run it as a Ruby application.
I click "Ruby Application", and then click "OK".
THE SECOND PROBLEM: the dialogue box disappears, but nothing else happens.
Expected behaviour: the Console view should get focus, and item.rb should be executed, with the results showing up in the Console view's textarea.
By this point, it would be reasonable to give up. But programmers are unreasonably persistent, right? So: click the Console tab.
The Console view's header says, "item.rb [Ruby Application] /usr/bin/ruby", and below this is a blank textarea containing only a blinking cursor.
Press the <Return/Enter> key on the Macbook's keyboard once or twice.
THE THIRD PROBLEM: the Console view's textarea suddenly updates with the output of item.rb, but weirdly, it doesn't stop at gets.chomp, it just acts as though the user has entered an empty response at that stage (i.e. as though the user has simply pressed the <Return/Enter> key on the keyboard), and ploughs on until the entire program has executed. The Console view's header then changes to "<terminated> item.rb [Ruby Application] /usr/bin/ruby".
Expected behaviour: item.rb should execute in the Console view just as it does in the Terminal.
Please can you help me troubleshoot these three problems?
Many thanks.
It sounds like you have an older version of Aptana, RDT, RadRails or DLTK Ruby installed, as there is no "Ruby" perspective in Aptana Studio 3.x.
You should be able to right click the file in the Project Explorer, App Explorer, or in the open editor for the file and choose Run As > Ruby Application.
Ideally you'd remove any old installation of ruby plugins to avoid some sort of conflict before doing so. It should then launch the file as expected.
The Enter/Return behavior you're talking about sounds like the program is not flushing STDERR/STDOUT and hitting Enter is proceeding to enter in the input (so, it's buffering the output you should see that forms the prompt, then you hit Enter/Return and it takes that as the input so it proceeds after the gets call). if things printed to STDOUT don't show, you can try and force auto-flushing by adding $stdout.sync = true to the top of your script. Studio 3.x should set that up silently for you on programs launched through it. If not, then you should file a bug: http://jira.appcelerator.org/secure/CreateIssue!default.jspa

Selenium-IDE test can't switch browser windows

I'm writing a Selenium IDE script to test part of our website that opens a window that takes the user to a third party site that we integrate with. The test clicks a link on our website, that opens a new window on the third party site where we need to tick a checkbox and submit a form, at which point the window closes and we then need to check another page on our own website.
Our problem is that the script breaks at the Selenium selectWindow action, because it says that it cannot find a window with the given name. If we then manually run that line in the IDE, it works!
I have added numerous waits, pauses and other tricks to make sure that the window exists and has the correct title when the SelectWindow action is hit, but we still get the above error.
The script is...
click link=activate
waitForPageToLoad
selectWindow Third party activation site
Are there any tricks to getting this to work?
You dont need that waitForPageToLoad as i'm assuming the host page isn't reloading.
You may want to check out the api ( http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/java/com/thoughtworks/selenium/Selenium.html#selectWindow(java.lang.String) ) entry for the command. This is the java docs, but it the same for selenium IDE.

Creating quick GUI front ends

I wanted to have a GUI front-end for a script that accepts numerous command-line options, most of them are UNIX paths. So I thought rather than typing them in (even with auto-completion) every time, I'd create a GUI front end which contains text boxes with buttons beside them, which when clicked will invoke the file browser dialogue. Later, I thought I'd extend this to other scripts which would sure require a different set of GUI elements. This made me think if there's any existing app that would let me create a GUI dialog, after parsing some kind of description of the items that I want that window should contain.
I know of programs like Zenity, but I think it's doesn't give me what I want. For example, if I were to use it for the first script, it'll end up flashing sequence of windows in succession rather than getting everything done from a single window.
So, basically I'm looking at some corss-platform program that lets me create a window from a text description, probably XML or the like. Please suggest.
Thanks
Jeenu
Mozilla's XUL is a cross platform application framework - . You could write an app as a Firefox plugin or a standalone XUL application.
mono and monodevelop could work for this. Or even something super simple like shoes.

Resources