Friday, October 3, 2014

JIRA AUTOMATION USING REST API

1.     While working as a manual or automation tester we need to interact with JIRA many time, for bug reporting, for task creation etc, it take much time to do this again and again, to minimize this time, we can automate this process by interacting with JIRA using its REST API



1     1.    Create a java project in eclipse



1.       As a Prerequisite, we need some client libraries to access JIRA Rest API
Javax.ws.rs.jar
Jersey-bundle-1.6.jar

Jason-lib.jar




1.       Create Package & Class, Add following code

package testing;
import javax.naming.AuthenticationException;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.Base64;
import core.ValueSettings;
class Case1 {
   // Create a string for authorization(Passing username and password)
    static String auth = new String(Base64.encode(ValueSettings.userAuthentication()));

    // Url for creating an issue using REST API ----
    static String url = ValueSettings.getIssueURL()+"/TES";     // Project ID
    static String url11 = "http://localhost:8080/rest/api/2/issue";

     //JSON for creating an issue using REST API
        
             static String data = "{\"fields\"" +
                                                 ":{\"project\"" +
                                                                  ":{\"key\":\"TES\"}," +
                                                                 "\"description\": \"description|TESTING|B\"    ,"+   // Description
                                                                 "\"priority\": {\"name\": \"Major\"},"+
                                                                 "\"reporter\": {\"name\": \"testingworldnoida\"},"+
                                                                 "\"assignee\": {\"name\": \"testingworldnoida\"},"+
                                                                 "\"summary\":\"REST Test \",\"issuetype\":{\"name\":\"Task\"}}}";
             static String data2 = "{\"fields\"" +
                                                     ":{\"project\"" + 
                                                            ":{\"key\":\"TES\"}," +
                                         "\"summary\": \"something's wrong\","+
                                         "\"issuetype\": {\"name\": \"Task\"},"+
                                     //    "\"assignee\": {\"name\": \"testingworldnoida\"},"+
                                     //     "\"reporter\": {\"name\": \"testingworldnoida\"},"+
                                     //     "\"priority\": {\"name\": \"Major\"},"+
                                       
                                         "\"description\": \"description\"}" ;
             
             //url for retrieving an issue using REST API ---- R of CRUD
              static String url1 = "http://localhost:8080/rest/api/2/issue/TJ-1";
            //url for updating an issue using REST API ---- U of CRUD
             static String url2 = "http://localhost:8080/rest/api/2/issue/TJ-1";
             
               /*
                * JSON data to be updated for an issue using RESP API               
                *
                * */
       
             static String data1 = "{\"fields\":{\"assignee\":{\"name\":\"vinodh\"}}}";
           
                  //  String data2 = "{fields:{summary:Demo Test}}"
               /*
                * url for deleting an issue using RESP API ---- D of CRUD
                *
                * */
              static String url3 = "http://localhost:8080/rest/api/2/issue/TJ-1";
             /*
                * HTTP POST method is used to create the issue
                *
                * */
                public static String invokePostMethod(String auth, String url, String data) throws AuthenticationException, ClientHandlerException {
                   Client client = Client.create();
                   System.out.println(url);
                   WebResource webResource = client.resource(url);
                 
                   ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").post(ClientResponse.class, data);
                   int statusCode = response.getStatus();
                   System.out.println(statusCode);
                   if (statusCode == 401) {
                       throw new AuthenticationException("Invalid Username or Password");
                   }
                   return "issue successfully created"; 
               }
                         
               /*
                * HTTP GET method is used to get the issue
                *
                * */
               private static String invokeGetMethod(String auth, String url) throws AuthenticationException, ClientHandlerException {
                   Client client = Client.create();
                   WebResource webResource = client.resource(url);
                   ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").get(ClientResponse.class);
                   int statusCode = response.getStatus();
                   System.out.println(statusCode);
                   if (statusCode == 401) {
                       throw new AuthenticationException("Invalid Username or Password");
                   }
                   return response.getEntity(String.class);
               }
           
               /*
                * HTTP PUT method is used to update the issue
                *
                * */
            private static String invokePutMethod(String auth, String url, String data1) throws AuthenticationException, ClientHandlerException {
                                   Client client = Client.create();
                                   WebResource webResource = client.resource(url);
                                   ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").put(ClientResponse.class, data1);
                                   int statusCode = response.getStatus();
                                   if (statusCode == 401) {
                                       throw new AuthenticationException("Invalid Username or Password");
                                   }
                                   return "success";
                               }            
              /*
                * HTTP DELETE method is used to delete the issue
                *
                * */
              private static String invokeDeleteMethod(String auth, String url) throws AuthenticationException, ClientHandlerException {
                   Client client = Client.create();
                   WebResource webResource = client.resource(url);
                   ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").delete(ClientResponse.class);
                   int statusCode = response.getStatus();
                   if (statusCode == 401) {
                       throw new AuthenticationException("Invalid Username or Password");
                   }
                   return "successfully deleted";
               }            
       
