Monday, November 10, 2014

Ruby for Beginners : The Basics

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It's very simple and easy to learn. So, this is a tutorial for beginners in which I shall be covering the basics of Ruby and gradually more tutorials will be posted.

If you have not yet already installed the Ruby on your machine, you can refer the Installation steps in this article to download the setup and starting coding.

Interactive Ruby is the smartest way for the beginners to start learning Ruby. It can be opened from the Start Menu of your Windows under the Ruby section, after the installation is complete. In case of Mac OS and Linux, you can open up the Terminal(Mac) or shell(Linux) and type the command irb and hit enter. Something like the below should be displayed when you open it.
irb(main):001:0>
Now, when any value is entered whether a number or a string, Ruby returns some value. Any piece is called 'Object' in Ruby.
irb(main):001:0> "Hello World"
=> "Hello World"
irb(main):002:0> 7
=> 7
Interactive Ruby is a calculator on its own. Simple mathematical calculations can be performed very easily on irb terminal, that include basic arithmetic operations(Addition, Subtraction, Multiplication, Division), exponent and remainder. Division is done based on the input type: Integer or Float.
irb(main):003:0> 4+5
=> 9
irb(main):004:0> 6-3
=> 3
irb(main):005:0> 3*2
=> 6
irb(main):006:0> 5/3
=> 1
irb(main):007:0> 5.0/3.0
=> 1.6666666666666667
irb(main):008:0> 2**3
=> 8
irb(main):009:0> 7%4
=> 3
String operation is also very easy to perform in Ruby. There are many methods for strings manipulation.
irb(main):010:0> "Hello World".length
=> 11
irb(main):011:0> "Hello "+"World"
=> "Hello World"
irb(main):012:0> "Hello ".concat("World")
=> "Hello World"
irb(main):013:0> "hello".capitalize
=> "Hello"
irb(main):014:0> "hello".reverse
=> "olleh"
irb(main):015:0> "hello".next
=> "hellp"
irb(main):016:0> "hello".upcase
=> "HELLO"
irb(main):017:0> "HELLO".downcase
=> "hello"
irb(main):018:0> "hElLo".swapcase
=> "HeLlO"
Variable can be used in Ruby right away without declaration. You just need to set the value of a variable and start using it. Variable name must begin with lowercase letter. Constants are the variables with first letter in uppercase.
irb(main):019:0> city = "Delhi"
=> "Delhi"
irb(main):020:0> age = 25
=> 25
Print and Puts command are used to print the value in Ruby. The print command just prints the value to the screen whereas puts adds a new (blank) line after value to be printed. Here, nil is returned by the commands which is Ruby’s absolutely-positively-nothing value.
irb(main):021:0> print "Hello"
Hello=> nil
irb(main):022:0> puts "Hello"
Hello
=> nil
These basics can be practiced in Interactive Ruby with ease which will give you the basic idea of how Ruby commands works. In next article, I will cover the Control Flow in Ruby.

Tuesday, October 28, 2014

What is Selenium Tool Suite?


Selenium automation is path-breaking achievement in terms of the features that it has and the tasks that it performs. There were many tools in the market before and after it but Selenium soon led the market in terms of the usage. And this is so because it's easy to learn, simple to use, free to download and effective in implementation. You can read more about selenium from my last article.

This article describes the tools those combinedly forms the Selenium Tool Suite; namely Selenium IDE, Selenium RC(Remote Control), Selenium Webdriver and Selenium Grid. These tools constitute as what we call Selenium Automation tool. Each tool has its purpose and should only be used based on that. So, how do you know which tool is best for you?

1. Selenium IDE


    Selenium Integrated Development Environment(IDE) is the Firefox plugin used to create test scripts. It can do a simple record-and-playback of the user interactions with the browser and then exports them as a reusable script in one of many programming languages that can be later executed. Due to its easy-to-use interface, it can be grasped very fast.

    It is a prototyping tool and has no support for iteration and conditional operations. Hence, it is advisable to use Selenium 2 or Selenium 1 for serious and robust test automation.

