Tuesday 15 December 2020

JMeter Performance Test of Application

 Case Study - 01

------------------

Performance Testing of application 

Case 1

      1-> With 5 users, all users are hitting server at same time.

      2-> User are visiting 3 pages

      3-> Before going to each of the page, we need to have some waiting time.

      4-> My URL could be change in future(Keep in mind)

      5-> Generated tabular and graph as well


---------------------------

solution using jmeter -

<?xml version="1.0" encoding="UTF-8"?>

<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.3">

  <hashTree>

    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">

      <stringProp name="TestPlan.comments"></stringProp>

      <boolProp name="TestPlan.functional_mode">false</boolProp>

      <boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>

      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>

      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">

        <collectionProp name="Arguments.arguments"/>

      </elementProp>

      <stringProp name="TestPlan.user_define_classpath"></stringProp>

    </TestPlan>

    <hashTree>

      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="TestCase1" enabled="true">

        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>

        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">

          <boolProp name="LoopController.continue_forever">false</boolProp>

          <stringProp name="LoopController.loops">1</stringProp>

        </elementProp>

        <stringProp name="ThreadGroup.num_threads">5</stringProp>

        <stringProp name="ThreadGroup.ramp_time">1</stringProp>

        <boolProp name="ThreadGroup.scheduler">false</boolProp>

        <stringProp name="ThreadGroup.duration"></stringProp>

        <stringProp name="ThreadGroup.delay"></stringProp>

        <boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>

      </ThreadGroup>

      <hashTree>

        <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Req1" enabled="true">

          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">

            <collectionProp name="Arguments.arguments"/>

          </elementProp>

          <stringProp name="HTTPSampler.domain"></stringProp>

          <stringProp name="HTTPSampler.port"></stringProp>

          <stringProp name="HTTPSampler.protocol">https</stringProp>

          <stringProp name="HTTPSampler.contentEncoding"></stringProp>

          <stringProp name="HTTPSampler.path">/</stringProp>

          <stringProp name="HTTPSampler.method">GET</stringProp>

          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>

          <boolProp name="HTTPSampler.auto_redirects">false</boolProp>

          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>

          <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>

          <stringProp name="HTTPSampler.embedded_url_re"></stringProp>

          <stringProp name="HTTPSampler.connect_timeout"></stringProp>

          <stringProp name="HTTPSampler.response_timeout"></stringProp>

        </HTTPSamplerProxy>

        <hashTree/>

        <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Req2" enabled="true">

          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">

            <collectionProp name="Arguments.arguments"/>

          </elementProp>

          <stringProp name="HTTPSampler.domain"></stringProp>

          <stringProp name="HTTPSampler.port"></stringProp>

          <stringProp name="HTTPSampler.protocol">https</stringProp>

          <stringProp name="HTTPSampler.contentEncoding"></stringProp>

          <stringProp name="HTTPSampler.path">/soap-web-services-api/</stringProp>

          <stringProp name="HTTPSampler.method">GET</stringProp>

          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>

          <boolProp name="HTTPSampler.auto_redirects">false</boolProp>

          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>

          <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>

          <stringProp name="HTTPSampler.embedded_url_re"></stringProp>

          <stringProp name="HTTPSampler.connect_timeout"></stringProp>

          <stringProp name="HTTPSampler.response_timeout"></stringProp>

        </HTTPSamplerProxy>

        <hashTree>

          <ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Constant Timer" enabled="true">

            <stringProp name="ConstantTimer.delay">3000</stringProp>

          </ConstantTimer>

          <hashTree/>

        </hashTree>

        <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="Req3" enabled="true">

          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">

            <collectionProp name="Arguments.arguments"/>

          </elementProp>

          <stringProp name="HTTPSampler.domain"></stringProp>

          <stringProp name="HTTPSampler.port"></stringProp>

          <stringProp name="HTTPSampler.protocol">https</stringProp>

          <stringProp name="HTTPSampler.contentEncoding"></stringProp>

          <stringProp name="HTTPSampler.path">/docker/</stringProp>

          <stringProp name="HTTPSampler.method">GET</stringProp>

          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>

          <boolProp name="HTTPSampler.auto_redirects">false</boolProp>

          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>

          <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>

          <stringProp name="HTTPSampler.embedded_url_re"></stringProp>

          <stringProp name="HTTPSampler.connect_timeout"></stringProp>

          <stringProp name="HTTPSampler.response_timeout"></stringProp>

        </HTTPSamplerProxy>

        <hashTree>

          <ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Constant Timer" enabled="true">

            <stringProp name="ConstantTimer.delay">3000</stringProp>

          </ConstantTimer>

          <hashTree/>

        </hashTree>

        <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP Request Defaults" enabled="true">

          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">

            <collectionProp name="Arguments.arguments"/>

          </elementProp>

          <stringProp name="HTTPSampler.domain">automationstepbystep.com</stringProp>

          <stringProp name="HTTPSampler.port"></stringProp>

          <stringProp name="HTTPSampler.protocol">https</stringProp>

          <stringProp name="HTTPSampler.contentEncoding"></stringProp>

          <stringProp name="HTTPSampler.path"></stringProp>

          <stringProp name="HTTPSampler.concurrentPool">6</stringProp>

          <stringProp name="HTTPSampler.connect_timeout"></stringProp>

          <stringProp name="HTTPSampler.response_timeout"></stringProp>

        </ConfigTestElement>

        <hashTree/>

        <ResultCollector guiclass="StatGraphVisualizer" testclass="ResultCollector" testname="Aggregate Graph" enabled="true">

          <boolProp name="ResultCollector.error_logging">false</boolProp>

          <objProp>

            <name>saveConfig</name>

            <value class="SampleSaveConfiguration">

              <time>true</time>

              <latency>true</latency>

              <timestamp>true</timestamp>

              <success>true</success>

              <label>true</label>

              <code>true</code>

              <message>true</message>

              <threadName>true</threadName>

              <dataType>true</dataType>

              <encoding>false</encoding>

              <assertions>true</assertions>

              <subresults>true</subresults>

              <responseData>false</responseData>

              <samplerData>false</samplerData>

              <xml>false</xml>

              <fieldNames>true</fieldNames>

              <responseHeaders>false</responseHeaders>

              <requestHeaders>false</requestHeaders>

              <responseDataOnError>false</responseDataOnError>

              <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>

              <assertionsResultsToSave>0</assertionsResultsToSave>

              <bytes>true</bytes>

              <sentBytes>true</sentBytes>

              <url>true</url>

              <threadCounts>true</threadCounts>

              <idleTime>true</idleTime>

              <connectTime>true</connectTime>

            </value>

          </objProp>

          <stringProp name="filename"></stringProp>

        </ResultCollector>

        <hashTree/>

        <ResultCollector guiclass="SummaryReport" testclass="ResultCollector" testname="Summary Report" enabled="true">

          <boolProp name="ResultCollector.error_logging">false</boolProp>

          <objProp>

            <name>saveConfig</name>

            <value class="SampleSaveConfiguration">

              <time>true</time>

              <latency>true</latency>

              <timestamp>true</timestamp>

              <success>true</success>

              <label>true</label>

              <code>true</code>

              <message>true</message>

              <threadName>true</threadName>

              <dataType>true</dataType>

              <encoding>false</encoding>

              <assertions>true</assertions>

              <subresults>true</subresults>

              <responseData>false</responseData>

              <samplerData>false</samplerData>

              <xml>false</xml>

              <fieldNames>true</fieldNames>

              <responseHeaders>false</responseHeaders>

              <requestHeaders>false</requestHeaders>

              <responseDataOnError>false</responseDataOnError>

              <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>

              <assertionsResultsToSave>0</assertionsResultsToSave>

              <bytes>true</bytes>

              <sentBytes>true</sentBytes>

              <url>true</url>

              <threadCounts>true</threadCounts>

              <idleTime>true</idleTime>

              <connectTime>true</connectTime>

            </value>

          </objProp>

          <stringProp name="filename"></stringProp>

        </ResultCollector>

        <hashTree/>

        <ResultCollector guiclass="StatVisualizer" testclass="ResultCollector" testname="Aggregate Report" enabled="true">

          <boolProp name="ResultCollector.error_logging">false</boolProp>

          <objProp>

            <name>saveConfig</name>

            <value class="SampleSaveConfiguration">

              <time>true</time>

              <latency>true</latency>

              <timestamp>true</timestamp>

              <success>true</success>

              <label>true</label>

              <code>true</code>

              <message>true</message>

              <threadName>true</threadName>

              <dataType>true</dataType>

              <encoding>false</encoding>

              <assertions>true</assertions>

              <subresults>true</subresults>

              <responseData>false</responseData>

              <samplerData>false</samplerData>

              <xml>false</xml>

              <fieldNames>true</fieldNames>

              <responseHeaders>false</responseHeaders>

              <requestHeaders>false</requestHeaders>

              <responseDataOnError>false</responseDataOnError>

              <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>

              <assertionsResultsToSave>0</assertionsResultsToSave>

              <bytes>true</bytes>

              <sentBytes>true</sentBytes>

              <url>true</url>

              <threadCounts>true</threadCounts>

              <idleTime>true</idleTime>

              <connectTime>true</connectTime>

            </value>

          </objProp>

          <stringProp name="filename"></stringProp>

        </ResultCollector>

        <hashTree/>

        <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">

          <boolProp name="ResultCollector.error_logging">false</boolProp>

          <objProp>

            <name>saveConfig</name>

            <value class="SampleSaveConfiguration">

              <time>true</time>

              <latency>true</latency>

              <timestamp>true</timestamp>

              <success>true</success>

              <label>true</label>

              <code>true</code>

              <message>true</message>

              <threadName>true</threadName>

              <dataType>true</dataType>

              <encoding>false</encoding>

              <assertions>true</assertions>

              <subresults>true</subresults>

              <responseData>false</responseData>

              <samplerData>false</samplerData>

              <xml>false</xml>

              <fieldNames>true</fieldNames>

              <responseHeaders>false</responseHeaders>

              <requestHeaders>false</requestHeaders>

              <responseDataOnError>false</responseDataOnError>

              <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>

              <assertionsResultsToSave>0</assertionsResultsToSave>

              <bytes>true</bytes>

              <sentBytes>true</sentBytes>

              <url>true</url>

              <threadCounts>true</threadCounts>

              <idleTime>true</idleTime>

              <connectTime>true</connectTime>

            </value>

          </objProp>

          <stringProp name="filename"></stringProp>

        </ResultCollector>

        <hashTree/>

      </hashTree>

    </hashTree>

  </hashTree>

