Jira Integration with Selenium || Raise a bug for failure test cases || No Manual Bug in JIRA


Filing issues in JIRA is boring, wanna do with Simply Cool Automation on Selenium... 


I have tried by importing in Product and ran automation from the script, issues are getting filed in JIRA for the failed test cases.

Here we go with Selenium script to raise a bug for Failure Test Cases to direct punch on JIRA.


Step 1 : 

Maven Dependencies to add in our POM.xml

<!-- https://mvnrepository.com/artifact/net.rcarz/jira-client -->
<dependency>
<groupId>net.rcarz</groupId>
<artifactId>jira-client</artifactId>
<version>0.5</version>
</dependency>

Step 2 :

Add two packages in your project, say... com.listeners and com.jira

*Under package com.listeners
     =TestJiraListener.java
*Under package com.jira
     =JiraPolicy.java
     =JiraServiceProvider.java

Add these two files in the respective Packages, refer attachment.

Step 3 : 

Under listener package in TestJiraListener.java file, we need to provide JIRA Authentication API token with our Email ID.

Here is the piece of code change in the TestJiraListner.java file

     JiraServiceProvider jiraSp = new JiraServiceProvider("https://apptha.atlassian.net/","youremail@domain", "XXXXXXXXXXXX", "VOD");

In the place of "XXXXXX" we need to generate JIRA Authentication API Token and replace it.

How to generate JIRA Authentication API Token

Log in to https://id.atlassian.com/manage/api-tokens

  • Click Create API token.
  • From the dialog that appears, enter a memorable and concise Label for your token and click Create.
  • Click Copy to clipboard, then paste the token to your script, or elsewhere to save:


To generate JIRA API Token

Once you created the token, replace it in the place of "XXXXXX".

Now your project might look like this

Selenium Script to file failed automation test to JIRA

Step 4: 

Now we have to add JIRA annotation in our Main Class file, as follow

@JiraPolicy(logTicketReady=true)
@Test(priority = 0, enabled = true)
public void login() throws Exception
{
      //your codes
}

@JiraPolicy(logTicketReady=true)
@Test(priority = 1, enabled = true)
public void signup() throws Exception
{
      //your codes
}

Step 5 :

Now we will run our automation via testng.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="1" name="Suite" parallel="none" verbose="1">

<listeners>
<listener class-name="com.listeners.TestJiraListener" />
</listeners>

<!-- Start First Test -->
<test name="Test chrome" parallel="none" thread-count="1">
<parameter name="browser" value="chrome" />
<classes>
<class name="yourpackagename.yourmainclassfile" />
</classes>
</test> <!-- End First Test -->

That's it....! You are done....! All failure automate test cases are automatically filed in JIRA. 😎


****Sample Test Case Filed in JIRA****




Advantages
==========
- No need to raise a bug manually.
- Auto logging of issues/bugs/defects in JIRA
- Easy to configure and setup
- It can be used for web, mobile and API Automation also.

Referral Sources From

~~~GIT Repo path~~~
https://github.com/naveenanimation20/JiraIntegrationWithSelenium

~~~YouTube Link~~~
https://www.youtube.com/watch?v=c8lULfmhxzw


!!!!Codes are available.!!!!!


JiraServiceProvider.java
=================

//code
package com.jira;

import net.rcarz.jiraclient.BasicCredentials;
import net.rcarz.jiraclient.Field;
import net.rcarz.jiraclient.Issue;
import net.rcarz.jiraclient.Issue.FluentCreate;
import net.rcarz.jiraclient.JiraClient;
import net.rcarz.jiraclient.JiraException;

public class JiraServiceProvider {

 public JiraClient jira;
 public String project;

 public JiraServiceProvider(String jiraUrl, String username, String password, String project) {
  BasicCredentials creds = new BasicCredentials(username, password);
  jira = new JiraClient(jiraUrl, creds);
  this.project = project;
 }

