installing ruby on windows xp - dan stra … · open the windows command prompt by clicking on the...

26
Installing Ruby on Windows XP

Upload: vodien

Post on 17-Apr-2018

235 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 2: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 2 of 26

Table of Contents

1   Installation .............................................................................................2  1.1   Installing Ruby......................................................................................................... 2  

1.1.1   Downloading..................................................................................................................2  1.1.2   Installing Ruby...............................................................................................................2  1.1.3   Testing Ruby Installation ...............................................................................................6  

1.2   Installing Ruby DevKit ............................................................................................. 7  1.3   Installing Ruby Gems ............................................................................................ 10  1.4   Installing Selenium ................................................................................................ 12  1.5   Installing the IDE ................................................................................................... 14  

1.5.1   Install the Java JDK where required............................................................................14  1.5.2   Installing Netbeans......................................................................................................18  1.5.3   Configuring NetBeans ..................................................................................................20  

2   Testing your installation.....................................................................22  2.1   Create a new project ............................................................................................. 22  2.2   Create your test file ............................................................................................... 24  2.3   Run your test file ................................................................................................... 25  

1 Installation  

1.1 Installing Ruby

1.1.1 Downloading We will be installing Ruby version 1.9.2 – the latest version of Ruby. You can download the installer from:

http://rubyforge.org/frs/download.php/72170/rubyinstaller-1.9.2-p0.exe Download the file, save it on your desktop, and once complete, double click on the .exe file to open it. Agree with any security warnings that appear.

1.1.2 Installing Ruby You should now see this window:

Page 3: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 3 of 26

• Click “Next” • Select “I accept the license” and click “Next”

On the next screen:

• Change the installation path to “C:\Tech\Ruby192” • Check the “Add Ruby executables to your PATH” checkbox • Check the “Associate .rb and .rbw files with this Ruby installation” checkbox

The screen should now look like this:

Page 4: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 4 of 26

Click “Install”

Page 5: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 5 of 26

Once installation is complete, you should see this screen:

Click “Finish”, and the installer will close.

Page 6: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 6 of 26

1.1.3 Testing Ruby Installation We’re now going to test that ruby has installed properly by running ruby. Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, type “cmd” into the text box and click “Ok”:

When the Command Prompt appears, type:

ruby –v

and press Enter. You should see the ruby version number as in this screenshot:

Here you can see we have installed ruby version 1.9.2p0.

Page 7: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 7 of 26

1.2 Installing Ruby DevKit The rest of this document (except for the paths) works across pretty much any operating system. There are some problems compiling some Ruby gems on Windows because of the lack of a C compiler installed by default. The Ruby DevKit takes care of all of this for you. First of all, download the DevKit from:

http://github.com/downloads/oneclick/rubyinstaller/DevKit-4.5.0-20100819-1536-sfx.exe

Download the file, save it on your desktop, and once complete, double click on the .exe file to open it. Agree with any security warnings that appear. When the 7-Zip self-extracting archive window pops up, you should change the path to:

C:\Tech\Ruby-DevKit\

Once the file has extracted, open the Windows Command Prompt by select Start / Ru, typing “cmd” and pressing Enter. Next, navigate into the directory that you just extracted the files into. For instance:

cd ../../ cd Tech/Ruby-DevKit

Page 8: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 8 of 26

Now type:

ruby dk.rb init Which will generate a config file which should list the version of Ruby that we installed earlier.

Type:

notepad config.yml To check that it’s OK. You should see a line at the bottom of the file which reads:

- C:/Tech/Ruby192 Next, we will install the DevKit enhancements. To do this, type:

ruby dk.rb install Which should produce:

Page 9: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 9 of 26

Finally, to check that the installation has been successful, we’re going to try compiling a gem (see section 1.4 below for a full explanation of gems) to check this installation. Type:

gem install rdiscount --platform=ruby

RDiscount should install correctly and you should see:

Temporarily enhancing PATH to include DevKit... in the screen messages. Next type:

ruby -rubygems -e "require 'rdiscount'; puts RDiscount.new('**Hello RubyInstaller**').to_html"

and press enter. You should see:

<p><strong>Hello RubyInstaller</strong></p> In summary:

Page 10: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 10 of 26

1.3 Installing Ruby Gems Gems in Ruby are self-contained programs or libraries. So, the “mysql” gem contains code that you may use to connect to mysql. I say may as there can be multiple gems that do the similar things in different ways. For instance there are two well known and competing Object Relational Mappers – DataMapper and ActiveRecord. In this section we will download and install the gems you will need to test. To do this, return to the command prompt you have open above, and type in:

gem list

This lists the gems which are already installed. We will now download and install the gems you need; which are:

• selenium-webdriver • watir-webdriver • rspec • ruby-debug-ide • test-unit

The gem package manager will also download any dependencies that are required by these gems, and that you do not have installed. Return to the Command Prompt window, and type:

gem install selenium-webdriver watir-webdriver rspec ruby-debug-ide test-unit --platform=ruby

and press “Enter”. Note: When installing gems on Windows with DevKit, you should always append

-- platform=ruby

when installing gems. This ensures that the source is downloaded and compiled locally rather than binaries downloaded which will not work on windows. More information can be found here: http://github.com/oneclick/rubyinstaller/wiki/Development-Kit under the heading “Example Native RubyGem Installations using the DevKit”.

Page 11: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 11 of 26

It may take a while to complete, but once done you should see output that looks like this:

Page 12: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 12 of 26

1.4 Installing Selenium Although we will be creating tests using Watir, which is a Ruby test API, the tests will be run by a Selenium server. The call stack looks like this: Watir tests -> Watir-Webdriver -> Selenium-Webdriver -> Selenium Server This means that you can run Selenium tests without having it open a browser window. This is called running “headlessly”. This is much, much faster than having watir open a browser and run the tests. This means that you can run tests headless locally, prior to checking in, and then the build server can take care of the longer and heavier cross browser testing in the nightly build. We’re going to install the standalone selenium server on your PC. To do this: Create a new directory; C:\Tech\Selenium\ Go to http://code.google.com/p/selenium/downloads/list/ and download the latest version of the selenium-server-standalone-2* file, saving it to C:\Tech\Selenium\ Open the Windows Command Prompt by clicking Start / Run, typing “cmd” and pressing Enter. Navigate to the Selenium directory and list the contents by typing:

cd ../.. cd Tech/Selenium

You should see:

Page 13: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 13 of 26

Now we’re going to start the Selenium server. Type:

java –jar selenium-server-standalone-2.0a5.jar The Selenium server will now start. When the security alert appears, click the “Unblock” button:

You should see something like this in the Command Prompt window:

This means that the Selenium server is up and running and waiting for connections on port 4444. Leave the window where it is, as we will return to it later.

Page 14: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 14 of 26

1.5 Installing the IDE Everyone has their favourite IDE, but if you do not have one yet and want one that works well with Ruby, then Netbeans is a good choice. In this section we will install Netbeans and configure it for use with the version of Ruby we just installed.

1.5.1 Install the Java JDK where required Netbeans is a Java application and needs the JDK (Java Development Kit) to run. So that we can be sure that everyone’s IDE works in the same way, we’re first going to download the current version of the Java JDK from here: http://is.gd/fdHJl Download the file, save it on your desktop, and once complete, double click on the .exe file to open it. Agree with any security warnings that appear. You should now see this window:

Click “Next”

Page 15: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 15 of 26

Next, you will see the installation options page. Leave the default options as they are and click “Next”:

The installation will start.

Page 16: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 16 of 26

When the installation is about half way through, a second window will pop up. This is for the JRE – Java Runtime Environment. You will see a window that looks like this:

Click “Next”, and the JRE will be installed.

Page 17: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 17 of 26

The second window will disappear when the JRE has been successfully installed, and you will be left with:

Click “Finish” to close the window. When the browser window opens asking you to register, close it again.

