Friday, February 13, 2015

Automation of naukri profile update - Selenium

This script uploads ur profile at naukri.com with out using AutoIt

package Selenium_script;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Upload {

public static String naukari = "https://login.naukri.com/nLogin/Login.php";
public static String nauk = "http://www.naukri.com/";
public static String upload = ".//*[@id='colL']/div[2]/div[1]/a[2]";
public static String view = ".//*[@id='colL']/div[2]/div[1]/span";
public static String view1 = ".//*[@id='colL']/div[2]/div[1]/a[1]";
public static String up_prof = ".//*[@id='uploadLink']";
public static String save = ".//*[@id='editForm']/div[8]/button";
public static String mynauk = ".//*[@id='mainHeader']/div/div/ul[2]/li[2]/a/div[2]";

public static void setClipboardData(String st) {

  StringSelection stringSelection = new StringSelection(st);
  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
}

public static void main(String[] args) throws AWTException {




WebDriver dri = new FirefoxDriver();
dri.get(nauk);


dri.findElement(By.xpath(".//*[@id='login_Layer']/div")).click();
WebElement fra = dri.findElement(By.xpath(".//*[@id='loginLB']/div[2]"));

fra.click();

dri.findElement(By.id("eLogin")).sendKeys("yourusername"); //Enter your username
dri.findElement(By.id("pLogin")).sendKeys("yourpassword"); // Enter your password
dri.findElement(By.xpath(".//*[@id='lgnFrm']/div[7]/button")).click();
dri.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);


dri.manage().window().maximize();

//Logged in
//Clicking on view profile
WebElement view_prof = dri.findElement(By.xpath(view1));
Actions builder = new Actions(dri);
builder.click(view_prof).build().perform();



//Clicking on upload link
WebElement prof_upload = dri.findElement(By.xpath(up_prof));
prof_upload.click();

WebElement attachcv = dri.findElement(By.xpath(".//*[@id='attachCV']"));
Actions builder1 = new Actions(dri);
builder1.click(attachcv).build().perform();



//upload the file
//The below method calls the setclipboard method and put the file path in clipboard

setClipboardData("Path to your resume file");

//The below lines of code will paste the clipboard content and click open button in the modal window

Robot robot = new Robot();
robot.delay(500);

robot.keyPress(KeyEvent.VK_CONTROL); //Press control key
robot.keyPress(KeyEvent.VK_V); //Press key v
robot.keyRelease(KeyEvent.VK_V); // Release "v"
robot.keyRelease(KeyEvent.VK_CONTROL); //Release ctrl key
robot.keyPress(KeyEvent.VK_ENTER); //Press enter key that clicks the open button in the modal
robot.keyRelease(KeyEvent.VK_ENTER); //Release the enter key
robot.delay(1000); //Delay in milli seconds

//Closing the modal window of upload file
WebElement sav_btn = dri.findElement(By.xpath(save));
sav_btn.click();

//Log out button



WebElement my_naukri = dri.findElement(By.xpath(mynauk));
WebElement log_out = dri.findElement(By.xpath(".//*[@id='mainHeader']/div/div/ul[2]/li[2]/div/ul/li[5]/a"));
Actions builder3 = new Actions(dri);
builder3.moveToElement(my_naukri).click(log_out).build().perform();







}

}

Wednesday, January 14, 2015

Selenium script to get table values

package Ecomm_selenium;

import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Tablevalues {

       /**
       * @param args
       */
       public static void main(String[] args) {
              // TODO Auto-generated method stub
           //String paths = ".//*[@id='fk-mainbody-id']/div/div[2]";       
           //String
             
              WebDriver d = new FirefoxDriver();
              d.get(site);
              //WebElement webtable = d.findElement(By.xpath(".//*[@id='grey-box']/div"));
              int RowIndex = 3;
              List<WebElement> Rowcount = d.findElements(By.xpath(".//*[@id='grey-box']/div/div["+RowIndex+"]"));
             
              System.out.println("No: of Rows in table:" + Rowcount.size());
                    
              //for(WebElement rowelem : Rowcount)
              for(int i=0; i <= RowIndex; i++)
              {
                     int ColIndex = 3;
                     for(int j = 0; j <= ColIndex; j++){
                           WebElement value = d.findElement(By.xpath(".//*[@id='grey-box']/div/div["+i+"]/div["+j+"]/p"));
                           System.out.println("Row" + i + "Column" + j + "Data" + value.getText());
                     }
                    
                     
              }
              d.quit();
       }
      
}

Selenium script to get list of values

//code to get list of values

package Ecomm_selenium;
import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

//Getting list of webElements
public class Login {

