Friday 31 May 2013

Handling untrusted SSL certificates using selenium webdriver in IE?


Some time we get these SSL errors or notification when we try to execute our scripts,At that time we need to by pass that one

SSL error in IE In the following way..













To By pass it just need to add a small piece of code when ever it occurs.

i.e

try {
                driver.get("javascript:document.getElementById('overridelink').click();");
            } catch (Exception e) {
            }

Generate Interactive reports Using TestNG+ANT +XSLT In Selenium

XSLT stands for XML (Extensible Markup Language) Stylesheet Language for Transformations.
XSLT gives interactive(user friendly) reports with "Pie Chart"; but only on TestNG framework. It is better compared to ReportNG and ordinary TestNG reports. Its uses the pure XSL for report generation and Saxon as an XSL2.0 implementation.

XSLT = XSL Transformations

Steps to Generate testng-xslt report:

1. Download testmg-xslt.zip
2. Unzip and copy the testng-results.xsl from the testng-xslt folder(testng-xslt-1.1\src\main\resources) to your own project folder.
3. Now copy the saxon library from (testng-xslt-1.1\lib\saxon-8.7.jar)to your project lib folder.
4. Modify your build.xml of ant and add the following target to it.

Build.xml Configuration


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

<project>
    <property name="src.dir" value="src" />
    <property name="lib.dir" value="lib" />
    <property name="log.dir" value="logs" />
    <property name="build.dir" value="build" />
    <property name="classes.dir" value="classes" />
    <property name="reports.dir" value="reports" />
    <property name="testNG.report" value="${reports.dir}/TestNG" />
    <property name="suite.dir" value="suite" />
    <!-- Class-Path -->
    <path id="classpath">
        <pathelement location="${classes.dir}"/>
        <fileset dir="${lib.dir}" includes="*.jar"/>
    </path>
    <!-- Delete directories that are not needed -->
    <target name="delete-dir" >
            <delete dir="${build.loc}"/>
            <delete dir="${reports.dir}"/>
            <delete dir="${classes.dir}"/>
            <echo> /* Deleted existing Compiled Directory Classes */ </echo>
    </target>
    <!-- Create Directories -->
    <target name="create-source-dir" depends="delete-dir">
        <mkdir dir="${classes.dir}"/>
        <mkdir dir="${reports.dir}"/>       
        <mkdir dir="${testNG.report}"/>
        <echo> /* Created Directories */ </echo>
    </target>
    <!-- Compiling Tests -->
    <target name="compile-classes" depends="create-source-dir">
        <javac destdir="${classes.dir}" includeantruntime="false" debug="true" srcdir="${src.dir}">
            <classpath refid="classpath"/>
        </javac>
        <echo> /* Compiled Directory Classes */ </echo>
    </target>
    <!-- Running Tests and TestNG report generation -->
    <target name="testNGreport" depends="compile-classes">
        <taskdef resource="testngtasks" classpathref="classpath"/>
        <testng classpathref="classpath" outputDir="${testNG.report}" haltOnfailure="false">
              <xmlfileset dir="." includes="${suite.dir}/TestNG.xml" />
        </testng>
        <echo> /* Run Directory Classes */ </echo>
    </target>
   
         <target name="testng-xslt-report">
                <delete dir="${basedir}/testng-xslt">
                </delete>
                <mkdir dir="${basedir}/testng-xslt">
                </mkdir>
                <xslt in="${basedir}/reports/TestNG/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
                    <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
       
                    <param expression="true" name="testNgXslt.sortTestCaseLinks" />
       
                    <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
       
                    <param expression="true" name="testNgXslt.showRuntimeTotals" />
       
                    <classpath refid="classpath">
                    </classpath>
                </xslt>
            </target>
   
</project>


5. Create TestNG.xml file in your project with the following script for TestNG execution.
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
  <test name="Test">
    <classes>
      <class name="package.classname"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->
6. Now, try to run the command.
Navigate to Project Location from command prompt  

ant testng-xslt-report
Results will be look like this:






Tuesday 28 May 2013

QTP Interview Questions for 2+ exp


1. Explain QTP automation framework.

2. What is HYBRID framework?

3. What are the Features & Benefits of QTP?

4. What are the types of Object Repositories in QTP?

5. Which object repository we use in real time and can we merge 2 object repostiory and

how? 
as said there r 2 types of object repository i.e.

1) per action

2) shared mode

by default its per action but in real time we use shared mode.

yaa we can merge two obj rep by an option " merge object

repositories in Quick Test Plus.

6. Explain the concept of object repository.

7. How QTP recognizes objects?

8. WHAT IS THE USE OF "FUNCTION GENERATOR" IN QTP? 
1)the use of functional generator in
qtp is which lists out

the all the built in functions in qtp and helps you to

write the vb script for un known objects.

2)it is also used to reduce the typing mistakes & synta

errors


9. What is User defined function in QTP 
user defined function is nothing but ,u can define ur own

fuction for particular functionality.

Normaly we will create user defined functions for the

reusable functionality(which is available in ur

application)

10. How we can add actions in the test using QTP? 
there four actions call to action ,copy of action,call to

exesitng action,call to winner,split action just right

click on any one select it



11. How to write script in qtp(vbscript), I mean without application deployed..and how to call

script1 into script2?
 runaction actionname(iteration mode,iteration

range,parameters)

12What is the differnce between action & script? 
A script can have multiple actions.

A script is a test case which have multiple actions.

For an example, for an functional testing you can single

action which can be considered as a script

For integration testing you

can add multiple actions which

is also considered together as a script

12. what will happen in object repository(shared) if we call an existing action from an

external action? and what happen in object repository(per action)if we call an existing

action from an external action?

13. Suppose I have 5 Actions in my Test script. Out off which i want to make 3rd action as

my start-up action. How should i make it?

14. What is the difference between Call Run action and copy of action?

15. What are reusable actions?

16. What is the difference between functions and actions in QTP?

17. What is the difference between function and sub-routine.?

18. What is batch testing?

19. HOW TO DO THE BATCH TESTING USING QTP?

20. In how many ways you perform batchtesting?

21. Write a sample script/ small code snippet to COUNT TOTAL NUMBER OF HYPERLINKS on

a webpage.

22. Write a sample script/ small code snippet to select any radio-button or checkbox on a

webpage.

23. What is descriptive programming.? What are it’s pros and cons.?

24. Have you ever written a compiled module? If yes tell me about some of the functions

that you wrote.

Ans: I Used the functions for Capturing the dynamic data during runtime. Function

used for Capturing Desktop, browser and pages.



25. Can you do more than just capture and playback in QTP?

26. What is the difference between check point and output value.

27. Discuss QTP Environment.

28. Differentiate the two Object Repository Types of QTP.

29. How to handle dynamic objects in QTP?

30. How many checkpoints can be used in QTP.?

31. Is it possible to connect QTP with QC.? If Yes then how.?

32. Can the defects be logged automatically in QC for a script getting failed of a testcase.?

If Yes then how.?

33. What is a Run-Time Data Table? Where can I find and view this table?

34. What is the difference between image checkpoint and bitmap checkpoint

35. What is the concept of checkpoint declaration in the QTP mainly for the Objects, Pages,

Text and Tables ?

36. What is the limitation to XML Checkpoints?

37. What is the use of Accessibility check point?

38. Where is the bitmap checkpoint be saved?

39. In how many ways we can add check points to an application using QTP.?

40. What is the difference between Table checkpoint and Database checkpoint in QTP?

41. What is parameterization? How we can implement it in QTP.?

42. In how many ways does parameterization can be done in QTP?

43. How does Parameterization and Data-Driving relate to each other in QTP?

44. What are the properties you would use for identifying a browser & page when using

descriptive programming ?

45. What are the different scripting languages you could use when working with QTP ?

46. Explain the keyword createobject with an example.

47. How to handle the exceptions using recovery secnario manager in QTP?

48. How to use the Object spy in QTP?