</jmeterTestPlan>


Saturday 5 December 2020

Example of POM in java selenium

 package com.test.webpages;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.support.FindBy;

import org.openqa.selenium.support.PageFactory;

import org.openqa.selenium.support.ui.*;

import org.assertj.core.api.Assertions;




public class RegistrationPage {

private WebDriver driver;

//private static String url="https://www.cisiveglobal.com/Registration.html";


@FindBy(xpath = "//*[@id='name']")

WebElement elementName;


@FindBy(xpath = "//*[@id='dateofbirth']")

WebElement elementDOB;


@FindBy(xpath = "//*[@id='male']")

WebElement elementMale;


@FindBy(xpath="//*[@id='female']")

WebElement elementFemale;


@FindBy(xpath="//*[@id='qualification']")

WebElement elementQualification;


@FindBy(xpath="//*[@id='mobile']")

WebElement elementMobile;


@FindBy(xpath="//*[@id='emailid']")

WebElement elementEmail;


@FindBy(xpath="//*[@id='address']")

WebElement elementAddress;




public RegistrationPage(WebDriver driver) {

this.driver=driver;

PageFactory.initElements(driver, this);

}


public void enterName(String name) {


Assertions.assertThat(name)

.hasSizeGreaterThan(1)

.hasSizeLessThan(25)

.doesNotContainOnlyWhitespaces();

elementName.sendKeys(name);


}

public void enterDOB(String dateofbirth)

{

Assertions.assertThat(dateofbirth)

.doesNotContainAnyWhitespaces()

.isLessThan(java.time.LocalDateTime.now().toString())

.isGreaterThan("01/01/1900");

elementDOB.sendKeys(dateofbirth);


}

public void enterMale(String male) {

Assertions.assertThat(male)

.doesNotContainAnyWhitespaces()

.isEqualTo("male");

elementMale.click();

}


public void enterFemale(String female) {

Assertions.assertThat(female)

.doesNotContainAnyWhitespaces()

.isEqualTo("female");

elementFemale.click();

}


public void enterQualification(String qualification) {

Assertions.assertThat(qualification)

.doesNotContainAnyWhitespaces();

Select select=new Select(elementQualification);

select.selectByValue(qualification);


}


public void enterMobile(String mobile) {

Assertions.assertThat(mobile)

.doesNotContainAnyWhitespaces()

.hasSizeGreaterThan(0)

.hasSizeLessThan(11)

.containsOnlyDigits();

elementMobile.sendKeys(mobile);


}

public void enterEmail(String email) {

Assertions.assertThat(email)

.doesNotContainAnyWhitespaces()

.hasSizeGreaterThan(3)

.hasSizeLessThan(25);

elementEmail.sendKeys(email);


}

public void enterAddress(String address) {

Assertions.assertThat(address)

.hasSizeGreaterThan(0)

.hasSizeLessThan(255);

elementEmail.sendKeys(address);


}



}



