Dim n
n=inputbox ("Enter a number to display first 10 factors")
for i=1 to 10
msgbox n & " X " & i & " = " & n*i
next
Monday, March 23, 2015
Find the factorial of a given number
Dim n
n=inputbox ("Enter a number to compute factorial")
fact=1
for i=2 to n
fact=fact*i
next
msgbox "The factorial of " & n & " is " & fact
n=inputbox ("Enter a number to compute factorial")
fact=1
for i=2 to n
fact=fact*i
next
msgbox "The factorial of " & n & " is " & fact
Print even numbers in a range
Dim n
n=30
for i=1 to n
if i mod 2 = 0 then
msgbox "The number: " & i & " is even"
end if
next
n=30
for i=1 to n
if i mod 2 = 0 then
msgbox "The number: " & i & " is even"
end if
next
Find whether given number is a odd number
Dim n
n=inputbox ("Enter a number")
if n mod 2 = 0 then
msgbox "The number: " & n & " is not odd"
else
msgbox "The number: " & n & " is odd"
end if
n=inputbox ("Enter a number")
if n mod 2 = 0 then
msgbox "The number: " & n & " is not odd"
else
msgbox "The number: " & n & " is odd"
end if
Tuesday, June 24, 2014
Common mistakes by QTP tester
Below are the items to make sure you include to avoid mistakes
2. Improper reporting: One need to report after each and every step such that the report should look like a test case with all steps in detail
3. Type casting: While comparing the expected and actual value, the values have to be converted and both of them should belong to the same data type to get compared. Else the step fails though the value is correct
4. Mandate Else block: For each If statement there should be an Else statement to ensure the coverage of all the flows
5. Using on error resume next: Many a times the errors go unnoticed due to this line. Ensure that you use On error go to 0 after the block where you think the error will not occur. Else, you need to comment this line every time you debug the code to identify theh exact error
6. Using of Exit for and exit loop: One should use these statement liberally to improve the performance of the script
7. Use .exist with a timeout ex. broswer().page().exist(3) to improve the performance
8. Check the qtp run status or error number before reporting it to the custom report like excel or html, else the actual report would be failed but the custom report shows pass
9. Always clear the local object repository while using share repository as the objects in local repository will be given preference and properties would change and script would fail
10. Delete the Browser chache each time you start the execution so that the latest/updated files would be downloaded from the server.
1. Capture screen for
failure steps: Many times we ignore this and many a times we end up in
unable to reproduce it. Its safe to capture a screenshot and save it in a
location for future reference and escalation
2. Improper reporting: One need to report after each and every step such that the report should look like a test case with all steps in detail
3. Type casting: While comparing the expected and actual value, the values have to be converted and both of them should belong to the same data type to get compared. Else the step fails though the value is correct
4. Mandate Else block: For each If statement there should be an Else statement to ensure the coverage of all the flows
5. Using on error resume next: Many a times the errors go unnoticed due to this line. Ensure that you use On error go to 0 after the block where you think the error will not occur. Else, you need to comment this line every time you debug the code to identify theh exact error
6. Using of Exit for and exit loop: One should use these statement liberally to improve the performance of the script
7. Use .exist with a timeout ex. broswer().page().exist(3) to improve the performance
8. Check the qtp run status or error number before reporting it to the custom report like excel or html, else the actual report would be failed but the custom report shows pass
9. Always clear the local object repository while using share repository as the objects in local repository will be given preference and properties would change and script would fail
10. Delete the Browser chache each time you start the execution so that the latest/updated files would be downloaded from the server.
11. Use print instead of msgbox so that if you miss to delete or comment it, print wouldnt stop the execution.
Wednesday, March 12, 2014
Capture password from email in outlook using QTP
Consider the message by auto sending "Password service" is as below
Hi User,
Please find the credentials below.
User Name is: name597406
New password is: KI7UJ6$x^3DIwul
Note: Please change your password as soon as you login into your application
Thanks & Regards,
Admin
Check the "From" field and note the Display name of the sender and let it be "Password Service"
The code is as below
Dim olFolderInbox, iTotalMails, sSubject
olFolderInbox = 6 : sSubject = ""
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
'Create reference to Inbox Folder
Set oInbox = objNamespace.GetDefaultFolder(olFolderInbox)
'Find all items in the Inbox Folder
Set oAllMails = oInbox.Items
iTotalMails = oAllMails.Count
'Loop through the mail items
For i=1 to iTotalMails
'Check if the mail is UnRead or not
If oAllMails(i).UnRead = True Then
' msgbox oAllMails(i).sendername
If oAllMails(i).sendername="Password Service" then
res=split(oAllMails(i).Body,"password is: ")
res1=split(res(1),"Note:")
msgbox res1(0)
Exit for
end if
End If
Next
Sunday, February 16, 2014
Log4j implementation
Following are the steps
to generate logs for the applications,
Step1: Create one sample project
Step2: Create Package in the project to place java classes
Step3: Download Lo4j jar file from http://logging.apache.org/log4j/1.2/download.html
Step4: Add log4j jar file to the project build path
Step5: Create log4j property file at the project level and add the
properties into the file as shown in fig1.
|
#All==>all
messages
#WARN==>only
warning message etc..
log4j.rootLogger=ALL
#log4j.logger.<Package>=,<log
file name>FileAppender
log4j.logger.com.pack=,logTestFileAppender
#
junit_log4jFileAppender - used to log messages in the junit_log4j.log file.
log4j.appender.logTestFileAppender=org.apache.log4j.FileAppender
log4j.appender.logTestFileAppender.File=logTest.log
log4j.appender.logTestFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.logTestFileAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %-4r [%t] %-5p %c %x - %m%n
|
Fig 1: log.properties
Step6: Create one java class in the package
Step7: Create reference variable for logger class as shown in
fig2.
|
public static
Logger logger=Logger.getLogger(classname.class)
|
Fig2: Reference Variable for Logger Class
Step8: In the main method load the logger properties by using configure()
method in PropertyConfigurator Class.
Step9: By using Logger reference variable write info, debug and
error etc types of logs as shown in fig3.
|
Logger.info(“START:: Starting of
some XY()”);
Logger. debug(“Values passed to
the some XY() are :: a: ”+a);
Logger. error(“ERROR:: Error
occurred in some XY()”);
|
Fig3: Sample code to
write info, debug and error logs
Step10: After completion of code run the project and find the
generated logs in the path given in log.propeties for the property “log4j.appender.logTestFileAppender.File”.
Example:
package com.pack;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LogExample {
public static Logger logger=Logger.getLogger(LogExample.class);
public void test() {
WebDriver driver=new FirefoxDriver();
logger.info("Browser Launched");
driver.get("http://www.gmail.com");
logger.info("URL Entered");
logger.debug("Hi");
logger.fatal("Hello");
}
public static void main(String[] args) {
PropertyConfigurator.configure("log.properties");
LogExample example=new LogExample();
example.test();
}
}
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LogExample {
public static Logger logger=Logger.getLogger(LogExample.class);
public void test() {
WebDriver driver=new FirefoxDriver();
logger.info("Browser Launched");
driver.get("http://www.gmail.com");
logger.info("URL Entered");
logger.debug("Hi");
logger.fatal("Hello");
}
public static void main(String[] args) {
PropertyConfigurator.configure("log.properties");
LogExample example=new LogExample();
example.test();
}
}
Subscribe to:
Comments (Atom)
AI in Software Testing: How Artificial Intelligence Is Transforming QA
For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...
-
Test-Driven Development (TDD) is a software development approach that emphasizes writing automated tests before writing the code. The appr...
-
Agile software development is a highly iterative and collaborative approach to software development that emphasizes flexibility and a...
-
Software development is a complex process that requires a high degree of accuracy, efficiency, and speed. One way to achieve these goals i...