              public static void main(String[] args) throws Exception {
                              /*
                                * 1. Creating an JIRA issue in project with key TJ using REST API
                                *
                                */
                            
                              System.out.println(invokePostMethod(auth, url11, data));
                                                  
                                /*
                                * 2. Getting details of an JIRA issue in project with issue no TJ-1 using REST API
                                */
                              
                              String resp=invokeGetMethod(auth, url1);                       
                             
                              JSONObject jo=(JSONObject)JSONSerializer.toJSON(resp);
                            
                               JSONObject sum=jo.getJSONObject("fields");
                            
                               System.out.println(sum.getString("summary"));
                                                          
                               /*
                                * 3. Updating details of an JIRA issue in project with issue no TJ-1 using REST API
                              */
                         
                               System.out.println(invokePutMethod(auth, url2, data1));
                                                         
                               /*
                                * 4. Deleting an JIRA issue in project with issue no TJ-1 using REST API
                                */                          
                              
                               System.out.println(invokeDeleteMethod(auth, url3));
                   }
             
             
            
}

 Run this code, go to  JIRA and Verify



Here we will find Task is created 




















Wednesday, September 17, 2014

Best ever set of "Selenium Interview Questions"

CLICK HERE FOR COMPLETE QUESTION SET      Selenium interview questions



TESTING WORLD
Call or WhatsApp: 8743913121
www.youritmentor.in
www.worldtesting.in
Video Ad : https://www.facebook.com/video.php?v=569070436559995&set=vb.100003711325602&type=2&theater&notif_t=like

Training in Selenium, QTP, LoadRunner, Jmeter, SoapUI, Mobile Automation, Manual Testing

View Courses @ www.youritmentor.in


All Supported Element Locators in Selenium

Element Locator
Supported in RC
Supported in Webdriver
Id
id=
findElementById
Name
name=
findElementByName
Identifier
identifier=
fot Available
Link
link=
findElementByLinkText
findElementByPartialLinkText
CSS
css=
findElementByCssSelector
DOM
dom=
Not Available
XPATH
xpath=//
findElementByXpath
Class Name
class=
findElementByClassName
Tag Name
Not available
findElementByTagName


=================================================================

Annotations in Junit

@Test

@Test(timeout=500)

@Test(expected=IllegalArgumentException.class)

@Before (Will execute before every @Test Annotation)

@After            (Will execute after every @Test Annotation)

@BeforeClass (Will execute before executing any other annotation, execute only once at the start)

@AfterClass (Will execute after executing all other annotation, execute only once at the end)

@Ignore( used with @Test annotation, will skip execution of particular test method)

@Parameterized     (used for running my test case with multiple data)


Sunday, September 14, 2014

Python for Testers : Variables


Variables in Python

Variables are used to hold data, and value of variable can be change
In python we need not to declare variable, variables are declared automatically when we assign value to it

I=10;  #  int type variable is declared

J=100.055;   #  float type variable is declared

K=”Hello World”;  #   String type variable is declared

Program ::: Variable.py



Python for Testers: Python coding guidelines


Python Coding Guidelines/ Standards

Python is a case sensitive language


Identifier: Name of variable, method, module, class, object etc is called identifier.
                Identifier can have letters, number, _, can start with underscore and alphabets
                Identifier cannot have other special characters
                Class name should start with capital letter other identifier start with small letter
                If identifier start with _, means it need to be private
                If identifier start with __, means it need to be strongly private
                If identifier start and end with __ , means identifier has  language defined special name
                Eg:   __init()__


Blocks in python does not use braces, for blocks we use indentation


Statement in python does not end with semicolon, each line shows a separate statement
                    If we want to write statement in multiple line we can use line continuation symbol(\),  
                    statement contains []{}() does not need line continuation symbol


Comments is created by using # symbol


String         can be placed in ‘’ or “” or(triple) ‘’’    ‘’’ or “””      “”” , triple is used when string
                     exists in more than 1 line