--====================


package com.test.webpages;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.support.FindBy;

import org.openqa.selenium.support.PageFactory;


public class RegistrationPageOperations {


private WebDriver driver;

//private static String url="https://www.cisiveglobal.com/Registration.html";

@FindBy(xpath="//*[@id='btnSubmit']")

WebElement eleBtnSubmit;

@FindBy(xpath="//*[@id='btnReset']")

WebElement eleBtnReset;

public RegistrationPageOperations(WebDriver driver) {

this.driver=driver;

PageFactory.initElements(driver, this);

}

public void clickOnSubmit() {

eleBtnSubmit.click();

}

public void clickOnReset() {

eleBtnReset.click();

}

}


--=================================

package com.test.webpages;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

public class RegistrationSetup {

String driverPath="E:/geocodedriver/chorme/chromedriver.exe";
WebDriver driver;
RegistrationPage regPage;
RegistrationPageOperations regPageOpt;
@BeforeClass
public void Setup() {
System.setProperty("webdriver.chrome.driver", driverPath);
driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.cisiveglobal.com/Registration.html");
}
@Test(priority=1)
public void details_to_registration_page() {
regPage=new RegistrationPage(driver);
regPage.enterName("M Shahnawaz");
regPage.enterDOB("10-10-1990");
regPage.enterMale("male");
regPage.enterQualification("MCA");
regPage.enterMobile("9650953515");
regPage.enterEmail("msnazia2012@gmail.com");
regPage.enterAddress("Shaheen Bagh, New Delhi,Inida - 110065");
regPageOpt=new RegistrationPageOperations(driver);
regPageOpt.clickOnSubmit();
}
@Test(priority=1)
public void reset_to_registration_page()
{
regPageOpt=new RegistrationPageOperations(driver);
regPageOpt.clickOnReset();
}
@AfterClass
public void Teardown() {
driver.quit();
}
}


