Continuous Integration with Jenkins (Windows 10 and Mac OS X)

For the CI Integration with our current project — we needed Continuous Integration (CI).  Jenkins can be your friend and easy to setup and get go. You need to have Jenkins Server on your machine and code repository should be stored in remote location or locally (preferred) and additional plugins can you give better reports, build to triggering configuration, different statistics and after build execution status. Our object was pretty simple — Keep the log in recored and cont the test script execution in different server (QA, Preprod and Production).
Perquisites:
  1. Jenkins .war file. Easy to run in windows and mac platform. Just write in console java -jar jenkins.war
  2. JDK 7 (Old version worked for the Microsoft Azure OS 10)
  3. All Permissions given to access and execute.

 

Jenkins Configuration For Windows 10:
  1. JDK should be pre-installed. Verify the existence of java –
  2. In command prompt run, java -jar jenkins.war
  3. http://localhost:8080/ — will be started and you need to access and configure it.
  4. You might receive this warning in Windows 10 -> WARNING: Symbolic links enabled on this platform (Solution)
  5. In configuration you need to do these: 
    1. Execute Windows batch command for Windows OS
    2. First line – show the code repository of your scripts
    3. Second line – Execution command line — it can be customized or followup with cucumber help for different formats. We are generating .json for the report. 
    4. Third line – Moving the recently created .json file to a directory — by using Cucumber JVM will populate report.

windows10

Jenkins Configuration for MAC OS X:
  1. JDK should be pre-installed. Verify the existence of java –
  2. In console simply run, java -jar jenkins.war
  3. http://localhost:8080/ — will be started and you need to access and configure it.
  4. In configuration you need to do these: 
    1. Execute Shell for Unix. 
    2. First line – show the code repository of your scripts
    3. Second line – Execution command line — it can be customized or followup with cucumber help for different formats. We are generating .json for the report. 
    4. Third line – Moving the recently created .json file to a directory — by using Cucumber JVM will populate report.

      macosx
    5. If you need to run all the Jobs — one after another, you can mention that here in below in post-build actions
      build
Note: 
  1. To setup plugins we need to access here and look for Cucumber JVM Reports. (Restart if required)

plugins

Testingbot Configuration For Cloud Testing In Multiple Browser

In my project, I’ve to cover several browsers and in different operating system. So, I’m using currently selenium webdriver to execute functional test automation by using cucumber testing tools and capybara library. If you want to play around with testingbot easily — get the hands dirty by downloading the project from github.

List of Browser & OS Coverage: 

  • Firefox (Windows OS, Mac OS X)
  • Chrome (Windows OS, Mac OS X)
  • Safari (Mac OS X)
  • IE browser 10 (Windows OS)
  • IE Browser 11
  • Microsoft EDGE Browser (Upcoming)

In Windows OS, we have OS 7 and OS 10. In Mac OS X, we have El Capitan, Yosemite.

Now, we have looked into some solutions. We have found Testingbot Integration can simply the solution and we can get test coverage of any browsers and operation on request.

Solution:

In env.rb file,

List of browser version/operating system declaration format has given at testingbot browser coverage


require 'capybara'
require 'capybara/cucumber'
require 'rspec'
require 'selenium/webdriver'
require 'testingbot/cucumber'

if ENV['TESTINGBOT_BROWSER']
  caps = {}
    caps[:browser] = ENV['TESTINGBOT_BROWSER'] || "chrome"
  caps[:version] = ENV['TESTINGBOT_BROWSERVERSION'] || "35"
  caps[:platform] = ENV['TESTINGBOT_BROWSEROS'] || :WIN10
  Capybara.default_driver = :testingbot
  Capybara.register_driver :testingbot do |app|
    client = Selenium::WebDriver::Remote::Http::Default.new
    client.timeout = 120
    Capybara::Selenium::Driver.new(app,
                                   :browser => :remote,
                                   :url => "http://clientkey:clientsecretkey@hub.testingbot.com:4444/wd/hub",
                                   :http_client => client,
                                   :desired_capabilities => caps)
end

else
  caps = Selenium::WebDriver::Remote::Capabilities.chrome
  caps.version = "35"
  caps.platform = :WIN10
  Capybara.default_driver = :testingbot
  Capybara.register_driver :testingbot do |app|
    client = Selenium::WebDriver::Remote::Http::Default.new
    client.timeout = 120
    Capybara::Selenium::Driver.new(app,
                                   :browser => :remote,
                                   :url => "http://clientkey:clientsecretkey@hub.testingbot.com:4444/wd/hub",
                                   :http_client => client,
                                   :desired_capabilities => caps)
  end
end



In lib/cucumber_helpber.rb file,


require 'capybara/cucumber'
require 'rspec/expectations'

Capybara.default_driver = :testingbot

Capybara.app_host = "https://trello.com"
Capybara.run_server = true
Capybara.default_wait_time = 5