49. what is the use of Text output value in Qtp?

50. What is the file extension of the code file & object repository file in QTP?

51. Can we merge two object repositories.? If Yes then How.?



52. How to make arguments optional in a function?

53. How to covert a String to an integer?

54. Inserting a Call to Action is not Importing all columns in Datatable of globalsheet. Why?

55. How to supress warnings from the "Test results page"?

56. When we try to use test run option "Run from Step", the browser is not launching

automatically why?

57. Does QTP is "Unicode" compatible?

58. How to "Turn Off" QTP results after running a Script?

59. How to verify the Cursor focus of a certain field?

60. How to handle Run-time errors in QTP?

61. How to change the run-time value of a property for an object?

62. How to retrieve the property of an object?

63. How to open any application during Scripting?

64. What Types of properties that QTP learns while recording?

65. Can we Script any test case with out having Object repository? or Using Object

Repository is a must?

66. How to execute a WinRunner Script in QTP?

67. 3 differences between QTP & Winrunner?

68. How to add a runtime parameter to a datasheet?

69. What scripting language is QTP of ?

70. How we can Analyze the Checkpoint results.?

71. what do you call the window testdirector-testlab?

72. How to Import data from a ".xls" file to Data table during Runtime.

73. How to export data present in Datatable to an ".xls" file?

74. Where can I find information on the IE Document Object Model?

75. How to terminate an application that is not responding?

76. How to record on non standard menus?

77. How to configure Quick Test to record on Embedded HTML Controls?

78. How do I launch a new browser from a test?

79. How do I make the test prompt the user for input while it is running?

80. How to remove result files from old tests?

81. How to change the logical name of a Test Object?

82. What is the significance of “Mic.ini file” in QTP.?How we can modify it.?

83. How to change the registry settings for QTP?

84. How to use Environment variable?

85. Does Quick Test have any debugging capabilities?

86. What command-line arguments can I use when launching Quick Test?



87. I have a Microsoft Access database that contains data I would like to use in my test.

How do I do this?

88. How do I add a manual wait step to my test?

89. How the Smart identification mechanism works ?

90. What are the properties used by the Smart Identification mechanism?

91. Can I change the Active Screen page which is shown on every new test?

92. What is ACTION TEMPLATE in QTP? How we can create it?

93. How to pass parameters when calling actions?

94. How to configure the report to show only error (by default)?

95. What is the purpose of Object spy?

96. What is the return value of the ‘Quit’ Method?

97. What is the purpose of loading QTP Add-Ins?

98. Can we re-use the user defined Environment variables?

99. What is Object model ?

100. Can A user use object repository file for two different tests which Are running at the

same time??

101. How do you comment your script?

102. How do you handle pop-up exceptions?

103. What are batch tests and how do you create and run batch tests?

104. How do you store and view batch test results?

105. What are function Key Strokes?

106. How to record the function Key Strokes?

107. What are Environment variable?

108. How do you write messages to the report?

109. What is the diff between SystemUtil.Run and Invoke?

110. How can I improve the working speed of QTP?

111. How do I maintain my test when my application changes?

112. What are the new features available in QTP 9.5?

113. What is the Extensions of Script, Repositories Files?

114. How do you automate the Quick Test settings?

115. Explain about Update Run in QTP ?

116. Several QTP scripts may be called in a BPT test. Each one may have different data in a

data table. How can the BA in BPT override and control data tables?

117. Can users who prefer descriptive programming in QTP have the ability to SaveAs

Descriptive? If this is chosen, the OR values could be saved in the script instead of the

logical values.

118. Will QTP/BPT work with descriptive programming or only through the object repository?

 

119. Win Runner uses TSL which is a derivative of C. QuickTestPro is VBScript. How are

you going to be able to port Win Runner scripts to QuickTestPro?

120. How are checkpoint baseline values and the purpose of the checkpoint

communicated back to the BA in BPT ?

121. Can it be confirmed that Quality Center works with Microsoft SQL Server?


Monday 27 May 2013

Qtp Script to download attachments from outlook emails

