Monday, May 15, 2017

Load balance multiple selenium Grid hubs for Distributed testing




Load balance, your Selenium Grid hub servers to improve the testing speed. There are multiple providers available in the market to load balance your applications. Few open source softwares are
nginx, apache httpd, etc.,

This page will help you in setting up your selenium grid hub servers in a load balanced environment by using the nginx.

1. As a primary step install the nginx on your local machine. Those who use mac can use the home brew to install the nginx.
  command: brew install nginx
if the nginx is already installed and needs to be upgraded, then run "brew update nginx"

2. Run <ps -ef|grep "nginx"> to check if there are any nginx process running in the background.
   If you find any nginx process running, then either just stop the service or kill the process

3. Now, download the selenium-server-standalone jar file from the seleniumhq.org. This example uses "selenium-server-standalone-2.53.1.jar".

4. From the server directory, run the hub as follows


java -jar selenium-server-standalone-2.53.1.jar -role hub   --- call it ---- HUB A

17:24:16.808 INFO - Launching Selenium Grid hub
2017-05-15 17:24:17.359:INFO::main: Logging initialized @691ms
17:24:17.367 INFO - Will listen on 4444
17:24:17.402 INFO - Will listen on 4444
2017-05-15 17:24:17.405:INFO:osjs.Server:main: jetty-9.2.z-SNAPSHOT
2017-05-15 17:24:17.425:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@a74868d{/,null,AVAILABLE}
2017-05-15 17:24:17.445:INFO:osjs.ServerConnector:main: Started ServerConnector@5c072e3f{HTTP/1.1}{0.0.0.0:4444}
2017-05-15 17:24:17.446:INFO:osjs.Server:main: Started @779ms
17:24:17.446 INFO - Nodes should register to http://169.254.86.238:4444/grid/register/
17:24:17.446 INFO - Selenium Grid hub is up and running
17:40:18.394 INFO - Registered a node http://169.254.86.238:5555

5. From the same directory, create another hub as follows

java -jar selenium-server-standalone-2.53.1.jar -role hub -port 4445 ---- call it ---- HUB B

17:25:00.741 INFO - Launching Selenium Grid hub
2017-05-15 17:25:01.296:INFO::main: Logging initialized @696ms
17:25:01.304 INFO - Will listen on 4445
17:25:01.344 INFO - Will listen on 4445
2017-05-15 17:25:01.346:INFO:osjs.Server:main: jetty-9.2.z-SNAPSHOT
2017-05-15 17:25:01.371:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@a74868d{/,null,AVAILABLE}
2017-05-15 17:25:01.401:INFO:osjs.ServerConnector:main: Started ServerConnector@5c072e3f{HTTP/1.1}{0.0.0.0:4445}
2017-05-15 17:25:01.401:INFO:osjs.Server:main: Started @801ms
17:25:01.402 INFO - Nodes should register to http://169.254.86.238:4445/grid/register/
17:25:01.402 INFO - Selenium Grid hub is up and running
17:42:49.934 INFO - Registered a node http://169.254.86.238:5556
 
6. Now register a node to hub A as follows,


java -jar selenium-server-standalone-2.53.1.jar -role wd -hub http://localhost:4444/grid/register

17:40:17.905 INFO - Launching a Selenium Grid node
17:40:18.258 INFO - Java: Oracle Corporation 25.51-b03
17:40:18.258 INFO - OS: Mac OS X 10.11.6 x86_64
17:40:18.265 INFO - v2.53.1, with Core v2.53.1. Built from revision a36b8b1
17:40:18.316 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform MAC
17:40:18.316 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform MAC
17:40:18.316 INFO - Driver class not found: com.opera.core.systems.OperaDriver
17:40:18.316 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
17:40:18.318 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
17:40:18.318 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
17:40:18.356 INFO - Selenium Grid node is up and ready to register to the hub
17:40:18.376 INFO - Starting auto registration thread. Will try to register every 5000 ms.
17:40:18.376 INFO - Registering the node to the hub: http://localhost:4444/grid/register
17:40:18.395 INFO - The node is registered to the hub and ready to use

7. Now register a node to hub B as follows,

java -jar selenium-server-standalone-2.53.1.jar -role wd -hub http://localhost:4445/grid/register -port 5556

