Tech It Easy: 2015

Tuesday, 22 December 2015

Geb - "get into the groove(y)" - the way I used it


Dear friends,

I am back with a new post cheers

Image Courtesy: http://www.123rf.com/photo_5468266_boy-with-computer.html

As a continuation to my earlier post on Geb(pronounced as 'Jeb')
http://techiteasypolicy.blogspot.in/2015/04/geb-very-groovy-browser-automation.html , I am here with a new tool/candy I created and using in my day to day work.


I personally feel that this is a groovier (funny) or viral way of using Geb though it is meant for Web Automation Testing.

The Problem:
Each time when I want to open my application in some browser like chrome for testing or what ever, the following are the sequence of things I do (it is pretty similar with every other web based project or application)

If you want, use it at your own discretion

1. Open the browser
2. Put the URL in the URL bar (or clicking the bookmark)
3. As my app starts with a login page, I provide username, password (is a trivial one and not that sensitive),
4. Click on Submit button to login  and proceed with my intended work.

Rescue:
Here comes the Geb script to rescue us,

To run the following script you need groovy in the path.

Then run the following command in command prompt (assuming that in the current path there is a file named appTrigger.groovy and it has the following piece of code in it)

groovy appTrigger.groovy

@Grab('org.gebish:geb-core:0.10.0')
@Grab('org.seleniumhq.selenium:selenium-chrome-driver:2.43.1')
@Grab('org.seleniumhq.selenium:selenium-support:2.43.1')
import geb.Browser

Browser.drive {
    go 'http://localhost:8080/myApp/' 
    $ '#gwt-debug-login-username' value 'Superuser'
    $ '#gwt-debug-login-password' value 'Superuser'
    $ '#gwt-debug-login-submit-button' click()
}

That's it, Geb does the heavy lifting for you.

Actually, it is not just login submission, its about the Web browser and automating user interactions with it. Hence you can extrapolate it and use it in your own way.

Going one step further (Externalizing the URL and username and password into a config.properties file)

@Grab('org.gebish:geb-core:0.10.0')
@Grab('org.seleniumhq.selenium:selenium-chrome-driver:2.43.1')
@Grab('org.seleniumhq.selenium:selenium-support:2.43.1')
import geb.Browser

config = new Properties()
new File('config.properties').withInputStream { config.load it }
Browser.drive {
    go config.url
    $ config.username_selector value config.username 
    $ config.password_selector value config.password
    $ config.button_selector click()
}


//config.properties
url=http://localhost:8080/myApp/
username=Superuser
password=Superuser

username_selector=#gwt-debug-login-username
password_selector=#gwt-debug-login-password
button_selector=#gwt-debug-login-submit-button

Going still further with Gradle's application plugin we can create a jvm application Distribution with which user with plain Java installed in their machine can run this tool. Long live Gradle :)

The distribution Zip file created by by above Gradle plugin has every thing required to run the app without the Sophisticated build tools and/or IDEs.

Code for the above said Gradle based App is in my GitHub repository https://github.com/PraveenGandhi/geb-based-tool-to-open-app, feel free to hack it.

 Hope you enjoy this.

PS: I have used password here, please don't use your sensitive passwords like net-banking credentials  etc.


Monday, 13 July 2015

ngChat - 3 way data binding


Dear Angular Friends,

I made an app (simple html page of 66 lines) with Angular and Firebase (AngularFire). Please have a look at it.

Any one who has GMail account can login in to this app and chat with others.



Demo: http://praveengandhi.github.io/ngChat.html

Source: https://github.com/PraveenGandhi/PraveenGandhi.github.io/blob/master/ngChat.html


In AngularJs we have seen 2-way data binding, with AngularFire we archive 3-way data binding which is cool, isn't it.



Code below:



<html ng-app="myChatRoom">
  <head>
    <title>Chat</title>
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <link rel="shortcut icon" href="img/stvd.png">
  </head>
  <body>
  <div class="container">
  <div ng-controller="ChatCtrl">
    <div id="login">
      <span ng-show="auth.user">
        <img ng-src="{{auth.user.thirdPartyUserData.picture}}" width="40" height="40"/>
        Hello {{auth.user.displayName}}...! | <a href="#" ng-click="auth.$logout()" class="btn btn-default">
        <span class="glyphicon glyphicon-log-out"></span> Logout</a>
      </span>
      <a class="btn btn-info btn-lg btn-block" ng-hide="auth.user" ng-click="auth.$login('google')">
 <span class="glyphicon glyphicon-envelope"></span> Log in with Gmail</a>
    </div>
      <div ng-show="auth.user">
    <p class="bg-info velocity-opposites-transition-slideLeftIn" data-velocity-opts="{ stagger: 150 }" ng-repeat="message in messages">
      <img ng-src="{{message.from.thirdPartyUserData.picture}}" width="30" height="30"/><b>{{message.from.displayName}}</b> says:   {{message.content}}
    </p>
    <br/>
    <form ng-submit="addMessage()">
      <div class="form-group">
     <label class="sr-only" for="message">Write your message</label>
       <input ng-model="message" id="message" class="form-control input-block" placeholder="Write your message"/>
      </div>
      <button type="submit" class="btn btn-primary btn-block"><span class="glyphicon glyphicon-send"></span> Send</button>
    </form>
    </div>
  </div>