In env file, you’ve to add Client key and Client Secret Key. Which is available under accounts settings of testingbot

That’s it. Enjoy.

References: For demo See this Link 

Virtualbox to run VIsual Studio 2013 in MAC OS X

Problems:

In my current project as I need to local environment to run the project. I’ve both MAC and Windows machine but switching back and forth is waste of time and I lose motivation and speed of work. Going through some hard time, I’ve decided lets resolve this situation and optimize the mac machine for visual studio 2013 and So, I go through some research and did the local environment setup very quickly and get the job done.

Requirements:

  1. VirtualBox for Mac
  2. Windows 7 Professional 32 Bit
  3. Microsoft SQL Server 2008 (No Link attached
  4. Visual Studio 2013 (No Link attached)
  5. My Project Source Code
  6. SQL QA Database Backup

Now, I’ve installed the Virtualbox and setup Windows 7. Few things, I wish to note and share

  1. At first, I took 25GB space for basic installation of SQL Server 2008 and Visual Studio 2013. Reached upto 22GB (Fixed)
  2. Then, I’ve shutdown the Windows 7 in Virtualbox
  3. I need E: Local DIsk to install the project
  4. From your Installed OS (Virtual box left side) list, click to settings -> Storage -> Add storage -> Continue within extra 10GB Space.
  5. Now, Once created. You have to recheck while within the Windows 7 System. Menu to Devices -> Insert Guest Additional CD Images — click to Install 2 things
  1. It will find your recently created E Drive. From Windows 7 Partition -> Give the format and make the drive or allocate the drive as E:/ and Active the partition.
  2. Now share between files and folder (Mac and Windows) — create the bridge by following menu to Devices -> Insert Guest Additional CD Images (Wait for reboot and let it happen)

 

In Action:

Additional:

  1. MAC Host to Guest (Windows 7), SSH Tunneling approach – http://prntscr.com/aoi4zk

Note:

  1. I’ve noticed some CPU 100% Consumtion issue while memory leaks. Some of the suggestions applied. Still in observation, will try to update eventually

Attention:

  1. It’s hard but I try to install most of the genuine software as much as possible. it’s hard to manage things but not impossible.

Setting up cucumber in rails project

Setting up cucumber in rails project is pretty much simple.

Lets do this:

From your unix environment, terminal to run one after another:

rails new my_projects
//rails g scaffold post title:string text:text
// rails g model comment post_id:integer text:text 
// rake db:migrate
// rails s

Now, open your Gemfile and add that block of code

group :test, :development do
  gem 'cucumber-rails', :require => false
  gem 'database_cleaner'
end

Once you’ve added. Run simply “bundle install”

rails generate cucumber:install

That’s it🙂. Now, you can have similar structure. You can start your project scratch.

Screen Shot 2015-12-06 at 8.41.56 PM

How to Click Text/Numbers Using Capybara and Cucumber

Problems:

We have a jquery date picker calendar. Now, we have to open the calendar and select a date. But selecting a link and selecting a date (number) is different.

Screen Shot 2015-11-22 at 2.17.17 PM

Issues to be discussed:

Cucumber contains a web step that allows you to easily click a link. But what if what you want to click is not a link, but some plain text like:



<h3 class='clickable-text'>Click me</h3>


Cucumber doesn’t have a web step for such case. so I needed an alternative approach. Capybara code that would click the text above.

find('.clickable-text', :text => 'Click me').click

Then I’ve got a cool idea. Let’s load them up…

Solutions:

Save the file at auto_posting.rb

And I want to make schedule posting with custom time and date

Given /^I want to make schedule posting with custom time and date$/ do
 find(:xpath, ".//*[@id='SocialHistory']").click
 find(:xpath, ".//*[@id='SocialDate']").click
 page.execute_script %Q{ $("input[id^='splash_']:contains('28')").trigger("click"); }
end

Save the file at auto_posting.feature

 

I needed to set custom date and so I refectored thus  I can bypass my date 29.

And I select 29 from the calender.

Given /^I select "([^"]*)" from the calender$/ do |date|
 find('.calendarDate', :text => date).click
end

Thanks a lot to automicobject and teamgaslight and gazler for the comments.

Simple Cucumber Installation in Windows 7

Problems:

  1. Installing cucumber in windows/pc is hard – mostly fails with so many errors😦
  2. It works sometimes and sometimes not😦
  3. Community and support is poor😦
  4. Not easily explained anywhere😦

So here YOU go:

Firstly:

  1. Visit Ruby Installer page and under left side Download Ruby 2.2.3(x32) or Ruby 2.2.3(x64). It depends on your PC wether it’s 32bit or 64 bit – download as accordingly.
  2. Install the downloaded rubyinstaller-2.2.3.exe file to c:/ drive (default location). And keep selecting (all), when options come to screen and move on next and complete the installation
  3. Now search for “Start command prompt with Ruby” and run this console.