Friday 20 November 2020

Array List and Custom Class in Java

 As salamo alaikum wa rahmatullah

package collections.demo;


import java.util.ArrayList;


class Employee{

int emp_no;

String empname;

double Salary;

}



public class CustomClassArrayList {


public static void main(String[] args) {

// TODO Auto-generated method stub

ArrayList<Employee> aListEmp=new ArrayList<Employee>();

Employee e=new Employee();

e.emp_no=101;

e.empname="Mohammad Shahnawaz";

e.Salary=1200.99;

aListEmp.add(e);

e=new Employee();

e.emp_no=102;

e.empname="Arham Hanan Zamman";

e.Salary=1200.99;

aListEmp.add(e);

e=new Employee();

e.emp_no=103;

e.empname="Khadija Zamman";

e.Salary=1200.99;

aListEmp.add(e);

for(Employee e1: aListEmp) {

System.out.println("Employee no :- "+e1.emp_no);

System.out.println("Employee name :- "+e1.empname);

System.out.println("Employee salary :- "+e1.Salary);

}

}

}

#kazonline #kazacademy


jazak allah khair

Example of Array List Iterator in Java

 As salamo alaikum wa rahmatullah

Example of Array List and Fetch Element using Iterator in Java
package collections.demo;

import java.util.ArrayList;
import java.util.Random;
import java.util.*;