Qtp Script to download attachments from outlook emails

Set a = CreateObject("Outlook.Application")
Set b = a.GetNameSpace("MAPI")
Set c = b.GetDefaultFolder(6)
For each item in C.Items
if item.unread then
For each att in item.attachments
FileName="C:\Email Attachments\" &att.FileName
att.saveasfile FileName
Next
End if
Next

qtp script to display string vertically

qtp script to display string vertically


a = "SatyasAutomation"

x=len(a)

For i = 1 to x

b = b & vbnewline & Mid(a,i,1)

Next

Msgbox b

Qtp Script to find the number of occurences of a char in a string


Qtp Script to find the number of occurences of a char in a string


str="hellllllllo all"

counter=0

For i=1 to len(str)

char=mid(str,i,1)

If char="l" Then

counter=counter+1

End If

Next

Msgbox counter

QTP Script:turn On and turn Off Capslock using SendKeys

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{CAPSLOCK}"
Msgbox"CapsLock is ON"
WshShell.SendKeys "{CAPSLOCK}"
Msgbox"CapsLock is OFF"
Similarly we can turn On/Off NumLock and ScrollLock also.
WshShell.SendKeys "{NUMLOCK}"
WshShell.SendKeys "{SCROLLLOCK}"

Sunday 26 May 2013

Different ways to refresh the WebPage in selenium WebDriver


 5 different ways, using which we can refresh a webpage.There might be even more :)

There is no special extra coding. I have just used the existing functions in different ways to get it work. Here they are
  
1.Using sendKeys.Keys method

driver.get("https://accounts.google.com/SignUp"); 
driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);

 2.Using navigate.refresh()  method


  driver.get("https://accounts.google.com/SignUp");   
driver.navigate().refresh(); 


3.Using navigate.to() method
 
driver.get("https://accounts.google.com/SignUp");   
driver.navigate().to(driver.getCurrentUrl()); 


4.Using get() method
 
driver.get("https://accounts.google.com/SignUp");   
driver.get(driver.getCurrentUrl()); 

5.Using sendKeys() method

driver.get("https://accounts.google.com/SignUp");  
driver.findElement(By.id("firstname-placeholder")).sendKeys("\uE035"); 







 

Selecting a date from Datepicker in Selnium WebDriver

If we look at the Datepicker, it is just a like a table with set of rows and columns.To select a date ,we just have to navigate to the cell where our desired date is present.

Here is a sample code on how to pick a 13th date from the next month.

import java.util.List;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 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.BeforeTest;
import org.testng.annotations.Test;;

public class DatePicker {

 WebDriver driver;
 
 @BeforeTest
 public void start(){
 System.setProperty("webdriver.firefox.bin""C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");  
 driver = new FirefoxDriver();
 }
 
 @Test
 public void Test(){
 
  driver.get("http://jqueryui.com/datepicker/");
  driver.switchTo().frame(0);
  driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
  //Click on textbox so that datepicker will come
  driver.findElement(By.id("datepicker")).click();
  driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
  //Click on next so that we will be in next month
  driver.findElement(By.xpath(".//*[@id='ui-datepicker-div']/div/a[2]/span")).click();
  
  /*DatePicker is a table.So navigate to each cell 
   * If a particular cell matches value 13 then select it
   */
  WebElement dateWidget = driver.findElement(By.id("ui-datepicker-div"));
  List<webelement> rows=dateWidget.findElements(By.tagName("tr"));
  List<webelement> columns=dateWidget.findElements(By.tagName("td"));
  
  for (WebElement cell: columns){
   //Select 13th Date 
   if (cell.getText().equals("13")){
   cell.findElement(By.linkText("13")).click();
   break;
   }
  } 
 }
}</webelement></webelement> 

Monday 20 May 2013

Selenium Sampleinterview Questions


  1. In your experience, what are some of the challenges with Selenium?
Some Challenges:
The use of the locators need to be carefully thought through.
Handling Dynamic Elements
Handling Ajax Call Element
Handling Http's URL's