17:42:49.494 INFO - Launching a Selenium Grid node
17:42:49.817 INFO - Java: Oracle Corporation 25.51-b03
17:42:49.817 INFO - OS: Mac OS X 10.11.6 x86_64
17:42:49.820 INFO - v2.53.1, with Core v2.53.1. Built from revision a36b8b1
17:42:49.862 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform MAC
17:42:49.863 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform MAC
17:42:49.863 INFO - Driver class not found: com.opera.core.systems.OperaDriver
17:42:49.863 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
17:42:49.864 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
17:42:49.864 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
17:42:49.896 INFO - Selenium Grid node is up and ready to register to the hub
17:42:49.916 INFO - Starting auto registration thread. Will try to register every 5000 ms.
17:42:49.917 INFO - Registering the node to the hub: http://localhost:4445/grid/register
17:42:49.934 INFO - The node is registered to the hub and ready to use

8. Now you have setup 2 grid servers and registered a node each.

9. Let us now start configuring the nginx with a round-robin load balanced configuration.

add the following config to http node in the nginx configuration file "/usr/local/etc/nginx/nginx.conf"

    upstream gridapp {
      server localhost:4444;
      server localhost:4445;
    }

in the above, gridapp is loadbalanced name

Then update the server that listens on 80 port as follows.
server {
         listen 80;
         location / {
           proxy_pass http://gridapp;
         }
    }

This means, when users access http://localhost:80, nginx proxy passes to loadbalanced servers (localhost:4444, localhost:4445) named with gridapp.

To Test:
From your browser, hit http://localhost:80 and observe different nodes displayed.




Wednesday, December 7, 2016

Download Previous versions of Chrome Browsers

 Chrome Browser Versions:  Here are the links to download the previous versions of Chrome Browsers

https://commondatastorage.googleapis.com/chromium-browser-continuous/index.html
https://omahaproxy.appspot.com/

Saturday, November 19, 2016

Create Your First Angular application with npm, bower, angularjs

This post assumes you have already installed nodejs, npm on your machines. To start with let us use the terminal/sublime text editor to create our app which shows our name on the webpage.

Follow the steps to create your simple page.
1. Launch the terminal and create a directory named <ajs> anywhere in your drive. I chose "/Users/Yuvaraj" location to create the <ajs> directory.

    /Users/Yuvaraj> mkdir ajs

2. Navigate to the ajs directory.
    /Users/Yuvaraj> cd ajs

3. Now interactively create a package.json file in ajs directory by running the following command,
    /Users/Yuvaraj/ajs>npm init
     we should see the following questions on running this command.
 
     This utility will walk you through creating a package.json file.

It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (ajs) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /Users/Yuvaraj/ajs/package.json:

{
  "name": "ajs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Is this ok? (yes)

4. After generating the package.json file. Let us install http-server, bower libraries using the npm and save these dependencies into the package.json by running the following command.
   /Users/Yuvaraj/ajs>npm install --save http-server
   /Users/Yuvaraj/ajs>npm install --save bower
  Observe that http-server, bower are automatically saved into package.json file in the dependencies section and a folder node_modules is created with the libraries installed.

5. Now create an app directory where we put all the application code.
     /Users/Yuvaraj/ajs>mkdir app

6. Initialise bower by running the following command.  Make sure we see bower.json after running the command in app directory.
     /Users/Yuvaraj/ajs/app>bower init

7. After initialising the bower, install the angular dependency and save to the bower.json.
    /Users/Yuvaraj/ajs/app>bower install --save angular
   
    We observe that a new folder bower_components gets created in app folder with angular dependency added.   

8. Now edit the package.json file by adding a start script into the script section.

     "scripts": {
  "start": "http-server ./app -a localhost -p 2222",
        "test": "echo \"Error: no test specified\" && exit 1"
      },

With this step we are done with the setup. Once the setup is completed we can start creating the angular modules and bind them with the html.

9. Now create a app.js file in the app folder and put the following content in it.
 
    angular.module('yuvi', [])
     .controller('TestController', function TestController(){
         this.name = "Yuvaraj";
    });
 
10. Create a index.html in app folder and put the following html in it.
   
      <html ng-app='yuvi'>
       <head>
          <script type="text/javascript" src="/bower_components/angular/angular.js"></script>
<!-- this refers the angular.js file reference added from the bower dependencies installed -->
          <script type="text/javascript" src="app.js"></script>   <!-- this refers the app.js file that we have just created -->
        </head>

        <body ng-controller='TestController as testCtrl'>
            <h1>{{testCtrl.name}}</h1>
        </body>
     </html>

11. Now we are done with writing our simple app which displays our name. Now let us start our application by running the start script configured in our package.json.
 In the terminal run npm start command where the package.json file is available.

   /Users/Yuvaraj/ajs>npm start
   we must a message saying the server is started on a specific port with the url to the application.
    http://localhost:2222.

 Simply launch the url <http://localhost:2222> in the browser. We see "Yuvaraj" displayed as a header.
 

  

Friday, October 21, 2016

Launch Selenium Grid on Amazon EC2

Here are the steps to launch your selenium grid on ec2 instance.

1. To launch the selenium grid on ec2, you must have an aws console account.
2. Create a t2.micro instance through ec2 service in the console.
3. Click on Security groups link in the ec2 management console.
4. Click on the default/security group currently assigned to your instance.
5. Add the following protocol rules to the inbound and outbound traffic.
   Type: All TCP
   Protocol: TCP
   Port Range: 4444 / 0 - 65535 (default value)
   Source: 0.0.0.0/0
6. Using the keypair generated while creating the instance, connect to the box.
7. Create a folder <selenium>.
8. run the following command to download the selenium server jar file.
   wget http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.1.jar
9. Launch the grid using the following command
     java -jar selenium-server-standalone-2.53.1.jar.1 -role hub
10. Now, open your browser on your local machine and launch the grid url in the browser
      http://xxxxxxxxx:4444/grid/console

Next post will describe the steps to register the nodes to the grid....

Friday, September 16, 2016

How to Install Groovy Plugin in the Jenkins and write the groovy code in the console



Install the groovy plugin:

In order to install the groovy plugin in your jenkins server, first we download the the required (groovy) plugin from the plugin repository https://updates.jenkins-ci.org/download/plugins/groovy/.

The plugin extensions are hpi. Once the plugin is downloaded from the plugin repository, go to Manage Jenkins page and Manage Plugins page. Now goto Advanced tab, then chose the plugin file you have downloaded and click upload. This will install the groovy plugin on your jenkins server.

Write groovy code in the groovy script console.

 Refer the https://www.cloudbees.com/jenkins/juc-2015/presentations/JUC-2015-USEast-Groovy-With-Jenkins-McCollum.pdf

groovy Script vs System Groovy Script

The plain "Groovy Script" is run in a forked JVM, on the slave where the build is run. It's the basically the same as running the "groovy" command and pass in the script.

The system groovy script, OTOH, runs inside the Jenkins master's JVM. Thus it will have access to all the internal objects of Jenkins, so you can use this to alter the state of Jenkins

Where to store the script?

● Can put it in source and pull it from source
● Or you can put the script directly into the command box that is provided


Friday, March 25, 2016

Configure Protractor


Follow these steps to configure the protractor.

1. install npm from https://nodejs.org/download/release/npm/
2. install protractor using "npm install -g protractor"
3. install webdriver using webdriver-manager update.
4. start the selenium server using webdriver manager
     webdriver-manager start
5. Now protractor will accept the configuration file (protractor.conf.js).

   exports.config ={
         seleniumAddress: 'http://localhost:4444/wd/hub'
         jasmineNodeOpts:{
                  showColors: true,
                  defaultTimeoutInterval: 3000  

           }
     }

6. protractor can start the selenium server if we provide the path to the selenium server standalone jar. This will slow down the overall time it takes to run the tests due to protractor having to start the server as opposed to an instance already running:
seleniumServer: './node_module/protractor/selenium/selenium-server-standalone-2.42.0.jar'

https://github.com/angular/protractor/blob/master/docs/api.md

Sunday, January 31, 2016

SOAP mocking SOAPUI Groovy XML Parsing


Mocking is one of most regular tasks that testers need to do as part of their Job. Handling the mock using groovy bit challenging. Following is an example to parse the request xml and evaluate the xpath on the request xml.

Example:
import java.text.*
import groovy.lang.*
import java.util.*
import com.eviware.soapui.support.XmlHolder

def sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
def currentOrderId = new Date().getTime()
def holder = new XmlHolder(mockRequest.requestContent)
holder.namespaces['ns1'] = "http://xxxxxx/aaaaa/fffffffffffff/2.0/vvvvvvvv/4.0"
holder.namespaces['ns'] = "http://xxxxxx/aaaaa/ffffffffffffff/2.0/bbbbbbbb/4.0"
def nodeV2 =  holder.getDomNodes("//*")[3]
log.info nodeV2.getNodeName()
def hubId= nodeV2.attributes.getNamedItem("Hub").getNodeValue()

if(hubId.equals(400)){
context.setProperty("request1", hubId)
}


//def nodeV =  holder.getNodeValue("//ns1:OrderID")
//def nodeV =  holder.getDomNode("//ns1:OrderID")
//log.info nodeV.attributes.getNamedItem("id").getNodeValue()