public class ArrayListIterationDemo {

public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Integer> iList=new ArrayList<Integer>();
for(int i=0; i<=10;i++) {
Random rand=new Random();
int a=rand.nextInt(1000);
iList.add(a);
}
Iterator itr=iList.iterator();
System.out.println("Iterate usin for loop");
for( ; itr.hasNext() ; ) {
System.out.println(itr.next());
}
itr=iList.iterator();
System.out.println("Iterate usin while loop");
while(itr.hasNext()) {
System.out.println(itr.next());
}

}

}

#kazonline #kazacademy


Jazak allah khair

Example of Linked List in Java

 As salamo alaikum wa rahmatullah

package collections.demo;


import java.util.LinkedList;

import java.util.Scanner;


public class LinkedListDemo {


public static void main(String[] args) {

// TODO Auto-generated method stub

LinkedList<String> lList=new LinkedList<String>();

Scanner sc=new Scanner(System.in);

for(int i=0;i<=5;i++) {

System.out.println("Enter the string for Linked List");

String name=sc.nextLine();

lList.add(name);

}

System.out.println(lList);

// iterating data

for(int j=0; j<lList.size();j++) {

System.out.println("Element of Linked List - "+lList.get(j));

}


}


}


Jazak allah khair

Example of Array List in Java

 As salamo alaikum wa rahmatullah

package collections.demo;


import java.util.ArrayList;

import java.util.Scanner;


public class ArrayListDemo {


public static void main(String[] args) {

// TODO Auto-generated method stub

ArrayList<String> aList=new ArrayList<String>();

Scanner sc=new Scanner(System.in);

for(int i=0; i<=5;i++) {

System.out.println("Enter the string for Array List");

String str=sc.nextLine();

aList.add(str);

}

// printing element

System.out.println("Element is Array List"+aList);

// fetching element using for loop

for(int i=0; i<aList.size(); i++) {

System.out.println("Element : -"+aList.get(i));

}


}


}


Jazak allah khair

Example of Array, Vector and Hash Table in Java

 As salamo alaikum wa rahmatullah

Example of Array, Vector and Hash Table


package collections.demo;


import java.util.Hashtable;

import java.util.Vector;


public class CollectionDemo {


public static void main(String[] args) {

// TODO Auto-generated method stub

int arr[]=new int[] {1,2,3,4,5,6};

Vector<Integer> v=new Vector();

Hashtable <Integer,String> hTable=new Hashtable();

// Adding element into the vector

v.add(1);

v.add(2);

v.add(3);

System.out.println(v);

v.set(0, 3);

System.out.println(v);

// Adding element into the HashTable

hTable.put(1, "Selenium");

hTable.put(2, "Java");

hTable.put(3, "OOSPS");

hTable.put(4, "Selenium");

System.out.println(hTable);

String s=hTable.values().toString();

System.out.println("Values of Hash Table :- "+s);

// Array instance creation requires []

// While vector and HashTable require ()

// Vector element insertion required addElement()

// but HashTable element insertion require put()

// Accessing the first element of the 

// array, vector and HashTable

System.out.println(arr[0]);

System.out.println(v.elementAt(0));

System.out.println(hTable.get(1));

}


}

--

Output

[1, 2, 3]

[3, 2, 3]

{4=Selenium, 3=OOSPS, 2=Java, 1=Selenium}

Values of Hash Table :- [Selenium, OOSPS, Java, Selenium]

1

3

Selenium


#kazonline #kazacademy

Jazak allah khair