2. Selenium Remote Control(RC) or Selenium 1


    Selenium RC was the main selenium project for a long time before it was merged with Webdriver project to form Selenium 2. It support several languages (Java, Javascript, Ruby, PHP, Python, Perl and C#) and almost every browser. Selenium RC has two components:

  • The Selenium Server which launches and kills browsers, interprets and runs the Selenese commands passed from the test program, and acts as an HTTP proxy, intercepting and verifying HTTP messages passed between the browser and the AUT.
  • Client libraries which provide the interface between each programming language and the Selenium RC Server.

    It was successful in overcoming the Same Origin policy, through proxy injection. Previously, Selenium Core was unable to open the pages of the different domains.

3. Selenium Webdriver or Selenium 2


    Selenium Webdriver was developed to overcome the limitations of Selenium RC and is more advanced than Selenium IDE. It better supports dynamic web pages where elements of a page change without the page itself being reloaded. It has well-designed object-oriented API to interact with browsers. It supports all the languages and browsers supported by Selenium 1. Selenium 2 still runs Selenium 1’s Selenium RC interface for backwards compatibility.

    Webdriver does not rely on injected Javascript functions for automation unlike Selenium RC, instead it makes direct calls to the browser using each browser’s native support for automation.

4. Selenium Grid


    Selenium Grid is a tool that allows user to run the tests in parallel across multiple environments, thereby distributing the large test suite over different machines and different browsers. It runs the test simultaneously at the same time using different machine and hence saving the time and boosts the performance.


How to Choose the Right Selenium Tool:

Selenium IDE:
  • Learn the basics of Selenium and get familiar with the selenium commands.
  • Understand about locators and how to use them.
  • Create tests with little or no prior knowledge of automation.
  • Create quick bug reproduction scripts.
  • Save the test suite to various format and can also export to Selenium RC/Webdriver.  

Selenium RC:
  • Design the tests using more elaborate languages than Selenese.
  • Understand the primitive structure of selenium tool.

Selenium Webdriver:
  • Should be always given priority over Selenium RC excluding when the latter is only needed.
  • Create robust and browser-based regression automation.
  • Test dynamic webpages where elements changes constantly.
  • Create customized test results.

Selenium Grid:
  • Run test scripts across multiple browsers and operating systems simultaneously.
  • Run a large test suite by distributing it across and save time.

Reference: Selenium Tool Suite.

Tuesday, October 14, 2014

Selenium Automates Browsers


What is Selenium? The title says it all, Selenium automates browsers. It is though not just limited to automating the browser. In other words, Selenium is actually a suite of tools to automate web browsers across many platforms. It is a power packed tool for automation of your Application under Test(AUT) with its rich features that are hard to find in one tool.

Selenium was originally developed by Jason Huggins in 2004 at ThoughtWorks. He must have been a smart bored-to-the-core guy who preferred automating the tasks to avoid redundant manual effort. He created a sort of JavaScript library that formed that basis of Selenium Core. Selenium Core can be understood as the combination of Selenium RC and Selenium IDE. Finally in 2009, Selenium RC(Selenium 1.0) and Web driver, which was a separate project then, was merged and formed Selenium 2.0. Meanwhile in 2008, another tool Selenium Grid was developed.

Selenium Circle of Life 

This is the logo-ical representation of Selenium tool, which covers the platforms, browsers and programming languages supported by Selenium.

Features of Selenium:


1. Open Source Tool

    To say the least, Selenium is an Open source tool supported by vast community behind it. That means if some feature is not yet supported by selenium, there are people making it possible and soon selenium may support that feature. It can be downloaded free from the selenium downloads.

2. Multiple Browser and Operating Systems

    As shown in the image above, Selenium supports a wide variety of browsers and operating systems. Its support Windows, Mac and Linux platform on one hand and all major browsers like Chrome, Firefox, IE, Safari and Opera on the other. It also supports mobile platforms of Android, iOS, Blackberry and Windows phone, the drivers of which can be downloaded from the download section. More details about supported platforms.

3. Multiple Languages for Scripting

    Selenium supports multiple languages to write your selenium test cases. Eg. Java, Ruby, C#, JavaScript, Python, Php, Perl, Objective C, Haskell, R, Dart and Tcl.

4. Record and Playback

    It support recording the user interaction with browser and playing it back to user. This feature is only available through Selenium IDE which is a Firefox-only plugin.

5. Highly Flexible

    Selenium has its elaborate tool suite to cater to the need of the user. Each tool has its own area of functioning and should be used accordingly. Recorded tests through Selenium IDE can be converted to multiple programming languages and testing frameworks it supports. Selenium Grid distributes the tests over various nodes of different platforms.

6. Active Forum/Support Available

    This is the life support system of the Selenium. Any issues or bug can be reported to the forums in which active selenium users can respond and solve the queries.

Limitations:

1. Supports only the web-based application and cannot automate client-based, windows-based or desktop applications.
2. Do not support applications that use flash/flex or silverlight.
3. No inbuilt reporting capabilities but you can use JUnit, TestNG or NUnit for reporting purposes.
4. No object spy or object repository as in QTP.

Thursday, October 9, 2014

Ruby Installation


Ruby is a cross platform, interpreted and object-oriented language. You need to install Ruby, on any platform on which you wish, to be able to develop or run the existing Ruby programs. It can be easily installed on Windows, Mac OS and Linux/Unix.

Installing the Ruby is very simple and I would guide you through installation on Windows as a platform by using the Ruby Installer for Windows. It gives you everything you need to set up a full Ruby development environment on Windows. If you are having Mac or Linux platform or if you are interested to know about other ways to download the Ruby on your machine, I would suggest a read on Ruby Installation on its official site: Installation Link.

1. Download and Install:


     Download the latest version of Ruby 2.1.3 or you may also download the currently most stable Ruby 1.9.3. Once it is downloaded, double-click the installer to start the installation. Select language and agree to the terms; and then check the boxes as shown in the figure:


Select the check box to set the System Environment Variable Path to the bin folder of Ruby and associate .rb and .rbw files.
Click Install.

2. Ruby on Start Menu:


     Ruby is installed on your machine and can be seen in the Start Menu. It has different entries: Interactive Ruby, which is IRB in a standard command line window; RubyGems Documentation Server, which starts the web server and run the gem command to install the gems on your server; Start Command Prompt with Ruby, which start ruby in command prompt if environment variable is not set for ruby yet; and Documentation, which contains the Ruby API documentation.

3. Install an Editor:


     Install any editor to write the Ruby programs as Ruby installer does not come with an editor or IDE. You can write in Notepad, but it is boring and dull to write in there. So, editor that can be considered includes Notepad++, Programmers' notepad, Sublime text or Scite among others.

This is what all needs to be done to install Ruby. You can start learning Ruby from tutorials online and create your own programs.

Tuesday, September 30, 2014

Language don't Matter


After writing the first post on Ruby and why Ruby can be a good choice for the testers to start programming, now I will shift to selenium automation. Though the blog is dedicated to selenium community and will cover bite of selenium automation concepts, but I would prefer to stick to Ruby and Java as the medium of test implementation, the understood reason here being comfort :)

