kttbase
Friday, March 3, 2023
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
http://software-testing-tutorials-automation.blogspot.com/2014/07/create-data-driven-framework-for.html
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>
@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.
@DataProvider | Marks 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 |
@Parameters | Describes how to pass parameters to a @Test method. |
@Test | Marks a class or a method as part of the test. |
http://selenium-suresh.blogspot.com/2013/09/selenium-webdriver-methods-with-examples.html
hp quality center/ALM test mgt tool
hp quality center/ALM test mgt tool
public class Foo
{
private int x;
public Foo()
{
this(1);
}
public Foo(int x)
{
this.x = x;
}
}
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.Overloaded Method | Overridden Method | |
---|---|---|
Arguments | Must change | Must not change |
Return type | Can change | Can’t change except for covariant returns |
Exceptions | Can change | Can reduce or eliminate. Must not throw new or broader checked exceptions |
Access | Can change | Must not make more restrictive (can be less restrictive) |
Invocation | Reference type determines which overloaded version is selected. Happens at compile time. | Object type determines which method is selected. Happens at runtime. |
Browser will go to wait for the same time for every element.
Suppose there is an element which takes some time to appear may be in just 1 second & some time it takes minutes to appear.
1 .As this will try to find element again and again until it find it or until the final timer runs out.
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.
public class fibonacc {
public static void main(String[]args){
int num=8;
Friday, October 10, 2014
Automationframework
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
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
- 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)
3.1. The Contains Assertion
3.2. The Not Contains Assertion
3.3. The Response SLA Assertion
4. TestStep specific Assertions
- 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
- 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.
- 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
- 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