Showing posts with label HP UFT. Show all posts
Showing posts with label HP UFT. Show all posts

Algorithms

Check if prime or not
1) int i,m,n, Flag = 0
2) n = user input
3) m = n/2 or Sqrt(n)
4) if n <=1 then not prime
5) loop  i = 2 and i<=m
6) if (n%i==0) , Not prime, Flag = 1, break loop
7) if flag = 0, Number is prime


 Check if prime or not between two numbers;
1) input start and end
2) Run loop between 2
3) create a function isPrime(i) and print if prime.

Isprime(i) algorithm
1) int i,m,n
2) n = user input
3) m = n/2 or Sqrt(n)
4) if n <=1 then not prime
5) loop  i = 2 and i<=m
6) if (n%!=0) , Not prime, Flag = 1, break loop
7) if flag = 0, prime.



 Find the factors of numbers
1) Get the number - should not be prime
2) loop fromi =  2 to number/2
3) if number%i = 0, then print i

 Factorial of Number

1) get the number
2) int fact = 1
3) for i = i to number
4) fact = fact * i print fact

String manipulation in UFT

1. Extract number from a string

By using regular expression


Instead of digit, If only string is required the use regular expression as [^\d]

By using mid function

                                                                     -x-
2. Extract certain string from a string





 using regular expression also this fleet can be achieved, but it will be very complex.

3. Extract all matching string from main string


prints delhi 4 times.

to get the count, use colmatch.value here value = 4.

Another way to handle the same












Excel Operations with UFT

1) Create a Excel file









2) Check if Excel file exist, if not then create Excel



3)  Write data to excel



4) Read Data from Excel

 

How to Read and Write in Notepad

Sometimes we need to fetch data from notepad into our script. In this case we use Scripting.FileSystemObject

Here is the code

1) To Read from Notepad








2) To Write to Notepad

Write will erase everything from notepad
 


3)Append Notepad

In case of append, only the num will change into 8. rest remains as write commands.

4) We can add new blank line, skip line and do all other bunch of stuffs

5) Some other cool stuffs