Monday, October 4, 2010
Monthly Mobile Musings from September
Thursday, September 16, 2010
Setting up TeamCity CI w/ Cucumber, Flex, FunFX, and Firefox in a Headless Environment: Part Two
Recently I had the “opportunity” (read: challenge) to setup a continuous integration build for a project with a Flex frontend and a Ruby/Rails backend. The project had been converted from Java-Hibernate-Tomcat to Ruby on Rails. Cucumber was introduced for GUI testing using the FunFX adapter. It was my first experience with Cucumber, so the combination of Cucumber, FunFX, Flex, and Firefox was a little daunting at first. But we got through it and actually, it turned out to be quite an effective tool in our testing suite.
But the fun really started when I was tasked with building the TeamCity CI server for our project. And after it was all over, I felt I needed to document the trip so others might benefit from it, if not just for posterity. This is the second part of the two-part series on that journey.
Continuing…
In the first part we installed the open source software we are using: Java, Ruby, Rails, and all the required Ruby Gems, as well as the Flex 4.1.0 SDK, Firefox, FlashPlayer, and the Git client. The FunFX adapter for Cucumber uses JSSH to communicate with Firefox, so we configured and built Firefox with JSSH to run in a headless environment. We installed the latest Flex 4.1.0 SDK and the FlashPlayer 10.1 plugin for Firefox.
So what we have left is the installation and configuration of TeamCity itself as well as the setup of the build process for our Cucumber, Flex, and FunFX sample project.
So let’s get started.
Install TeamCity
Download the latest version of the Professional TeamCity software from the TeamCity web site for the appropriate platform. The Professional version is free but is limited in number of projects, build configurations, and users. We will only define one project and are well within the limit for build configurations.
We will be executing the installation instructions detailed on the TeamCity web site to install TeamCity bundled with the Tomcat servlet container on a Linux platform. They are relatively simple and are documented here. If you wish to install TeamCity to an existing Tomcat servlet container or on a different platform, please refer to the instructions for your specific environment.
We will be using the default admin user that we’ll define during installation. We will also be using HSQLDB and the default build agent. Most of the defaults will suffice for our installation.
Copy the TeamCity tar.gz file to the TeamCity server. SSH into the TeamCity server as yourself. Copy the TeamCity tar.gz file from /home/teamcity to /usr/local, unpackage the tar.gz file, and create a symlink to the TeamCity install directory. You will also need to change the owner of the TeamCity install directory to the 'teamcity' user.
$ cd /usr/local
$ sudo cp /home/teamcity/TeamCity-5.1.3.tar.gz .
$ sudo tar -xzvf TeamCity-5.1.3.tar.gz
$ sudo ln -s TeamCity teamcity
$ sudo chown -hR teamcity TeamCity
Logout as yourself and SSH into the TeamCity server as the ‘teamcity’ user. We will run the TeamCity CI server under this ‘teamcity’ user.
Since there is no physical display device attached to the TeamCity server, we need to indicate to TeamCity it will be running in headless mode. This is done by setting TeamCity’s java.awt.headless Java options property to true. You can either create a setenv.sh file in the bin directory or add the statement to the catalina.sh file. If you are installing TeamCity to execute in an existing Tomcat servlet container, add the statement to the catalina.sh file in its Tomcat installation’s bin directory.
$ cd /usr/local/teamcity/bin
$ echo 'JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"' > setenv.sh
$ chmod +x setenv.sh
You should also set the TEAMCITY_SERVER_MEM_OPTS and TEAMCITY_AGENT_MEM_OPTS environment variables as described in the instructions for the TeamCity startup options. Although these values may vary according to your build requirements, we set our values as follows:
| TEAMCITY_SERVER_MEM_OPTS | -Xms512m -Xmx1024m -XX:MaxPermSize=1024m |
| TEAMCITY_AGENT_MEM_OPTS | -Xms512m -Xmx1024m -XX:MaxPermSize=1024m |
Start the server with the following command:
$ sh /usr/local/teamcity/bin/runAll.sh start
Then bring up the TeamCity application in a local browser (http://localhost
Create a CI Project
After creating the administrator account, you are presented with the Projects page. Select the Create Project link. Enter the appropriate values in the respective fields of the resulting screen:
| Name: | FC Converter |
| Description: | Fahrenheit to Celsius Conversion project |
Press the Create button.
Next we will associate the project with a version control system. Select the VCS Roots tab and then the +Create VCS root link.
Enter an appropriate VCS rootname and select the type of VCS from the dropdown.
The remainder of the screen is refreshed with the fields for the respective VCS. We are illustrating Git here. Enter / select as appropriate for the respective fields:
| VCS rootname: | fc_converter-root |
| Type of VCS: | Git (Jetbrains) |
| Fetch URL: | git://github.com/landerson/FC-Converter.git |
| Push URL: | (leave blank to use Fetch URL) |
| Branch name: | master |
| Clone repository to: | checkout |
| User Name Style: | Userid(jsmith) |
| Submodules: | Checkout |
| Authentication Method: | Anonymous |
| User name: | (leave blank) |
| Path to git: | /usr/bin/git(or as appropriate) |
| Clean Policy: | (as appropriate) |
| Checking Interval: | (as appropriate) |
Press the Test Connection button to test the SSH handshake with github. The test should succeed. The test must succeed in order for the TeamCity build configuration to work properly. After the test succeeds, press the Save button.
Select the General tab to return to the main project page. It is from this page that we will create the build configuration for this CI project.
We will create the following build configuration steps:
- checkout the project from the source repository and update the Ruby gems,
- compile the Flex source modules,
- restart the webserver, and
- run the Cucumber FunFX tests.
First we will create a build step to gather the sources and update any required Ruby Gems. Select the +Create build configuration link. Enter the following in the respective fields of the resulting General Settings screen:
| Name: | Step 1- Collect Sources |
| Description: | Checkout sources and update gems. |
| Fail build if: | check ‘an error message is logged by build runner’ |
Leave the remaining fields blank or checked as-is to accept the defaults.
Press the VCS Settings button and enter the following in the respective fields of the resulting Version Control Settings screen:
| +Attach existing VCS root: | fc_converter-root |
| VCS checkout mode: | Automatically on server |
| Checkout directory: | checkout |
| VCS labeling mode: | Do not label |
| Choose VCS roots to label: | (leave blank- do not check) |
The “Automatically on server“ selection will cause the project source to be checked out of the source repository into the TeamCity project working directory.
Press the Choose Build Runner button and enter the following in the respective fields of the resulting Build Runner screen:
| Build runner: | Rake |
| Rake tasks: | gems:install |
Uncheck any Attached reporters that may be checked and leave the remaining fields blank.
Press the Save button to create the build configuration. The screen is refreshed and should show the following message:
Build configuration "Step 1- Collect Sources" has been created successfully.
Select FC Converter Project in the Administration > FC Converter Project > Step 1 ... banner line just under the tabs at the top of the page to return to the main project page. If you named your project differently, your project ‘s name will appear in the banner line.
Next we will create a build step to compile the Flex source modules. Select the +Create build configuration link. Enter the following in the respective fields of the resulting General Settings screen:
| Name: | Step 2- Flex Compiles |
| Description: | Compile the Flex source modules. |
| Fail build if: | check ‘an error message is logged by build runner’ |
Leave the remaining fields blank or checked as-is to accept the defaults.
Although we are not checking out the sources in this step (or any subsequent step), we still need to specify the VCS settings to tell TeamCity where the sources are, e.g., in the checkout directory. Press the VCS Settings button and enter the following in the respective fields of the resulting Version Control Settings screen:
| +Attach existing VCS root: | fc_converter-root |
| VCS checkout mode: | Do not checkout files automatically |
| Checkout directory: | checkout |
| VCS labeling mode: | Do not label |
| Choose VCS roots to label: | (leave blank) |
Press the Choose Build Runner button and enter the following in the respective fields of the resulting Build Runner screen:
| Build runner: | Rake |
| Rake tasks: | flex:compile |
Uncheck any Attached reporters that may be checked and leave the remaining fields blank.
Press the Save button to create the build configuration. The screen is refreshed and should show the following message:
Build configuration "Step 2- Flex Compiles" has been created successfully.
Under the right hand column titled Configuration Steps, select 6 Properties and Environment Variables. On the resulting screen, select +Add new variable under Environment Variables. Enter the following in the respective fields of the resulting screen:
| Name: | FLEX_HOME |
| Value: | /usr/local/flex_4_sdk |
and press the Save button.
Again, select FC Converter Project in the Administration > FC Converter Project > Step 1 ... banner line just under the tabs at the top of the page to return to the main project page. If you named your project differently, your project ‘s name will appear in the banner line.
Next we will create a build step to restart the Rails web server. Select the +Create build configuration link. Enter the following in the respective fields of the resulting General Settings screen:
| Name: | Step 3- Restart the Web Server |
| Description: | Stop and start the Rails web server. |
| Fail build if: | check ‘an error message is logged by build runner’ |
Leave the remaining fields blank or checked as-is to accept the defaults.
Although we are not checking out the sources in this step we still need to specify the VCS settings to tell TeamCity the sources are in the checkout directory. Press the VCS Settings button and enter the following in the respective fields of the resulting Version Control Settings screen:
| +Attach existing VCS root: | fc_converter-root |
| VCS checkout mode: | Do not checkout files automatically |
| Checkout directory: | checkout |
| VCS labeling mode: | Do not label |
| Choose VCS roots to label: | (leave blank) |
Press the Choose Build Runner button and enter the following in the respective fields of the resulting Build Runner screen:
| Build runner: | Rake |
| Rake tasks: | webserver:stop webserver:start |
| Additional Rake command line parameters: | RAILS_ENV=cucumber |
Uncheck any Attached reporters that may be checked and leave the remaining fields blank.
Press the Save button to create the build configuration. The screen is refreshed and should show the following message:
Build configuration "Step 3- Restart the Web Server" has been created successfully.
Again, select FC Converter Project in the Administration > FC Converter Project > Step 1 ... banner line just under the tabs at the top of the page to return to the main project page. If you named your project differently, your project ‘s name will appear in the banner line.
Finally, we will create a build step to run the Cucumber FunFX tests. Select the +Create build configuration link. Enter the following in the respective fields of the resulting General Settings screen:
| Name: | Step 4- Run Cucumber Tests |
| Description: | Run the Cucumber FunFX Tests. |
| Fail build if: | check ‘an error message is logged by build runner’ |
Leave the remaining fields blank or checked as-is to accept the defaults.
Although we are not checking out the sources in this step we still need to specify the VCS settings to tell TeamCity the sources are in the checkout directory. Press the VCS Settings button and enter the following in the respective fields of the resulting Version Control Settings screen:
| +Attach existing VCS root: | fc_converter-root |
| VCS checkout mode: | Do not checkout files automatically |
| Checkout directory: | checkout |
| VCS labeling mode: | Do not label |
| Choose VCS roots to label: | (leave blank) |
Press the Choose Build Runner button and enter the following in the respective fields of the resulting Build Runner screen:
| Build runner: | Rake |
| Rake tasks: | ci:features |
Uncheck any Attached reporters that may be checked and leave the remaining fields blank.
Press the Save button to create the build configuration. The screen is refreshed and should show the following message:
Build configuration "Step 4- Run Cucumber Tests" has been created successfully.
Under the right hand column titled Configuration Steps, select 6 Properties and Environment Variables. On the resulting screen, select +Add new variable under Environment Variables. Enter the following in the respective fields of the resulting screen:
| Name: | DISPLAY |
| Value: | localhost:1.0 |
and press the Save button.
Again select +Add new variable under Environment Variables. Enter the following in the respective fields of the resulting screen:
| Name: | CUCUMBER_FORMAT |
| Value: | progress |
and press the Save button.
Select the Projects tab in the top left of the screen to display the build configuration steps for the FC Converter project.
Perform First Build
We’re now ready to execute our first build. We will use the first build configuration step we created to clone the project source for the first time.
To run the first step, press the Run button to the left on the Step 1- Collect Sources line. This will add the step to the build queue and it should begin executing immediately. You should see the 'Running:...' message underneath the step title line within seconds. When the step has completed, 'Running:...' should be replaced with 'Success'.
To view the output of the build step, hover the mouse pointer over the down arrow adjacent to the 'Success' label and select the 'Full log' choice in the resulting drop down menu. Take note of the checkout directory in the log - we will reference this later.
| [10:19:14]: Checkout directory: /usr/local/TeamCity/buildAgent/work/fc_converter [10:19:14]: Updating sources: server side checkout... [10:19:14]: [Updating sources: server side checkout...] Will perform clean checkout. Reason: Checkout directory is empty or doesn't exist [10:19:14]: [Updating sources: server side checkout...] Building clean patch for VCS root: fc_converter-root [10:19:14]: [Updating sources: server side checkout...] Repository sources transferred: 2.59Mb total [10:19:14]: [Updating sources: server side checkout...] Removing /usr/local/TeamCity/buildAgent/work/fc_converter [10:19:14]: [Updating sources: server side checkout...] Updating /usr/local/TeamCity/buildAgent/work/fc_converter |
This is the directory that contains the source for the FC Converter project. Press the browser's back button to return to the FC Converter project page.
The remaining steps of the build process can be setup to automatically run after successful completion of the immediately previous step. We’ll describe how to do this using the second step as an example. Then you can repeat the process for the third and fourth steps, selecting the appropriate preceding step in each.
Hover the mouse pointer over the down arrow immediately following the title of the second step, Step 2- Flex Compiles, to expose the dropdown menu. Select Edit Settings from the dropdown menu and the General Settings page for the step is displayed.
Select Build Triggering from the list under the Configuration Steps heading on the right margin of the page. We are going to add a build dependency trigger. Select the +Add new trigger link and then select Build Dependency Trigger in the Trigger Type dropdown of the pop-up window. Select Step 1- Collect Sources from the Build Configuration drop down and press Save.
Select the Projects tab at the top of the page to return to the FC Converter project page. Repeat the steps above starting with hovering the mouse pointer for the remaining two steps, selecting the previous step as a build dependency.
When you have finished setting the dependencies, press the Run button in the right margin of the Step 2- Flex Compiles step to launch the remainder of the build process. Each step will execute upon successful completion of the previous step. You can view the results of an individual step by hovering the mouse pointer over the down arrow immediately following the ‘Success’ status label under the step title and selecting either ‘Short log’ or ‘Full log’.
Points of Interest…
Referencing the checkout source directory of the FC Converter project (/usr/local/TeamCity/buildAgent/work/fc_converter)…
In the features/support directory you will notice two files: env.rb and firewatir_firefox_patch.rb. Files in the support directory are loaded by Cucumber prior to running features. The purpose of env.rb is to set up the environment for running features. The purpose of firewatir_firefox_patch.rb is as its name indicates: a patch for the FireWatir::Firefox class. The patch is to support a headless Firefox environment by pre-pending DISPLAY to the command that invokes Firefox.
The features/step_definitions directory contains the fc_converter_steps.rb file which defines the templates for the Cucumber steps used in the features/fc_converter.feature file.
Some things you may want to investigate on your own:
- Setting a build trigger for the first step dependent on SCM updates.
- Adding more features and Cucumber steps to support them.
- Generating some reports from the TeamCity server.
- Setting up email notifications on successful and / or failed builds.
Conclusion…
Although our project is a very simple example of using Cucumber, Flex, FunFX, and Firefox, the purpose of this article is to illustrate the setup of the server environment to support a remote, headless, continuous integration environment. And although it’s a little complex, it’s a once-and-done thing. Setting up TeamCity is relatively simple.
Hopefully the log of this journey has helped you in your quest to get Cucumber FunFX tests running in a remote CI environment.
Oh, and if you’re inclined, Chariot Solutions is running a CI event this fall.
In the future, look for a sister post to this one where we’ll use Hudson as our CI server.
Friday, September 3, 2010
Setting up TeamCity CI w/ Cucumber, Flex, FunFX, and Firefox in a Headless Environment: Part One
Recently I had the “opportunity” (read: challenge) to setup a continuous integration build for a project with a Flex frontend and a Ruby/Rails backend. The project had been converted from Java-Hibernate-Tomcat to Ruby on Rails. Cucumber was introduced for GUI testing using the FunFX adapter. It was my first experience with Cucumber, so the combination of Cucumber, FunFX, Flex, and Firefox was a little daunting at first. But we got through it and, actually, it turned out to be quite an effective tool in our testing suite.
But the fun really started when I was tasked with building the TeamCity CI server for our project. I scoured the blogs and tech sites for anything about CI builds of a Flex-Ruby/Rails project with Cucumber and FunFX. I found bits and pieces, like how to setup Firefox in a headless environment and how to setup TeamCity in a headless environment. So I filled in the rest around that to get the TeamCity server up and running with a continuous integration build for our project.
So why is a headless environment required? Our TeamCity CI server was a remote server- there is no input device or display device. So all of the setup was done via SSH through a VPN. But more importantly, we needed a headless implementation since FunFX requires browser interaction. FunFX “attaches” itself to a browser (via JSSH) so we needed a windowing emulator. We use the X virtual frame buffer of the X Window System (Xvfb) for this purpose (more about Xvfb at http://en.wikipedia.org/wiki/Xvfb).
After it was all over, I felt I needed to document it, if not just for posterity, but also so others might benefit. Since setting up the environment is as much an effort as setting up TeamCity, I decided to break it into two parts. So we’ll cover the basics of setting up the server in this first part and then in the second part we’ll tackle getting TeamCity set up. I hope you enjoy the trip as much as I did.
We're using a Debian-based system in this prensentation. We’re going to assume you’re familiar with your operating system and know what most of these commands are. Hopefully you can translate to your operating system, if different.
Basically, this is what we need to do:
· Install Java
· Install Ruby and Rails
· Install Flex SDK
· Install and Configure Firefox
o Test JSSH
o Install FlashPlayer
· Install the SCM Client
· Install TeamCity
o Create the CI project
o Create the build steps
o Run the build
So Let’s Get Started…
Because our Flex-Ruby/Rails project was a bit more complicated than what’s needed, plus it involved other requirements that do not need to be documented here, we’re going to use a small sample project, FC_Convert, an interface to convert Fahrenheit to Celsius. I have uploaded the project to my public github account and we reference it in these procedures.
First create a user account on the TeamCity server for the ‘teamcity’ user. This will create a /home/teamcity directory which we will be using. All downloads are to a local workstation and then copied to this home directory of the ‘teamcity’ user on the TeamCity server. It is assumed you will also have your own account on the TeamCity server with sudo capability that you can use to SSH for all of these tasks.
Install Java
Since this is a Ruby/Rails and Flex project, we do not need the JDK. For our project we are installing the JRE since TeamCity requires either the JRE or a JDK. If your build process requires Java, you’ll need to install the JDK.
Visit the Java website and download either the JRE or the JDK for the operating platform of your TeamCity server. Install the JRE or JDK per the installation instructions. In addition to adding the Java bin directory to the PATH environment variable, don’t forget to set the JAVA_HOME environment variable to point to the Java installation directory- TeamCity requires it.
Install Ruby and Rails
As of this writing, the latest version of FunFX (0.2.2) had a conflict with Ruby 1.9.1. Ruby 1.9.1 now includes FasterCSV but with renamed variables and methods. If you install Ruby 1.9.1 and then run FunFX, you will get the following message:
Please switch to Ruby 1.9's standard CSV library. It's FasterCSV plus support for Ruby 1.9's m17n encoding engine. |
FunFX uses the FasterCSV library and requires modification to run with Ruby 1.9.1. Since there are no features of Ruby 1.9.1 that we need for this project, we are installing Ruby 1.8.7 instead.
Installing Ruby and Rails is pretty straightforward. Depending on the platform of the server, Ruby can be installed as a set of pre-compiled executables (Windows) or compiled for the specific platform (Linux, Unix). The distribution files for Ruby installation can be found on the Ruby downloads web page.
And if your server’s operating system has a package installer, i.e., apt-get or yum, it’s even easier to install the latest version of Ruby 1.8:
$ sudo apt-get install ruby-full |
Otherwise, download the source tar, unpackage it, and then configure, build, and install Ruby.
$ cd /usr/local/src $ sudo tar -xzvf ruby-1.8.7-p302.tgz $ cd ruby-1.8.7-p302 $ sudo ./configure |
After Ruby is installed, you need to install the Ruby Gems package manager. Ruby Gems binaries can be downloaded from the project's download page. Again, check your server package installer first.
$ sudo apt-get install rubygems |
If the package installer is not available, download the RubyGems distribution file from the site, unpackage it, and install the package manager by running setup.rb in the install directory:
$ cd /usr/local/src $ sudo tar -xzvf rubygems-1.3.7.tgz $ cd rubygems-1.3.7 |
Installing Rails is a snap using the gems package manager.
$ sudo gem install rails |
Next you need to install any gems required by your application. Add your required gems to the list. NOTE: FunFX requires version 1.6.2 of the firewatir gem. Install it separately specifying the version.
$ sudo gem sources -a http://gems.github.com $ sudo gem install –v 1.6.2 firewatir |
Install Flex SDK
The Flex SDK and Flex compiler come in several flavors: Flex 3 or Flex 4, and Adobe Flex or Open Source Flex (not quite as feature rich as Adobe Flex). For purposes of this presentation, we’re installing the open source edition of Flex 4 and the Flex compiler. Visit the Adobe Open Source Flex web site Flex 4 downloads page and download the Flex 4 Open Source SDK zip file (we are installing Flex 4.1.0 SDK) as well as the Adobe Add Ons zip file.
Create the flex_4_sdk directory, unpackage the zip files, and set execute permissions on the bin, lib, and frameworks directories. If prompted to replace any files, reply yes.
$ cd /usr/local $ cd flex_4_sdk $ sudo unzip /home/teamcity/flex_sdk_4.1.0.16076_mpl.zip $ sudo unzip /home/teamcity/flex_sdk_4.1.0.16076_add_on.zip $ sudo chmod –R 755 /usr/local/flex_4_sdk/bin $ sudo chmod –R 755 /usr/local/flex_4_sdk/lib $ sudo chmod –R 755 /usr/local/flex_4_sdk/frameworks |
Install and Configure Firefox
Now it gets a little more difficult. Firefox must run as a headless application (no display device). We use the X virtual framebuffer of the X Window System (Xvfb) for this purpose (more about Xvfb at http://en.wikipedia.org/wiki/Xvfb).
First, insure Xvfb is installed on your system.
$ which Xvfb |
If this command does not return the location of Xvfb, it is not installed. Install it with your system’s package installer.
$ sudo apt-get install Xvfb xinit |
Start Xvfb and create a virtual display. This only needs to be done once on the server and after every reboot. Ideally, it could be started in a script that is run whenever the server is restarted.
$ startx – ‘which Xvfb’ :1 -screen 0 1024x768x24 & |
And since we will not have a browser window to install the JSSH plugin, we must build Firefox from source as opposed to installing binaries. But prior to building Firefox, you must insure your system has all the necessary development tools required to build an application. Here is a list of the development libraries I needed to load prior to executing a successful build of Firefox from source. I used the apt-get package manager for my Debian-based system.
$ sudo apt-get install libgtk2.0-dev $ sudo apt-get install libdbus-glib-1-dev $ sudo apt-get install libasound2-dev $ sudo apt-get install libIDL-dev $ sudo apt-get install build-essential gcc-3.4 $ sudo apt-get install libxt-dev $ sudo apt-get build-dep mozilla-thunderbird |
As of this writing we are installing the latest release of Firefox 3.5, 3.5.11. The Firefox 3.5.11 source code is available from the Mozilla repo at ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.5.11/source/. Download the firefox-3.5.11-source.tar.bz2 file from the site, copy it to the TeamCity server, and unpackage it.
$ cd /usr/local/src $ sudo mkdir firefox-3.5.11 $ cd firefox-3.5.11 |
Before building Firefox, we need to add configuration parameters to the mozilla configuration by creating a .mozconfig file if it does not exist. If it does exist, it should be modified to look like this:
$ cd mozilla |
This file is used in configuring the options to be used in building the Firefox application. Set the MOZCONFIG environment variable to point to this file and build Firefox.
$ export MOZCONFIG=/usr/local/src/firefox-3.5.11/mozilla/.mozconfig $ sudo make -f client.mk build |
Create a symlink to the firefox binary in /usr/local/bin:
$ sudo ln -s /usr/local/src/firefox-3.5.11/mozilla/firefox-jssh/dist/bin/firefox /usr/local/bin/firefox |
Test JSSH
We use FunFX for Flex testing. FunFX is a Watir / SafariWatir / FireWatir extension that lets you talk to an Adobe Flex application straight from Ruby. Firewatir is a Ruby gem that uses the Firefox JSSH connection. We need to first create a Firefox profile for use by the Cucumber FunFX tests so we can modify the default settings. We’ll name it firewatir.
SSH into the TeamCity server as the ‘teamcity’ user and create the firewatir profile.
$ DISPLAY=localhost:1.0 firefox -CreateProfile firewatir |
This creates a profile directory in the /home/teamcity/.mozilla/firefox directory for firewatir. The directory name for the profile is a two-part name: the first part is a randomly generated string of 8 letters and numbers; the second is the profile name specified in the -CreateProfile command- in our case, firewatir.
A skeleton file named prefs.js is created in this directory. The default configuration settings can be overridden for a particular profile by including them in the prefs.js file in this directory. Normally this file is maintained by Firefox. Typically, configuration changes are made via the about:config URL. But we need to modify this file since we do not have access to the about:config URL in a headless environment.
Modify the prefs.js file to contain the following:
$ cat .mozilla/firefox/vrvkdf9e.firewatir/prefs.js # Mozilla User Preferences /* Do not edit this file.
user_pref("app.update.auto", false); |
You will need two SSH sessions to test JSSH. SSH into the TeamCity host server as yourself for this test. Start Firefox in the teamcity user SSH session (Note: Xvfb must have been started prior to this. See above.):
$ DISPLAY=localhost:1.0 firefox -jssh 9997 -P firewatir |
Then use telnet to connect to JSSH in the other SSH session (enter Ctrl-] to exit the shell):
$ telnet localhost 9997 |
Terminate Firefox in the first SSH session via Ctrl-C. If you do not do this and Firefox remains executing, you may have difficulty running your first Cucumber test.
Install FlashPlayer
Since we’re using Flex for the client interface, we need to install the Adobe Flash Player as a plugin to Firefox. Unlike a development system that has a browser window with which to interact requiring the debug version of Flash Player, we do not need the debug version for the headless version of Firefox.
Flash Player can be downloaded from here. The installation instructions can be found here but are simple and are documented as follows.
Note: Firefox should not be executing when these installation procedures are executed.
Download the tar.gz file and copy it to the TeamCity host server. SSH into the host server as the 'teamcity' user and unpackage the tar.gz file. Create a plugins directory in the 'teamcity' user's .mozilla directory (if it does not exist) and move the unpackaged libflashplayer.so file to the plugins directory.
$ tar -xzvf libflashplayer-10.0.45.2.linux-x86_64.so.tar.gz |
Install the SCM Client
We are using Git for our sample project. Git binaries can be downloaded from here. You can also install git using your system’s package manager.
$ sudo apt-get install git |
If you are using your own project for this exercise, install your SCM client as appropriate.
That’s it for this session. Next time we’ll setup TeamCity and create a sample project.