</div>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular-animate.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/velocity/0.7.0/jquery.velocity.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/velocity/0.7.0/velocity.ui.min.js"></script>
<script src="js/angular-velocity.min.js"></script>

<script src="https://cdn.firebase.com/js/client/1.0.18/firebase.js"></script>
<script src="https://cdn.firebase.com/js/simple-login/1.6.2/firebase-simple-login.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/0.7.1/angularfire.min.js"></script>

<script type="text/javascript">
 var app = angular.module("myChatRoom", ["firebase",'angular-velocity']);
 
 app.factory("ChatService", ["$firebase", function($firebase) {
   var ref = new Firebase("https://welfare.firebaseio.com/chat");
   return $firebase(ref.limit(10));
 }]);
 
 app.controller("ChatCtrl", ["$scope", "ChatService", "$firebaseSimpleLogin",
   function($scope, chatService, $firebaseSimpleLogin) {
    var ref = new Firebase("https://welfare.firebaseio.com/");
     $scope.auth = $firebaseSimpleLogin(ref);
     $scope.messages = chatService;
     $scope.addMessage = function() {
       $scope.messages.$add({from: $scope.auth.user, content: $scope.message});
       $scope.message = "";
     };
   }
 ]);
</script>
</body>
</html>

Wednesday, 8 April 2015

Geb - Very Groovy Browser Automation



Dear Java/Testing friends,

Try to have a look at Geb(pronounced as 'Jeb') http://www.gebish.org/, which is a browser automation library built on WebDriver and leverages power of Groovy language and jQuery like content selection (using CSS selectors).
WebDriver is now there in Selenium 2.0  (Selenium 1.0 + WebDriver = Selenium 2.0).


Please find a sample script below. In this script I have also used a cool feature of Groovy language called Groovy Grapes (@Grab). Grapes are like dependencies of the script. We no need to download dependencies and add them to the class path (Grapes does all the heavy lifting for us).

To run the following script you need groovy in the path.

Then run the following command in command prompt

groovy Geb_Demo.groovy

@Grab("org.gebish:geb-core:0.10.0")
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.43.1")
@Grab("org.seleniumhq.selenium:selenium-support:2.43.1")
import geb.Browser

Browser.drive {
    go "http://google.com"
 
    // make sure we actually got to the page
    assert title == "Google"
 
    // enter wikipedia into the search field
    $("input", name: "q").value("wikipedia")
 
    // wait for the change to results page to happen
    // (google updates the page dynamically without a new request)
    waitFor { title.endsWith("Google Search") }
 
    // is the first link to wikipedia?
    def firstLink = $("li.g", 0).find("a")
    assert firstLink.text().contains("Wikipedia")
 
    // click the link 
    firstLink.click()
 
    // wait for Google's javascript to redirect to Wikipedia
    waitFor { title.contains("Wikipedia") }
    browser.driver.executeScript("alert('Hello Gopal');")
}

Monday, 9 March 2015

CHMOD calculator - built with AngularJS and Material Design

Dear Friends,



Please have a look at my new tool CHMOD Calculator.
It is used to get the Octal value for file permissions in Linux.
It is built with Google's AngularJS and material design (materializecss.com)

http://praveengandhi.github.io/chmod_calc.html


Once the value is decided then that can be used to change the file permissions in linux using the following command
chmod -R 755 .
-R is for recursive
. is current directory



Hope it is useful to you :)

Friday, 27 February 2015

Today I learnt to use Gradle-Plugin called 'Application'

Dear Java Friends,

I started using Maven from 2013 August. After a while I came across Gradle. It is pretty much similar and simpler than Maven. It also has the notion of plugins as Maven. Today I have learnt a new plugin named application and used it like charm.



Demo app code at my Githubhttps://github.com/PraveenGandhi/gradle-application-plugin-demo

Long back I have seen a presentation (http://www.infoq.com/presentations/Improve-Your-Java-with-Groovy) by Ken Kousen called "Improve Your Java with Groovy". There he emphasizes about Gradle and says:

Maven people seeing Gradle for the first time, some times just weep, you know how much simpler life can be.

Usually I used to create some kind of automation utilities at work (inspired by my Senior at Cognizant). Now the time has come to share these tools that make my work easier with other friends (might not be typical java developers) like testers and Business guys.

I cannot give these tools as they are to others, if I give like that I need to help to to use it. Rather it is better to make some executable scripts (.bat files) which makes the usage of the tool much easier. Initially I used to create such by my bear hands. Now it is all there as a simple Gradle plugin (application).

How?


From Gradle docs:

The Gradle application plugin extends the language plugins with common application related tasks. It allows running and bundling applications for the jvm by creating a jvm application Distribution.

It gives us the tasks like run, distZip,distTar and so on.

I have used run to simply run the app using Gradle.
I used distZip to create a distribution which has every thing required to run the app without the Sophisticated build tools and/or IDEs.

The above said distribution (project_name-version_number.zip) has two folders namely bin and lib.

As the name,
bin folder has start-up scripts like batch(for windows) and bash(for UN*X).
lib folder has the output jar (of the current project) and all the libraries mentioned in the dependency list of build.gradle.

Long live Gradle :)