 public void createJiraTicket(String issueType, String summary, String description, String reporterName) {

  try {
   FluentCreate fleuntCreate = jira.createIssue(project, issueType);
   fleuntCreate.field(Field.SUMMARY, summary);
   fleuntCreate.field(Field.DESCRIPTION, description);
   Issue newIssue = fleuntCreate.execute();
   System.out.println("new issue created in jira with ID: " + newIssue);

  } catch (JiraException e) {
   e.printStackTrace();
  }

 }

}


JiraPolicy.java
===========

package com.jira;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface JiraPolicy {
 boolean logTicketReady();
}


TestJiraListener.java
=====================

package com.listeners;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import com.jira.JiraPolicy;
import com.jira.JiraServiceProvider;

public class TestJiraListener implements ITestListener {

 @Override
 public void onTestStart(ITestResult result) {
  // TODO Auto-generated method stub

 }

 @Override
 public void onTestSuccess(ITestResult result) {
  // TODO Auto-generated method stub

 }

 @Override
 public void onTestFailure(ITestResult result) {

  JiraPolicy jiraPolicy = result.getMethod().getConstructorOrMethod().getMethod().getAnnotation(JiraPolicy.class);
  boolean isTicketReady = jiraPolicy.logTicketReady();
  if (isTicketReady) {
   // raise jira ticket:
   System.out.println("is ticket ready for JIRA: " + isTicketReady);
   JiraServiceProvider jiraSp = new JiraServiceProvider("https://apptha.atlassian.net/",
     "yourJiraemailaddress@com", "XXXXXXXXXXXXXXXXXXX", "VOD");
   String issueSummary = result.getMethod().getConstructorOrMethod().getMethod().getName()
     + "got failed due to some assertion or exception";
   String issueDescription = result.getThrowable().getMessage() + "\n";
   issueDescription.concat(ExceptionUtils.getFullStackTrace(result.getThrowable()));

   jiraSp.createJiraTicket("Bug", issueSummary, issueDescription, "BShiv");
  }

 }

 @Override
 public void onTestSkipped(ITestResult result) {
  // TODO Auto-generated method stub

 }

 @Override
 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
  // TODO Auto-generated method stub

 }

 @Override
 public void onStart(ITestContext context) {
  // TODO Auto-generated method stub

 }

 @Override
 public void onFinish(ITestContext context) {
  // TODO Auto-generated method stub

 }

}

testng.xml
========

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="1" name="Suite" parallel="none" verbose="1">

 <listeners>
  <listener class-name="com.listeners.TestJiraListener" />
 </listeners>

 <!-- Start First Test -->
 <test name="Test chrome" parallel="none" thread-count="1">
  <parameter name="browser" value="chrome" />
  <classes>
   <class name="Major_Flow.Vplayed" />
  </classes>
 </test> <!-- End First Test -->


 <!-- <test name="my hub spot test firefox" parallel="methods" thread-count="5"> 
  <parameter name="browser" value="ff" /> <classes> <class name="com.MyTests.LoginTest" 
  /> </classes> </test> -->

</suite> <!-- Suite -->


Post Author and Executed By B.Siddarth(Admin)

Automation: Selenium Script to record Automation Test and Execution Video


Here we go, Selenium Screen Recorder: How To Record Selenium Test Execution Video

Techsouljours.blogspot.com - a blog for QA
Video Recording using selenium script


By using  Monte Screen Recorder API we record of our test cases as video format.

Monte Screen Recorder API available as Maven Dependencies where we can add in our POM.xml file as dependency tag.

How to Implement in our project :

We have one Java File of Recording screen functionality written and have attached as java file name as 'MyScreenRecorder.java' file

This 'MyScreenRecorder.java' file is the base function and we can use the method as 'MyScreenRecorder.startRecording("yourtestcase_recording")' in our own test case file.

For Example : Your Java file has the navigation function and if you want to record some scenarios, then we can use the method as 'MyscreenRecorder.startRecording' to start record and 'MyScreenRecorder.stopRecording' to stop the record.