Secondly: 

  1. Once again, Visit Ruby Installer page and under the “DEVELOPMENT KIT“, download DevKit-tdm-32…exe or DevKit-tdm-(x64)…exe. It depends on your PC wether it’s 32 bit or 64 bit – download as accordingly.
  2. Now unzip the DevKit-tdm-(x64)…exe file. And you will have a file named dk.rb.
  3. From “Start command prompt with Ruby”, locate the dk.rb or drag-drop this file to the console. 
  4. Once it will one on console, it will be like this
    c:\Users\users\ruby developmentkit\dk.rb init (hit enter)
  5. Again drag-drop the file to console, it will be like this
    c:\Users\users\ruby developmentkit\dk.rb  install (hit enter)

Thirdly:

Now we need to install few gem libary,

  1. gem install bundler #required 
  2. gem install cucumber

Forth:

  1. Download your cucumber projects and give this command “bundle install”.

Note:

  1. Ruby Installer and Development Kit preferred to install x64 or 32bit – depends on your PC. They have two version always there.
  2. To get color PASS/FAIL in windows console- Install Ansicon. Unzip the file, you will find x64/x32 – choose right one and ansicon (double click) or ansicon -i from console to install. It doesn’t work in 64bit at all. 
  3. Nokogiri is an HTML, XML, SAX, and Reader parser. It always messing up with windows setup. So, you need to setup manually.
    1. Download nokogiri desired version (mentioned in console or project requirement)
    2. Run this, gem install –local nokogiri-1.6.6.2-x86-mingw32.gem (just locate your file to console and hit enter)

Cucumber/Capybara: Run tests on Firefox, Chrome, Safari, Opera, Poltergeist/PhantomJS

The Problem:

Those are working with cucumber test automation – there is default browser given as Firefox. Firefox renders and performs best. But to give coverge on other platform and see how features functionality going on other browser – we must go through with other browsers too.

We need to cover up:

  1. Internet Exploer 10, 11
  2. Firefox – Mac/PC
  3. Chrome – Mac/PC
  4. Safari – PC

Pre-requsities:

  1. With the install Homebrew – http://brew.sh/ – to handle downloads for Chromedriver, Operadriver, Safaridriver, Poltergeist/PhantomJS in your machine
  2. Add these following lines and run “bundle”

gem 'capybara'
gem 'poltergeist'
gem 'selenium-webdriver'
gem 'cucumber'

Solution:

So, as we have cucumber_helper.rb file, replace with this code



require 'capybara/cucumber'
require 'rspec/expectations'

# Capybara.default_driver = :selenium  #disable default firefox

Capybara.app_host = "https://trello.com"
Capybara.run_server = true
Capybara.default_wait_time = 5

We need to disable it while we run the script.

As well, we have support/env.rb file, replace with these codes,


require 'capybara'
require 'capybara/cucumber'
require 'capybara/poltergeist'
require 'selenium-webdriver'


#pass environment variables to control which browser is used for testing. Default is HEADLESS/POLTERGEIST
#usage: firefox=true bundle exec cucumber features/test.feature


if ENV['chrome']
 Capybara.default_driver = :chrome
 Capybara.register_driver :chrome do |app|
 options = {
 :js_errors => false,
 :timeout => 360,
 :debug => false,
 :inspector => false,
 }
 Capybara::Selenium::Driver.new(app, :browser => :chrome)
 end
elsif ENV['firefox']
 Capybara.default_driver = :firefox
 Capybara.register_driver :firefox do |app|
 options = {
 :js_errors => true,
 :timeout => 360,
 :debug => false,
 :inspector => false,
 }
 Capybara::Selenium::Driver.new(app, :browser => :firefox)
 end
elsif ENV['safari']
 Capybara.default_driver = :safari
 Capybara.register_driver :safari do |app|
 options = {
 :js_errors => false,
 :timeout => 360,
 :debug => false,
 :inspector => false,
 }
 Capybara::Selenium::Driver.new(app, :browser => :safari)
 end
elsif ENV['opera']
 Capybara.default_driver = :opera
 Capybara.register_driver :opera do |app|
 options = {
 :js_errors => false,
 :timeout => 360,
 :debug => false,
 :inspector => false,
 }
 Capybara::Selenium::Driver.new(app, :browser => :opera)
 end
elsif
Capybara.default_driver = :poltergeist
 Capybara.register_driver :poltergeist do |app|
 options = {
 :js_errors => false,
 :timeout => 360,
 :debug => false,
 :phantomjs_options => ['--load-images=no', '--disk-cache=false'],
 :inspector => false,
 }
 Capybara::Poltergeist::Driver.new(app, options)
 end
end


Now, lets run the test on different browser:

Access your terminal and run any of it. And replace your desired brower and make sure you’ve pre-setup of web-drivers.


chrome=true bundle exec cucumber features/test.feature

Note: It might be working on Internet Explorer too. I’m still working on. I will let you know.