I have programming experience mostly in Ruby and Java, and I would like to focus more on Selenium with Ruby than Java with Ruby. Well, it is just a matter of choice to choose a language for Automation in Selenium as Language don't Matter here. It's well known that Selenium drivers supports a wide range of programming language- C#, Java, JavaScript, Objective C, Perl, Php, Phython, Ruby and some other lesser known languages.

If you see it is really an advantage selenium have over other automation tools that you are not bound to a particular language if you want to automate your tests. Simply, you don't have to learn another language. And mind it, that's really a big thing especially for tester who take initiative of learning a new language.

When I started coding years back, I used to think why we code that much, why the syntax matter too much, why am i need to remember all the code (though I stopped thinking on it once I learned about IntelliSense). Having said that if I look at the features Ruby give me as a programming language, I get most of my question answered, the answer being we need not! So, it gives you a high level programming syntax much more simple than strongly typed languages such as Java or C#. Moreover, it's a pure object oriented language and yes! everything in Ruby is an object, whether it is s variable or a method. And, if someday you eventually switch to web development, Ruby gives you the power that other languages lack, it being simple, less messy and more organised.

Not going farther and coming back to the point, I would point that automation in selenium is not restricted to your knowledge of a particular programming language and can be done in many languages. I would like the explore the tasty bites of selenium in the world of Ruby through my blog here. So, get connected and look out for more post on Ruby.

Wednesday, September 24, 2014

Ruby: A good pick for a tester to start Programming


Never actually learned programming. Don't have an idea how programming language can be mastered. Ever thought of starting programming and then dropped it. Afraid of syntax. Well, having yourself in the middle of these conditions, you may someday want to decide to start programming. You say, why not ! lets give it shot !!!

It's not that easy to learn a language to start programming in. But, then it's not that tough too. You just need an urge and patience and a hope. An urge to learn, the patience to keep going when code fails and a hope that one day you will have the confidence of writing lines of codes without compiling till the program is written well-off. So, starting to learn Ruby as your first programming is a good choice for every newbie, in general and testers, in particular(this blog is mostly dedicated to tester who want to learn programming and eventually move into Automation). Once, you learn one language it is easier to grasp other similar programming languages.

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. This is the description of Ruby copied from Wikipedia. It surely is dynamic programming language that means it is interpreted at runtime rather than compiled before execution, and can be used for writing software in a wide variety of application domains. It is higher level language and very easy to learn. 

Every language has a learning curve. After having the basic idea of the programming like data structures, objects, etc, the significant role is played by the syntax. It is the syntax that make the learning fast or slow. Once, you get the hold of it, things goes pretty smooth. People who have experience of programming in one language have the confidence to learn other languages for the very same reason because more or less syntax of different languages are similar. Ruby has far simple the syntax as compared to C++ or Java.

Though every language has its pros and cons. But, if you are choosing your first language you can definitely see Ruby as the best option and start creating cool websites in days to come. And, then you can always learn new languages and framework to enhance your skills and may switch to Java as well to broaden the purview.

Stay connected for more blog on the Ruby. I will be covering selenium also and will finally fuse the both to create Selenium automation framework in Ruby.