How to sort array values in qtp

Dim yourArray

Dim firstIteration

Dim secondIteration

Dim tempValue

yourArray=array(191,101,144,122,117,111,126,199,145,150,177,1,20202)

msgbox lbound(yourArray)

msgbox ubound(yourArray)

For firstIteration=lbound(yourArray) to ubound(yourArray)

       For secondIteration=lbound(yourArray) to ubound(yourArray)-1

                   If oArray(secondIteration)>yourArray(secondIteration+1) Then

                       tmp=oArray(oCounter2)

                       yourArray(secondIteration)=yourArray(secondIteration+1)

                       yourArray(secondIteration+1)=tempValue

                   End If

                      

       Next

    

Next

For firstIteration=lbound(yourArray) to ubound(yourArray)

   print yourArray(firstIteration)

Next

 

How to find duplicate character in string

Dim objStr

Dim objArray

Dim objchar

objStr = Inputbox(“Enter a String having some duplicate characters in it – as e.g. aacanddoodd”)

objchar= Inputbox(“Input the character you want to find which is duplicated or not as e.g. a or d or o”)

objArray=split(objStr,objchar)

print ubound(objArray)

How to execute javascript in webdriver using javaScriptExecutor using executescript method

How to Execute Javascript in Webdriver using Javascriptexecutor using executescript method?

JavaScriptExecutor can be used to execute javascript in WebDriver. JavaScriptExecutor actions like the way Xpath, Link, CSS, Id locators works in Selenium Webdriver.

javaScriptExecutor is supported by Selenium library and for that you need to import ‘org.openqa.selenium.JavascriptExecutor ‘ in your program.

In Selenium, javaScriptExecutor works like an interface and facilitates Javascript execution in there.

JavaScriptExecutor has two methods.one of the method is as below,

1) executescript – This method will block the execution of next line of code unitl it is completed.

example:

JavascriptExecutor js = (JavascriptExecutor) driver;  

js.executeScript(Script,Arguments);

Example for executeScript

import org.openqa.selenium.JavascriptExecutor;    

import org.openqa.selenium.By;   

import org.openqa.selenium.WebDriver;   

import org.openqa.selenium.WebElement;   

import org.openqa.selenium.firefox.FirefoxDriver;   

import org.testng.annotations.Test;   

public class ExecuteScriptExample {   

@Test   

public void ExecuteScriptTest()

{   

    WebDriver driver= new FirefoxDriver();   

    JavascriptExecutor js = (JavascriptExecutor)driver;   

    driver.get(“your website url having login option”);   

    WebElement button =driver.findElement(By.name(“xxxxxxxx”));   

    driver.findElement(By.name(“uid”)).sendKeys(“admin”);   

    driver.findElement(By.name(“password”)).sendKeys(“admin”);   

    js.executeScript(“arguments[0].click();”, button);

    js.executeScript(“alert(‘Test is completed – welcome to home page’);”);   

}   

}

How to execute javascript in webdriver using javaScriptExecutor executeAsyncScript Method

How to Execute Javascript in Webdriver using Javascriptexecutor using executeAsyncScript method?

JavaScriptExecutor can be used to execute javascript in WebDriver. JavaScriptExecutor actions like the way Xpath, Link, CSS, Id locators works in Selenium Webdriver.

javaScriptExecutor is supported by Selenium library and for that you need to import ‘org.openqa.selenium.JavascriptExecutor ‘ in your program.

In Selenium, javaScriptExecutor works like an interface and facilitates Javascript execution in there.

JavaScriptExecutor has two methods and one of the method is as below,

1) executeAsyncScript – This method will not block the execution of next line of code. Page rendering is fast here.

example:

JavascriptExecutor js = (JavascriptExecutor) driver;  

js.executeAsyncScript(Script,Arguments);

Example for executeAsyncScript

import java.util.concurrent.TimeUnit;   

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.JavascriptExecutor;   

import org.openqa.selenium.firefox.FirefoxDriver;   

import org.testng.annotations.Test;   

public class ExecuteAsyncScriptExample {   

@Test   

public void ExecuteAsyncScriptTest()    

{   

    WebDriver driver= new FirefoxDriver();   

    JavascriptExecutor js = (JavascriptExecutor)driver;   

    driver.get(“your website url”);   

    driver.manage().window().maximize();   

   driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);   

    long BeginTime = System.currentTimeMillis();   

    //executeAsyncScript() method is used to enable 10 seconds wait.

    js.executeAsyncScript(“window.setTimeout(arguments[arguments.length – 1], 10000);”);    