2.What is the difference between an assert and a verify with Selenium commands?

Assert: Will fail and abort the current test execution.
Verify: Will fail and continue to run the test execution.
3.How many testing frameworks can QA Tester use in Selenium RC?
Testing frameworks aren’t required, but they can be helpful if QA Tester wants to automate test cases. Selenium RC supports Bromine, JUnit, NUnit, RSpec (Ruby), Test::Unit (Ruby), TestNG (Java), unittest (Python).

4.Does Selenium support mobile internet testing?

Selenium supports Opera and opera is used in most of the Smart phones. So whichever Smart phone supports opera, selenium can be used to test. So, one can use Selenium RC to run the tests on mobiles

5. What are the basic annotations used to run TestNG tests in Selenium?

The basic annotations used to run TestNG tests in Selenium RC:
1. @BeforeClass: The annotated method with @BeforeClass will be run before the first test method in the current class is invoked.
2. @AfterClass: The annotated method with @AfterClass will be run after all the test methods in the current class have been run.
3. @BeforeMethod: The annotated method with @BeforeMethod will be run before each test method.
4. @AfterMethod: The annotated method with @AfterMethod will be run after each test method.
5. @Test: Marks a class or a method @Test with as part of the test.

6.What is the difference between Thread.Sleep() and Selenium.setSpeed()

Selenium.setSpeed:
1. takes a single argument in string format
ex: selenium.setSpeed(“2000″) – will wait for 2 seconds
2. Runs each command in after setSpeed delay by the number of milliseconds mentioned in setSpeed.
Thread.sleep:
1. takes a single argument in integer format
ex: thread.sleep(2000) – will wait for 2 seconds
2. Waits for only once at the command given at sleep.

7.  How to configure Selenium RC with eclipse to run Junit Tests?
  1. Download eclipse. click here to download the software
    2) Open eclipse -> Workspace Launcher window will open
    3) Create a workspace by giving meaningful name
    3) Click on Workbench
    4) Create a project of type java
    5) Create a package under src folder of the package
    6) Add Junit to the build path
    7) Add selenium rc java client driver to the build path
    8) Now drag and drop your test script (.which is exported from Selenium IDE) to the package created.


8.Which browsers does WebDriver support?

The existing drivers are the ChromeDriver, InternetExplorerDriver, FirefoxDriver, OperaDriver and HtmlUnitDriver. For more information about each of these, including their relative strengths and weaknesses, please follow the links to the relevant pages. There is also support for mobile testing via the AndroidDriver and IPhoneDriver.

9.What is Web Driver?

Web Driver uses a different underlying framework from Selenium’s javascript Selenium-Core. It also provides an alternative API with functionality not supported in Selenium-RC. WebDriver does not depend on a JavaScript core embedded within the browser; therefore it is able to avoid some long-running Selenium limitations.
WebDriver’s goal is to provide an API that establishes
A well-designed standard programming interface for web-app testing.
• Improved consistency between browsers.

    10. Describe Technical Problems that you had with selenium tool
    11.Wht does SIDE Stands for
        ans:Selenium IDE
    12.What Programming Languages is best for writing the Selenium Tests
    13.Compare QTP vs Selenium
    14.Can tests recorded using Selenium IDE be run in other browsers?
Ans:Yes. Although Selenium IDE is a Firefox add on, however, tests created in it can also be run in other browsers by using Selenium RC (Selenium Remote Control) and specifying the name of the test suite in command line.

    15.What are the locators available in Selenium?
    16..What is the difference between single and double slash in Xpath
                 Ans : / selects children of the context node,
                         // selects descendants of the context node.
    17. what is the diffarence b/w TestNG and Junit

    18. Explain about your reporting method
    19. How do you handle the secured connection error in HTTPS?
    20. How do you handle Ajax controls using selenium?
    21. Diffarent Types of Automation Framework
    22.what is the diffarence between Implicit and Explicit wait in selenium
    23. How to Handle the webTable data using Selenium
    24.What is the diffarence between actions, accessors,assertions