@Test
public void navigation() throws Exception{

MyScreenRecorder.startRecording("Navigation_recording");

/*
                       your code goes here
                */
               MyScreenRecorder.stopRecording();

}

That's simple, your test case got recorded and saved in separate folder.

Results:

Here I have attached the screen recorder java file and ran for navigation from google to contus and from amazon to flipkart.


MyScreenRecorder.java

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.monte.media.Format;
import org.monte.media.FormatKeys.MediaType;
import org.monte.media.Registry;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;

import static org.monte.media.AudioFormatKeys.*;
import static org.monte.media.VideoFormatKeys.*;

public class MyScreenRecorder extends ScreenRecorder {
public static ScreenRecorder screenRecorder;
public String name;

public MyScreenRecorder(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat,Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder, String name) throws IOException, AWTException
{
super(cfg, captureArea, fileFormat, screenFormat, mouseFormat, audioFormat,movieFolder);
this.name = name;

}

@Override
protected File createMovieFile(Format fileFormat) throws IOException {

if (!movieFolder.exists()) {
movieFolder.mkdirs();
} else if (!movieFolder.isDirectory()) {
throw new IOException("\"" + movieFolder + "\" is not a directory.");
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
return new File(movieFolder,
name + "-" + dateFormat.format(new Date()) + "." + Registry.getInstance().getExtension(fileFormat));

}

public static void startRecording(String methodName) throws Exception {
File file = new File("./recordings/");

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = screenSize.width;
int height = screenSize.height;

Rectangle captureSize = new Rectangle(0, 0, width, height);

GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice()
.getDefaultConfiguration();

screenRecorder = new MyScreenRecorder(gc, captureSize,

new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,CompressorNameKey,ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, 24,FrameRateKey,Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)),null, file, methodName);

screenRecorder.start();

}

public static void stopRecording() throws Exception {
screenRecorder.stop();
}

}