    long EndTime = System.currentTimeMillis();   

    System.out.println(“Passed time: ” + (EndTime – BeginTime));   

}   

}    

How to create a word document using VBscript in QTP?

How to create a word document using VBscript in QTP?

Dim oWordDocument

‘ To initaiate a Word Document object

Set oWordDocument = CreateObject(“Word.Application”)

oWordDocument.Documents.Add

‘ type words on documents

oWordDocument.Selection.TypeText “This is 1st line text on word file ” & vbnewline & “This is 2nd line text on word file”

oWordDocument.ActiveDocument.SaveAs “C:\SampleWordDoc.doc”

oWordDocument.Quit

Set oWordDocument=Nothing

How to find the alpha characters in a given string

How to find the alpha characters in a given string

 

Dim objStr

Dim objLength

Dim objChar

objStr=”1q2w3etest”

objLength=len(objStr)

alphacount=0

For i=1 to objLength

If not isnumeric (mid(objStr,i,1)) then

alphacount =alphacount+1

alphacharacter  = alphacharacter & mid(objStr,i,1)

End if

Next

msgbox “alpha chara count is  ” & alphacount

msgbox “alpha charaters are :   ” & alphacharacter

How to run java script on webdriver

Steps,

  1. create a java project using Eclipse IDE
  2. add a package and then a class (refer below code for package name and class name)
  3. then add necessary jar files (selenium-server-standalone-2.53.0, testing, etc)
  4. then copy/paste and update the code in your IDE
  5. place chromedriver in the folder and update code below for folder “Users/shali/Downloads/” path matching your pc folder
  6. run your script to verify results.

JavaScriptExample;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.remote.DesiredCapabilities;
public class JavaScriptTest {
public static void main(String[] args) {
 System.setProperty(“webdriver.chrome.driver”, “/Users/shali/Downloads/chromedriver”);
 ChromeOptions options = new ChromeOptions();
options.addArguments(“window-size=1024,680”);
 DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
 driver.get(“https://shalimatech.com/”);
 if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver)
.executeScript(“alert(‘testing for java script’);”);
}
  }
}

Dockers vs Virtual machines

Dockers vs Virtual machines, a quick note about the difference between two.

Docker is an open source tool used to make package of an application which contains all required libraries , dependent programs, files etc. Docker makes it easy to create , deploy and execute application programs.  Docker will give the surety that application will work without any issues in any given machine..

 However Virtual machines(VM) used to create virtual Operating system(OS) and are designed to run OS on servers. VM will emulate hardware. However Containers are faster and lighter than VM.

 

How to run jmeter in jenkins

How to run jmeter in jenkins

steps:

Jenkins setup and performance plugin setup:
1) copy performance plugin into Jenkin’s home directry before you start the test.
2) to do that – you can download the performance plugin “performance.hpi” from the site https://wiki.jenkins-ci.org/display/JENKINS/Performance+Plugin
3) how to find the home directry of jenkins – to do that you can navigate to jenkins home page (localhost:8080) and then
4) click on “Manage Jenkins” and then click on “Configure system” the you will notice “Home directy” path in there.

Configure Jmeter and create a basic script in Jmeter:
5) download Jmeter Binary zip file from Jmeter site http://jmeter.apache.org/download_jmeter.cgi
6) unzip it and go to the “bin” directory of the Jmeter folder, wherre you will notice “user.properties” file.
7) open the file in notepad or notepad++ or any other text editor
8) add a line “jmeter.save.saveservice.output_format=xml” to that. Save and close the “user.properties” file
9) create a Jmeter script and make sure you can run it in non GUI mode i.e either in DOS mode or using shell scripts in MAC (note down the commands used in respective OS and it could be used in Jenkins job setup)
Note: for windows command line run, you can use the following commands

C:\[JMETER BIN directory]\jmeter.bat -Jjmeter.save.saveservice.output_format=xml -n -t C:\[JMETER script “.jmx” file] -l Jmeter_test_results.jtl

Note 1: For detailed topics on Jmeter scripts creation , please visit Jmeter , Jmeter recording 

setup Jenkin’s job to run Jmeter scripts
9) go to Jenkins home page (localhost:8080) and then click on “New Item” on “Freestyle project”
10) in the “New item” page, give some name in the item name field and go to below to section “Build” and add build step
11) add build step can be either a) “execute windows batch command” for windows or b) “Execute shell” for MAC
12) provide your command in there and save.
13) Click on “Build now” which would call the Jmeter (jmx) file and run the program
14) after the run, you can verify the Jenkins console to review the results.