Thursday, 12 February 2015

spring-hibernate-multi-module-maven

Dear Friends,

Please have a look at my first Multi Module Maven project. It is a demo project for Spring MVC in following two flavors
  1. Java Config
  2. XML Config

Code is on my GitHub repository https://github.com/PraveenGandhi/spring-hibernate-maven-multi-module.



Wednesday, 11 February 2015

JBoss Gotchas

Dear Friends,

At times we might have to hit the apps running in Linux machine or another machine connected through the same network.

If you want to hit an application deployed in tomcat which is running in the same network that you are connected in, then you have to use http://IP_or_hostname:port_number/contextRoot
for example http://JaiRam-PC:8080/app that's it, you are good to go.

But if the application is running in JBoss you might see "This webpage is not available" as shown below.


Reason:
By default (due to security reasons) JBoss AS binds only to localhost.

Resolution or work around:

1. While running the JBoss use another param as follows

run.sh -b 0.0.0.0 
(on windows as follows)
run.bat -b 0.0.0.0
2. From JBoss AS 7, we have one more option, 
that is we can edit the JBOSS_HOME/standalone/configuration/standalone.xml to change the "public" and "management" interfaces to point to the hostname of your system or 0.0.0.0

Going one step further:

Form JBoss 7 on wards configuring the server and deployments can be done by admin console app (management). It runs on port number 9990 by default (http://localhost:9990/console/App.html) Which is again by default enabled for localhost, to be enable on network mode we have to run the server as follows

standalone.sh -bmanagement 0.0.0.0
(on windows as follows)
standalone.bat -bmanagement 0.0.0.0

I used to run my server as follows:




Lengthy param names are as below

-Djboss.bind.address=0.0.0.0
-Djboss.bind.address.management=0.0.0.0

Where did I apply this:

  1. At work I have got a Linux box (Performance Testing Environment) and I have to deploy my app in JBoss 7.1.1 in that box from another machine (my Laptop).
  2. One of my friends (middle-ware guy) was asked to start JBoss as said above like both the public (deployed apps) and management console app should be accessed in the same network. I suggested him to add  both parameters when running server as below and that worked like a charm.

standalone.sh -b 0.0.0.0 -bmanagement=0.0.0.0

Hope this post is useful to you, please drop in your comments.



Tuesday, 27 January 2015


Code completion support in eclipse/STS/GGTS

Dear Java Friends,

I recently came across the following from Spring News and it is working well for me. Hope it is useful to you as well. 

Code completion support in Eclipse and the Spring Tool Suite is aware of the camel case shortcuts. You don’t need to write NullPointerException, for example. It is enough to type in NPE and hit code completion to let it propose the right class name. This also works with lower case characters in between, so typing on “NuPoiEx” will also trigger the code completion to propose NullPointerException as class name.


Monday, 12 January 2015

"Run"ning easily 

Friends,

Hope all are doing great, just logging my first "tech it easy" post.

We all are used to shortcuts as it makes our life easier, do try this shortcut for any of your day to day activities, it makes your tech life easier.

Image Courtesy: cdn.marksdailyapple.com/


I have recently started  RUNning (using run in Windows OS for most used tools, IDEs, batch scripts and folders). I learnt this from one of my friends, Thirumal. Special thanks to him and hope this would be useful to you in one way or the other.

Main key/trick is to add a specific folder to your path (Environment variable) where you have all the .lnk (shortcut files), batch scripts etc., so that all of those are available on CMD and on RUN.

Step 1: Create a folder in any drive with any name of your choice (ex: 'E:\shortcuts').
Step 2: Put all your shortcuts and batch files in that folder.
Step 3: Append the location to your PATH variable in system environment variables (type sysdm.cpl in run and hit enter it would take you there).











You are ready to go :)

To open Google Chrome I need to type ch (case insensitive) in RUN and hit enter.


sky - skype, out - outlook, jd - java de-compiler, sts - spring tool suite ....

ev - environment variables ( use control.exe sysdm.cpl,System,3 as target of the shortcut file)
and to go to the shortcuts folder sh (use target as your shortcuts folder ex: 'E:\shortcuts')

To create new shortcut : right click on empty area on the shortcuts folder, go to New and click on shortcut as below.


select your intended exe, batch file or a folder then give the name as follows


My shortcuts list is below...




Cheers  :) and please do share your comments below.. hope to catch you soon on another "tech it easy" post.