Friday, March 3, 2023

xpath


locators

 id

name

cssSelector

Xpath

className

tagName

linkText

partialLinkText


Xpath - Firebug and Firepath - Chropath

-----------

<input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="username" spellcheck="false" tabindex="0" aria-label="Email or phone" name="identifier" autocapitalize="none" id="identifierId" dir="ltr" data-initial-dir="ltr" data-initial-value="" badinput="false">



//tagName[@attribute='value'] - Relative Xpath, Absolute xpath, partial xpath



//input[@name='identifier'][@id='identifierId']


//input[@name='identifier' and @id='identifierId']



//input[@id='identifierId']



//*[@id="identifierId"]

//*[@id="identifierId"]


//input[@name='q']


//*[@id="view_container"]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]


//html/


<input type="submit" class="button" value="Submit">

<input type="submit" class="button" value="Submit">`


XPATH SYNTAX

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

//tagName[@attribute='value']

//tagName[@attribute='value'][@attribute='value'][@attribute='value']

//tagName[starts-with(@attribute,'value')]

//tagName[contains(@attribute,'value')]

//tagName[text()='value']

//tagName[contains(text(),'partialvalue')]

//tagName[@attribute='value']/..

//tagName[@attribute='value']/parent::tagname

//tagName[@attribute='value']/following-sibling::tagname

//tagName[@attribute='value']/preceding-sibling::tagname[1]


CSS SYNTAX

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

input[id='identifierId']

input[id='identifierId'][type='email']

input[id^='identifie'] - starts-with

input[id$='tifierId'] - ends-with

input[id*='tifier'] - contains

#identifierId - id

tagName - tagName

.Xb9hP - className

input#identifierId.whsOnd.zHQkBf[type='email']

div.aCsJod.oJeWuf > div > div:first-child

div.aCsJod.oJeWuf > div > div:last-child

div.aCsJod.oJeWuf > div > div:nth-child(2)

div[jsname='dWPKW'] > div > div > div > div:nth-child(2)













Wednesday, March 1, 2023

Selenium Basic code

 import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.edge.EdgeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;


public class SelIntroduction {


public static void main(String[] args) {

//Invoking Browser

//Chrome - ChromeDriver exten->Methods close get

//Firefox- FirefoxDriver ->methods close get

// WebDriver  close  get

//WebDriver methods + class methods

// Chrome

System.setProperty("webdriver.chrome.driver", "/Users/rahulshetty/Documents/chromedriver");

WebDriver driver = new ChromeDriver();


//Firefox

System.setProperty("webdriver.gecko.driver", "/Users/rahulshetty/Documents/geckodriver");

WebDriver driver1 = new FirefoxDriver();

//Microsoft Edge

System.setProperty("webdriver.edge.driver", "/Users/rahulshetty/Documents/msedgedriver");

WebDriver driver2 = new EdgeDriver();

driver.get("https://rahulshettyacademy.com");

System.out.println(driver.getTitle());

System.out.println(driver.getCurrentUrl());

driver.close();

//driver.quit();


}


}

Tuesday, October 14, 2014

Java Selenium interview questions



1.       Tell about  roles and responsibilities of the current project.
2.       Day to day activities of current project.
3.       Java code for count the number of occurrence of each letter.(aabbbccccddd)
4.       Project  flow
5.       Selenium web driver : multi threading concept

8.       How you write the test suit
Test suite is a collection of test cases that are intended to test a behavior or set of behaviors of software program. In
 TestNG, we cannot define a suite in testing source code, but it is represented by one XML file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
  <test name="exampletest1">
    <classes>
       <class name="Test1" />
    </classes>
  </test>
  <test name="exampletest2">
    <classes>
       <class name="Test2" />
    </classes>
  </test>
</suite>  
9.       TestNG methods, which I used in my project

@BeforeSuite: The annotated method will be run before all tests in this suite have run. 
@AfterSuite: The annotated method will be run after all tests in this suite have run. 
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. 
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run. 
@BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked. 
@AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked. 
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked. 
@AfterClass: The annotated method will be run after all the test methods in the current class have been run. 
@BeforeMethod: The annotated method will be run before each test method. 
@AfterMethod: The annotated method will be run after each test method.
@DataProviderMarks a method as supplying data for a test method. The annotated method must return an Object[][] where each Object[] can be assigned the parameter list of the test method. The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotatio
@ParametersDescribes how to pass parameters to a @Test method.
@TestMarks a class or a method as part of the test.

11.   How you write the test case for search engine, example Google.
12.   In UI , if one field is changed to editable to non-editable, how you will test it?
14.   Which one is better in finding element css/xpath? When do you use each one?
not only performance is better with CSS locators, it's the compatibility too that matters.
We are testing on a multy browser environment in which we use: IE, SAFARI, FIREFOX, CHROME.
On IE the xpath almost never works OR it is SO slow that it can't be managed. So we use CSS where ever we can. Unfortunately IE does not support many CSS logics like, previous item, next item, counters and so on. But that can be arranged...
You have to tell your Developers to give distinctive IDs To every and each element you are using. It will greatly speed up your performance because you wont be needing to much XPATH magic to reach elements.

15.   In complicated web page , how you will find the element , by using xpath or css?
16.   If application is working in IE7 and one particular page is working in IE9. So when you navigate to this page it has to work in IE9 and when u navigate to other page it has to come back to ie7 ,
how will you write automation code?
17.   Where you will store the test cases?
hp quality center/ALM test mgt tool

18.   How will you run the test cases, did u use any tool?
hp quality center/ALM test mgt tool

19.   Have idea about Jenkins?

20.   What you automated in your current application?
21.   Difference between interface and abstract?

22.   What is constructor?
23.   What is public static void main() method?
24.   Can you explicitly call other class constructor?
Yes, it is possible:
public class Foo
{
    private int x;

    public Foo()
    {
        this(1);
    }

    public Foo(int x)
    {
        this.x = x;
    }
}
To chain to a particular superclass constructor instead of one in the same class, use super instead of this. Note that you can only chain to one constructor, and it has to be the first statement in your constructor body.
25.   Overloading and overriding?

http://way2java.com/oops-concepts/overloading/difference-method-overloading-overriding-java/

 Overloaded MethodOverridden Method
ArgumentsMust changeMust not change
Return typeCan changeCan’t change except for covariant returns
ExceptionsCan changeCan reduce or eliminate. Must not throw new or broader checked exceptions
AccessCan changeMust not make more restrictive (can be less restrictive)
InvocationReference type determines which overloaded version is selected. Happens at compile time.Object type determines which method is selected. Happens at runtime.

26.   Core java(Hashmap vs HashTable).
http://way2java.com/collections/hashtable/hashtable-vs-hashmap/

27.   String s = "abbcccdddd" to be encoded to 1a2b3c4d using java program.
28.   Program to find if the below pattern matches in given array.
array={10, 23, 1, 45, 5, 6, 2, 7, 8, 9}
 array[n1] < array[n2] < array[n3].
29.   SQL: function, views, Joins(Theory).
30.   Query to get name from table of employee with salary > 1000 (Employee and Salary tables).
31.   Two tables given and write test cases to validate the table data.
32.   difference between selenium webdriver/rc.
33.   what are the common assertions you used in in webdriver.
34.   How do you connect to DB in your java code.
35.   what are the options for logging your result.
36.   what is the object model you used in your framework?
37.   what are locators and name few.?
38.   how do you identify elements on a webpage..which tool did you use?
39.   How do you Sort the numbers using java?
40.   write a program to Reverse a string?
41.   How do you swap two numbers?
42.   Write a program to find factorial or a number using recursion?
43.   How will you search for an  element ?
44.   Find the smallest number from a given array?
45.   Perform Read from a file.
46.   Perform Write from a file.
47.   How will you catch exceptions (write a program with try-catch block)
48.   write a program to find common elements between two arrays?
49.   describe about your automation framework
50.   How do you identify elements in selenium
51.   How do you test Ajax application
52.   What is the difference between implicit and explicit wait?
Implicit Wait:
1.      During Implicit wait if the Web Driver cannot find it immediately because of its availability,
2.      The WebDriver will wait for mentioned time and it will not try to find the element again during the specified time period.
3.      Once the specified time is over, it will try to search the element once again the last time before throwing exception.
4.      The default setting is zero.
5.      Once we set a time, the Web Driver waits for the period of the WebDriver object instance.

Explicit Wait:
·         Suppose there is a scenario, when a particular element takes more than a minute to load.
·         In that case we would definitely not like to set a huge time to implicit wait, as if we do this,
Browser will go to wait for the same time for every element.
In order to avoid such situation,
1.      Introduce a separate time on the required element only.
2.      By following this browser implicit wait time would be short for every element and it would be large for specific element.
Fluent Wait:
Scenario:
Suppose there is an element which takes some time to appear may be in just 1 second & some time it takes minutes to appear.
In that case it is better to use fluent wait,
1 .As this will try to find element again and again until it find it or until the final timer runs out.
53.   What is the difference between assert and verify commands?
Verify command will verify the condition and if its not match, it will give error message in Log area and will start executing next commands. while in assert command, if condition does not match then it will stop remaining script execution.
54.   Write a program in Java to generate Fibonacci Series?

public class fibonacc {

public static void main(String[]args){

int num=8;

int current = 1;
int last = 0;
int lastlast;
for(int i=0;i<num;i++){
lastlast=last;
last=current;
current= last + lastlast;
System.out.println(current);
}}}
55.   Write a Program in Java  given the following scenario.  There will be a log file which will be generated and it will have lot of errors and exception.   you need to extract those words which says errors and write it into a file.

58.   About my project.
59.   Agile Methodology.
60.   Selenium Grid/Remote Web Driver.
61.   Continuous Integration.
62.   Architecture of my frame work. 

Friday, October 10, 2014

Automationframework

1.We have a n existing Test Ng  framework in eclipse
2.we have a maven project structure which has many packages like properties, utility,excel,testbase

3. we keep all our page objects, browser and url information in properties file and read from there using

Properties obj = new Properties();  
  FileInputStream objfile = new FileInputStream(System.getProperty("user.dir")+"\\src\\ObjectRepo\\objects.properties");
  obj.load(objfile);

4. we keep all our xl files in excel package and read from there
5.all the function libraries in utility files





I will create local work space what module i am going to work on -I will check out the module from svn
add required xls files
add the utility files to read and write data
create script to test the functionality by adding assertions ( assert.assetequal,not,true,null) and with different sets of data using data provider...
run all the steps from testng.xml
generate the test report

we can use ant/maven to run from cmd prompt
ant: build.xml  ant clear,compile,run, reports
mvn: main/test : in test we keep files: import the project into eclipse,get jar files by mvn compile in to local,mvn test, mvn test site for run and reports
pom.xml all dependencies we add

we can make .bat file and keep all the commands in there and run
SVN: once done, share or check into svn



Common Assertions

Assertion categories

Assertions are divided in several categories for easier managing. Only categories that contain applicable Assertions for specific type of sampler are enabled. In case of AssertionTestStep only categories that contain applicable Assertions for selected Source/Property combination are enabled ( please check http://www.soapui.org/Functional-Testing/assertion-test-step.html ). Same goes for enabling/disabling particular Assertion inside the category.
In addition under the Categories there is "Recently used" category which lists 5 Assertions most recently used, some of which may also be disabled for particular Source/Property selected.
All available Categories with containing Assertions are listed below.

Property Content Category

  • Contains - Searches for the existence of a string token in the property value, supports regular expressions. Applicable for any property.
  • Message Content Assertion - Allows for complex content validation of XML messages. Applicable to any property containing XML.
  • Not Contains - Searches for the non-existence of a string token in the property value, supports regular expressions. Applicable to any property.
  • XPath Match - uses an XPath expression to select content from the target property and compares the result to an expected value. Applicable to any property containing XML
  • XQuery Math - uses an XQuery expression to select content from the target property and compares the result to an expected value. Applicable to any property containing XML

Compliance, Status and Standards

  • HTTP Download all resource - downloads all resources referred to be an HTML document (images, scripts, etc.) and validates that they are all available. Applicable to any property containing HTML.
  • Invalid HTTP Status Codes - checks that the target TestStep received an HTTP result with a status code not in the list of defined codes. Applicable to any TestStep that receives HTTP messages
  • Not SOAP Fault - validates that the last received message is not a SOAP Fault. Applicable to SOAP TestSteps.
  • Schema Compliance - validates that the last received message is compliant with the associated WSDL or WADL schema definition. Applicable to SOAP and REST TestSteps. The schema definition URL supports Property Expansions (e.g. ${#System#my.wsdl.endpoint}/services/PortType?wsdl ).
  • SOAP Fault - validates that the last received message is a SOAP Fault. Applicable to SOAP TestSteps SOAP Request - validates that the last received request is a valid SOAP Request. Applicable to MockResponse TestSteps only.
  • SOAP Response - validates that the last received response is a valid SOAP Response. Applicable to SOAP TestRequest Steps only.
  • Valid HTTP Status Codes - checks that the target TestStep received an HTTP result with a status code in the list of defined codes. Applicable to any TestStep that receives HTTP messages.
  • WS-Addressing Request - validates that the last received request contains valid WS-Addressing Headers. Applicable to MockResponse TestSteps only.
  • WS-Addressing Response - validates that the last received response contains valid WS-Addressing Headers. Applicable to SOAP TestRequest Steps only.
  • WS-Security Status - validates that the last received message contained valid WS-Security headers. Applicable to SOAP TestSteps.

Script

  • Script Assertion - runs a custom script to perform arbitrary validations. Applicable to TestSteps only (i.e. not properties)

SLA

  • Response SLA - validates that the last received response time was within the defined limit. Applicable to Script TestSteps and TestSteps that send requests and receive responses.

JMS

  • JMS Status - validates that the JMS request of the target TestStep executed successfully. Applicable to Request TestSteps with a JMS endpoint.
  • JMS Timeout - validates that the JMS statement of the target TestStep did not take longer than the specified duration. Applicable to Request TestSteps with a JMS endpoint.

JDBC

  • JDBC Status - validates that the JDBC statement of the target TestStep executed successfully. Applicable to JDBC TestSteps only.
  • JDBC Timeout - validates that the JDBC statement of the target TestStep did not take longer than the specified duration. Applicable to JDBC TestSteps only.

Security

  • Sensitive Information Exposure - Checks that the last received message does not expose an sensitive information about the target system. Applicable to REST, SOAP and HTTP TestSteps.

3. Common Assertions

A large number of assertions are available for validating received messages, some being specific for a certain type of TestStep and some being common for all TestSteps. The assertions available for all TestSteps are:
  • Contains - checks for the existence of a specified string (see below)
  • Not Contains - checks for the non-existence of a specified string (see below)
  • Reponse SLA - check the response time against a specified value (see below)
  • XPath Match - compares the result of an XPath expression to an expected value (read more)
  • XQuery match - compares the result on an XQuery expression to an expected value (read more)
  • Script - runs an arbitrary script that can be used to validate the received message as desired (read more)
The first three of these are covered in more detail below.

3.1. The Contains Assertion

This assertion checks for the existence of some text in the received response or request message, its configuration dialog is as follows:
contains-assertion
The example shown in the screenshot specifies a reqular expression checking for the string "SessionID" in the entire content of the message to be validated, note the "(?s)" construct to specify whitespace handline (supported RegEx format). Property-Expansion is supported in the Content field.

3.2. The Not Contains Assertion

The counterpart for the Contains assertion; this one checks that a specified spring does not exist in the asserted message. The configuration dialog is the same as above:
not-contains-assertion
Here the example in the screenshot just checks for the non-existence of the tolen "Error" in the entire response.

3.3. The Response SLA Assertion

This assertion validates that the response time is within the specified value, otherwise the assertion will fail. The configuration dialog is a simple one:
response-sla-assertion
Property-Expansion is supported in the specified value, allowing you to control the assertion limit via some external mechanism if needed.

4. TestStep specific Assertions

A number of assertions are available that are specific to one or several types of TestSteps. These are covered in more detail together with the corresponding TestStep but also listed below to give you an overview:
For SOAP Request TestSteps the following assertions are available (see Validating SOAP Messages for more details)
  • Schema Compliance - validates the response message against the definition in the WSDL and contained XML Schema
  • SOAP Response - checks that the response is a valid SOAP Response
  • SOAP Fault - checks that the response is a SOAP Fault
  • Not SOAP Fault - checks that the response is not a SOAP Fault
  • WS-Security Status - validates the WS-Security headers and tokens in the response
  • WS-Addressing Response - validates the WS-Addressing Headers in the response
  • JMS Timeout - when using a JMS endpoint that specifies a response channel this assertion validates that the response is received within the specified time
  • JMS Status - when using a JMS endpoint, this assertion validates that no JMS-related errors occured
For REST Request TestSteps the following assertions are also available
  • Schema Compliance - validates the response message against the schema that has either been specified in an underlying WADL file or that has been inferred from the response.
For JDBC Request TestSteps the following assertions are also available
  • JDBC Timeout - validates that the result is received from the target database within the specified time
  • JDBC Status - validates that no JDBC-related errors occured
For MockResponse TestSteps the following assertions are available
  • Schema Compliance - validates the request message against the definition in the WSDL and contained XML Schema
  • SOAP Request - checks that the request is a valid SOAP Request
  • WS-Security Status - validates the WS-Security headers and tokens in the request
  • WS-Addressing Request - validates the WS-Addressing Headers in the request