Page 18: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 18 of 26

1.5.2 Installing Netbeans We’re going to download the Ruby bundle of Netbeans, which you can get from here: http://netbeans.org/downloads/index.html Download the Ruby version, save it on your desktop, and once complete, double click on the .exe file to open it. Agree with any security warnings that appear. The first installation screen asks you which server you want to install with the IDE. As we’re not going to be doing any web development, deselect the “Glassfish Server Open Source Edition 3.0.1” checkbox:

Then click “Next”. On the next screen, accept the Terms & Conditions by checking the checkbox, and select “Next”.

Page 19: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 19 of 26

The next screen asks you for your installation location and the location of the JDK. The screen should look like this:

You must ensure that the “Java environment for the NetBeans IDE” path matches the one you just installed:

C:\Program Files\Java\jdk1.6.0_21 Click “Next”. Click “Install” Once the registration is done, uncheck the “Register” checkbox and click “Finish”.

Page 20: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 20 of 26

1.5.3 Configuring NetBeans   We’re now going to check that NetBeans is configured correctly. To start, open NetBeans by selecting:

“Start / All Programs / NetBeans / NetBeans IDE 6.9.1” Once it’s finished loading, select the Tools menu and select “Ruby Platforms”

Page 21: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 21 of 26

You should now see the “Ruby Platform Manager”, which shows the different versions of Ruby installed on your computer. You should see two versions:

1. Built in JRuby 1.5.1 – which comes bundled with NetBeans  2. Ruby 1.0.2-p0 – the version we installed earlier  

 

Click “Close” to close.

Page 22: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 22 of 26

2 Testing  your  installation   Lastly, we’re going to test that your installation works by writing a quick test that uses Watir to run a test against the google homepage.

2.1 Create a new project With Netbeans open, select “File” from the top menu, and then “New Project”:

In the new project dialog, select “Ruby” in the middle section, and then “Ruby Application” in the right panel.

Click “Next”.

Page 23: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 23 of 26

On the next screen: • Rename the project to “RubyTraining” • Change the “Project Path” to “C:\Tech\Projects” • Deselect the “Create Main File” checkbox • Change the Ruby Platform to “Ruby 1.9.2-p0”

The screen should now look like this:

Click “Finish”.

Page 24: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 24 of 26

2.2 Create your test file Once the project has been created, right click on “Source Files” in the project pane, select select “New” / “Ruby File”.

Enter “google_test” into the ‘File Name” text box, and click “Finish”. When the file opens, select all of the text in the file and replace it with the text below:

require 'watir-webdriver' browser = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => :htmlunit) browser.goto "http://google.com" browser.text_field(:name => 'q').set("Watir is working!") browser.button(:name => 'btnG').click puts browser.url browser.close

Save the file by pressing “Ctrl + S” or selecting File / Save from the menu.

Page 25: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 25 of 26

This script

• goes to www.google.com • enters “Watir is working!” in the question box • Presses the search button (btnG) • “puts” (prints to screen) the new browser URL • closes the browser

2.3 Run your test file We’re now going to run this file in debug mode. To do this, either press “Shift + F6”, or select “Run” / “Run File” from the top menu. When the Windows Security Alert pops up, select “Unblock”.

You’ll only need to do this once. The IDE’s appearance will now change as the file is run.

Page 26: Installing Ruby on Windows XP - Dan Stra … · Open the windows Command Prompt by clicking on the start menu, and clicking “Run”. When the “Run” popup appears, ... Installing

Installing Ruby on Windows XP

Page 26 of 26

When it’s finished, click on the “Output – google_test” tab in the lower right pane. You will see the output of the script:

The important line here is:

http://www.google.co.uk/search?hl=en&source=hp&q=Watir+is+working%21&btnG=Google+Search

This is the new URL that the script “put” If you check the Command Prompt window where you earlier left Selenium open, you will also be able to see that Selenium has also been logging the output. And that’s it – you’re now ready for the ruby course and to run Watir & Ruby yourself.