MyTestDemo

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class MyTestDemo {

WebDriver driver;

@BeforeMethod
public void setup(){
System.setProperty("webdriver.chrome.driver", "E:\\Automation- setup files\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
}

@Test
public void navigationTest() throws Exception{
MyScreenRecorder.startRecording("NavigationTest_from_google_to_contus_viceversa");

driver.get("http://www.google.com");
driver.navigate().to("http://www.contus.com");
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();

MyScreenRecorder.stopRecording();
}

@Test
public void navigation_FeatureTest() throws Exception{
MyScreenRecorder.startRecording("NavigationTest_From_amazon_to_flipkart_viceversa");

driver.get("http://www.amazon.com");
driver.navigate().to("http://www.flipkart.com");
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();

MyScreenRecorder.stopRecording();
}


@AfterMethod
public void tearDown(){
driver.quit();
}

Test Execution got recorded and video got saved. 


Video Recording in selenium script1


                                         
Video Recording in selenium script2

Full Script from the scrap and want to import in your project. 

Here is the Github URL 

By using this feature we can create AVI/Mp4 recording video files for your test case execution, which can be shared to developers while logging the bugs.

Post author by Siddarth

How to get started Devops learning and approaches


For Devops Engineer in initial level here are the things in order for you (priority high to low), open source tools awareness and QA roles in devops process.

techsouljours.blogspot.com-Devops-qa-roles and tools


  • Be Ready with Centos/Ubuntu commonly used commands set. You never know when you need what with these commands.
  • Learn What is CI/CD and What tools are used in CI and tools used in CD (just tool names).
  • Learn what is Git and Basic commands. (Because Git is most commonly used version control tool for your application source code management ). Sign up in github.com Build software better, together and learn how to push your code into it.
  • Coming to most common CI tools : Jenkins is most preferred and open-source. Try to install it on your own. (YouTube is your best friend here).
  • Once you are ready with github and jenkins. Create a simple jenkins build by Integrating jenkins with github.
  • Docker is another high on demand Devops tool. It's container based technology. Understand this as deep as possible.
  • Learn Kubernetes.
  • Learn Ansible/Chef (configuration management tools). Try to learn these 2 tools. (atleast 1 is preferred)
  • Jfrog artifactory. (artifacts/binaries management tools)
  • At last Learn any one of cloud technologies like AWS or Azure (what are they and how they works - learning at least 1 technology is preferred with certification at the end).
AWS provides infrastructure as a service, where you can learn installing all the above tools installation using various AWS services.

Popular Devops tools

There are many tools in Devops. Depending on the projects requirement and standardization we have to pick the right tool.

  • Most commonly used tools for source code management (as a version control system). Github, Gitstash, bitbucket, AWS code commit. Among above all GitHub is popular. You need to have git knowledge to use any of above tools.
  • For Continuous Integration there are many tools in the market. Some of commonly used tools are Jenkins, Bamboo, Teamcity, Concourse, CodeBuild etc. Among all above tools Jenkins is popular and easy to learn CI tool.
  • Configuration management tools like Ansible, Chef, Puppet, Salt.

API Security Testing - How to prevent from Hacking and vulnerabilities


Web API Security testing with it's API Fuzzer that can do Information Gathering, analyze Security Headers, identify API specific vulnerabilities which ensures, that system and applications in an organization, are free from any loopholes that may cause a big loss


techsouljours.blogspot.com-an-qa-blog

Types of API and their Uses

  • REST and SOAP API use predominantly use HTTP as their protocol
  • Arguments are sent as part of the URL, as HTTP Header or in the request body
  • Message payload is predominantly JSON for REST and XML for SOAP

Why Hack an API ?
  • Provoke error messages or response that give us system details
                      - Database names
                      - File Paths
                      - Component versions
  • Find Security holes that give us access to system resources
  • Put the API in an unavailable or unstable state (DOS) 
Security Standards for Web API
  • SSL commonly used for transport-level encryption
  • Message level encryption and signatures :
    • SOAP/XML: WS-Security and related standards
    • REST:JSON Web Algorithms
  • Authentication
    • SOAP: WS-Security/SAML
    • REST: Oauth 1 + 2, OpenID Connect, SAML, custom
API Attack Surface Detection
  • We want to know as much as possible about an APIs endpoints, messages, parameters behaviour
  • The more we know - the better we can target our attack
  • Unfortunately though - an API has no ‘UI’ that can show is the attack surface

techsouljours.blogspot.com - a blog for QA article about api secuirty testing
-apis: {

    -{            

       path:”/pet/{petID}”,



-operations: [
                                         techsouljours.blogspot.com - a blog for QA article about api secuirty testing
-{
   method: “DELETE”,u
   summary: “Delete a pet”,
   notes: “ ”                   
   type: “void”,
   nickname: “deletepet”,

- authorizations: {

                               techsouljours.blogspot.com - a blog for QA article about api secuirty testing
- Oauth2: {
                -{
                    scope: “write:pets”,
                    description: “modify pets in your account”
                  }
          ]
},
techsouljours.blogspot.com - a blog for QA article about api secuirty testing
- Parameters: [
     - {
           name: “petID”,
           description: “Pet id to delete”,
           required: true,
           type:”string”,
           paranType: “path”,


techsouljours.blogspot.com - a blog for QA article about api secuirty testing

           allowMultiple:false
        }
},


Attack Surface Detection : API Metadata

  • api-docs.json
  • WSDL/XML Schema
  • Swagger, RAML, API-Blueprint, ioDocs, etc
  • Hypermedia (JSON-LD, Siren, etc)
  • Documentation / Developer Portals

What are some whatspp hacks?

We would not call it a hack but yeah there are some tricks and tips which i know, gonna share with all of you !!
## If needed you can use WhatsApp as a best image cropper tool ( as we all know WhatsApp use some compression to make large size image into smaller one, so you can do that).
## Self Note / offline diary : you can also use WhatsApp as offline dairy , simply make grouo of some friend's, remove all of them and it's Done ! Now you can save all your useful stuff , data in that group and read offline too everywhere when needed.
Useful information from whatsapp
Whatsapp Tricks



INSTEAD OF CREATING GROUP…
SIMPLY ADD YOUR NUMBER AS CONTACT AND “Whatsapp” YOUR USEFUL STUFF TO IT…
## Now you can Tag someone in group chat just use ‘@’ tag in start of his/her name and WhatsApp will show list of names
## Send anything over WhatsApp: let assume you have to send Quora.apk file , simply Rename it as Quora.apk.mp4 and send it to your friend ! Done !
## UNBLOCK YOURSELF WITHIN 5 minutes
If someone blocked you on Whatsapp and you want to unblock yourself


How do I prepare for Selenium automation testing interviews?

Important topics and interview preparation for automation test engineer. Here are the list of contents explained with all useful links and updates. 
Now if we assume you are ready to go and get with this career move.
Time is not a constraint, it purely depends on person’s ability to grasp

software automation engineer interview preparation
Selenium-automation-interview-preparation

  1. Firstly, you need to learn any programming and scripting language like JAVA, Python, Ruby,etc.
  2. Get familiar with basic concepts like OOPS concepts, various Data Types and Variables, Operators, Decision Making, Arrays, Loops, Classes and Objects, Class Constructors, String Classes, etc.
  3. Now coming to selenium webdriver part start with Set Up/Configure Selenium WebDriver
  4. Get acquainted with various WebDriver Commands

    Below are the topics which you need to be clear to be a Professional Selenium Tester;
  1. Core Java
  2. Selenium WebDriver
  3. HTML traversal & DOM concepts
  4. CSS Selectors & XPATH
  5. JavaScript for Selenium Webdriver
  6. TestNG concepts for test organization, prioritization & batch execution
  7. Github concepts for source code management
  8. Jenkins for CD/CI
  9. Basic understanding of different frameworks - keyword driven, data driven, hybrid, POM
  10. Basic understanding of the workings of their current framework - folder structure, object repositories, reusable functions, test data flow, reporting libraries etc.

Appium Installation full setup on Mac for real device iOS automation (GUI & Command line tools)

Here I have displayed the procedure for the complete installation of Appium in mac for real device iOS automation. I have given the steps for Command line tool installation and GUI installation of appium in mac.

Command Line Tool Installation of Appium in MAC

Step 1 : Install java JDK:


Step 2 : Install Android Studio:


Scroll till last and find the software as below: 

android-studio-ide-173.4819257-mac.dmg

Step 3 : Install Home brew

--> In Terminal install brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 4 : Install Node.js

--> install node.js:

download installer: https://nodejs.org/en/download/ and run

Step 5 : Install npm

--> In Terminal install npm:
brew update
brew install node
npm install -g npm

Step 6 : To setup Environment 

To open bash_profile in terminal, type the following command:
nano ~/.bash_profile

or

open -e .bash_profile
If bash profile not available, create a bash_profile by following command

  1. Start up Terminal
  2. Type "cd ~/" to go to your home folder
  3. Type "touch .bash_profile" to create your new file.
  4. Edit .bash_profile with your favorite editor (or you can just type "open -e .bash_profile" to open it in TextEdit.
paste following:

export ANDROID_HOME=/Users/user/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH

export JAVA_HOME=$(/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk)
export PATH=${JAVA_HOME}/Contents/Home/bin:$PATH
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH

export PATH=$PATH:/opt/bin:$PATH
save (Ctrl+S) and exit

NOTE : As default Android studio and Java takes the above path, if you have changed the path then do change it here with correct version

Step 7. Install Appium

In Terminal install Appium command line:
npm install -g appium@1.6.0-beta1
npm install wd
Step 8. Install Carthage 

Now type the following command to get into WebDriverAgent and Install carthage:
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

brew install carthage

npm i -g webpack
Step 9. Run Appium in command line

From above steps do 'cd' to get out of all subfolders and then type 'appium'

- cd
- appium

If everything works correct you should get the following line 

[Appium] Welcome to Appium v1.6.0-beta1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

GUI Installation of Appium in MAC


Follow the Same steps from command line tools from Step 1 to Step 6