                /**
                * @param args
                */
                public static void main(String[] args) {
                                // TODO Auto-generated method stub
                               
                                String site = "http://www.flipkart.com/";
                    String paths = ".//*[@id='fk-mainbody-id']/div/div[2]";                            
                    //String
                               
                                WebDriver d = new FirefoxDriver();
                                d.get(site);
                                List<WebElement> colu_vals = d.findElements(By.className("goquickly-list"));
                                java.util.Iterator<WebElement> i = colu_vals.iterator();
                                while(i.hasNext())
                                {
                                                WebElement value = i.next();
                                                System.out.println(value.getText());
                                               
                                }
                               
                               
                }

}

Tuesday, October 14, 2014

Gamification in Banking


Gamification is a business strategy which applies game design techniques to non-game contexts to drive user behavior.


what is non-game context mean here is some objective other than success in the game like business impact, Social impact, personal improvement etc.

Why Gamification:


Let us look at different areas of it:
It's broadly divided into three areas:
1.External  -  Marketing, Sales, Customer Engagement
2.Internal - HR, Productivity enhancement, Crowdsourcing
3.Behaviour Change - Health and wellness,Sustanibility, Personal finance.

Market segmentation of gamification:



Before moving on applying gamification to banking as a domian our inspiration comes from the positive results it got when applied by many companies with increase of  sales, productivity improvement and health and wellness improvement.



Keeping in mind the positive impact of applying game design techniques in non -game contexts we can apply the same to banking. we are here exploring applying gamification to a bank website where some thousands of customers uses internet banking everyday.  

While considering gamification techniques banking has it's own regulations:

Record Keeping
Reserve Requirements
Currency manipulation
Anti –fraud
Money laundering
Consumer Protection
Taxation and accounting

We here describe few areas where gamification can be applied in an internet banking website.
Although every bank offers its users some pricing plans that increases the chance of banking with their bank, our gamification techniques  will have a bigger impact.
User login to their internet banking website and how does it will be if user experience of the 
site having points he gained for his accounts maintenance, considering record of paying debts 
within timeline, his awareness on security initiatives by their bank to protect their customers 
information that is part of anti -fraud and money laundering which are serious problems in today's 
world. 










Tuesday, October 7, 2014

Regular expressions with Python

This is post on getting and writing programs with regular expressions using python as programming language.

There would be many theoretical intro of why do we use regualar expressions. In simple, regex are used for parsing data either in search engine or web scraping.

Regular expressions: The following line of code is the syntax of regex in python.
Regexp<name> = regexp.search()

Before getting into the lines of code let's have a glance at the patterns.

Quick patterns:
[abc]
A single character of: a, b, or c
[^abc]
Any single character except: a, b, or c
[a-z]
Any single character in the range a-z
[a-zA-Z]
Any single character in the range a-z or A-Z
^
Start of line
$
End of line
\A
Start of string
\z
End of string
.
Any single character
\s
Any whitespace character
\S
Any non-whitespace character
\d
Any digit
\D
Any non-digit
\w
Any word character (letter, number, underscore)
\W
Any non-word character
\b
Any word boundary


(…)
Capture everything enclosed
(a|b)
a or b
a?
Zero or one of a
a*
Zero or more of a
a+
One or more of a
a{3}
Exactly 3 of a
a{3,}
3 or more of a
a{3,6}
Between 3 and 6 of a
a{ ,6}
Not more than 6 of a







For any pattern  :

? – A regex followed by ? implies zero or one of the occurrence
*-   A regex followed by *implies Zero or more of the occurrence (Used for optional )
+ - A regex followed by + implies one or more occurrence
{x, y} – A regex with boundaries repeat itself in between x and y
{x, }  - A regex with lower bound is >/ x
{, y} – A regex wit upper bound  is  </ y
{x} – A regex with exact x times

Using # is a comment
Using \# in a regexp matches for the character #.

. : Matches any character except \n
\. : Matches only dot

Special case in escape character:
For the regexp [-a-zA-Z]: It considers hypen(–) as a character and looks for it.


With Python:

R with regular expressions in python:

Using r ‘regexp’ turns off backslash impact of python in the expression

Re library:

To work with regular expressions in python we need to import ‘re’ library into our code and is as below:
import re

If a regular expression looks like this:

Pattern = r’^[A-Z][a-z]{2}\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$’

It might be difficult to revisit the code and to debug this. Python avoids this with multiline expression using VERBOSE mode.

Pattern = r’’’
               ^
                [A-Z][a-z]{2}
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
$
               ‘’’


Exp = re.compile(pattern, re.VERBOSE) or
Exp = re.compile(pattern, re.X)

Simple example code for Regular expression


import sys
import re

address_pattern = r'''
^
(?P<Address1>P\.*O\.*\s*(BOX|Box|box)\s\d{1,5}) # address1 field

(?P<City>\s*\w*\W*\s*\w*\W*\s*\w*\W*\s*) # text between address and zip code

$
'''

address_reg_exp = re.compile(address_pattern, re.VERBOSE)

text = "PO Box 1055 Jefferson City, MO 65102"


match = address_reg_exp.search(text)

g = match.groups()
if match:
print match.group('Address1')
print match.group('City')