raw_input(“enter data”) its is used to take user from input @runtime
print(“HELLO”)  command is used to print something on console
num = raw_input("Enter a number  :")


Multiple statements in single line can be placed by separating through semi colon



Python for Testers: Creating and Running python programs


Interactive Python
We can start writing python code directly using python interactive environment
For working with python in interactive mode, open command prompt, write python, enter
Now we will be in python interactive mode can write and execute command






Executing Python Code
Apart from running python code in interactive environment, we can execute python from

à Command Line “python   myfile.py”
à Python script can be  executed from python IDE



Start of Python Scripting
Way-1 We can write code in interactive mode, for that go to command prompt and write python, it will invoke python interpreter. Now we can write and execute python statements




Way-2  Open a notepad file and write python scripts there, then go to command prompt and invoke python interpreter with filename as argument here it will execute file






Python for Tester: Python Introduction


PYTHON
Python is a interpreted, interactive, object oriented scripting language
Python is an interpreted language: We can execute it directly by interpreter, no need of compiler
Python is interactive as we can directly start its console and write and execute command
Object oriented, it support OOPS concepts




Installation of Python
Download this .msi installer and run, It will install python and will set it to your path variable as well

After installation, go to command prompt and type python, here it will display version

Python version can be seen by python -v


If does not display then set python “C:\Python27” in path variable and check again
Ctrl+Z is to come out from interactive mode



High Level features of Python
Easy to write code(very less keywords), simple syntax, no semicolon
Support both structural as well as OOPS style of programming
Interactive language, we can execute single statements as well
Rich set of existing libraries
Can easily be coupled with other languages like Java, C, C++
Support automatic garbage collection
Support all major databases
Supporting large set of platforms like Windows, MAC, Unix, Linux etc

Monday, September 8, 2014

Working with Selenium IDE (Day-2)


               SELENIUM   IDE      TOOLBAR



                                   We have 2 Tabs here

Table :   Shows Selenium command in table format.

Source : Shows Selenium recrded script in HTML format.

Left side of Windows we have space for TEST  CASE :  All test cases will be displayed here.



                              SELENIUM IDE TOOLBAR




Right Side Red Button : This button is used for Start Recording & Stop Recording.

When we open selenium IDE this button is already open.


Left Side Slider: This is used to controlling the speed when we run recording test case.
                             We can control speed of execution of test case.


Then we have 2 Buttons

1 Play button from Left : It is used for execution of complete test suite.

2 1 Play button from Left : It is used to execute only current selenium test case.




Pause / Resume Button : It is used to pause the execution script while running and Resume execution Script.



Step Button :


This button is mainly available/enable when we PAUSE execution of script, it is mainly used for debugging.

As we click on Step Button, Script will move 1 step forward.

Roll UP : Repeated sequence of commands are grouped together.



                                Bottom Panel on Selenium IDE

LOG :   Shows log while execution of script.

Reference :  Gives detail of command that we want to use 

UI Element : Mainly for mapping complex name of application to simple name.

RollUP  :  Repeated sequence of commands are grouped together.


EDIT MENU
à INSERT NEW COMMAND : To enter a new command
à INSERT NEW COMMENT : IT WILL ENTER A COMMENT IN TABLE VIEW






                                                 FILE MENU





ADD Test Case : To add other test cases in this test suite.

Properties : Select test case and click on properties to view properties.




                                      ACTION MENU BAR



Toggle Break Point :  Set Breakpoint, so application will pause at this line, similar to use Pause toolbar button.


Set / Clear Startpoint : Making Start point, so that application will run from particular line it will not start from 1st line.

Execute This Command : Execute only selected command.
 


                                                     Option Menu Bar




Reset IDE Window : Bring IDE window to its original settings.

Format : We can select any format, now In Source tab we will find coding in that format rather than HTML.

ClipBoard Format : We can set clipboard format, now if we select any of the command from Table of Selenium id and paste it anywhere else, it will paste in format which is selected in Clipboard format.




Selenium IDE installation (Day-1)

Install Selenium IDE

Any browser other than Firefox

Step1: Open IE



Step 3: Click on Download

Step 4: Click on Save



Here we will find that “selenium-ide-x.x.x.xpi” file will save in your system.


Step 5: Go to Location, where Downloaded file is saved.

Step 6: Right Click on that saved file, Select Open With à Select Firefox

Step 7: You will get following screen now



Step 8 : Click on Install Now



Step 9: Selenium IDE is installed, click on “Restart Firefox”

Step 10: Go to Tools

Here we will find that selenium IDE is installed .