Beruflich Dokumente
Kultur Dokumente
o java.lang.Object
o org.openqa.selenium.By
o org.openqa.selenium.By.ByClassName (implements java.io.Serializable)
o org.openqa.selenium.By.ByCssSelector (implements java.io.Serializable)
o org.openqa.selenium.By.ById (implements java.io.Serializable)
o org.openqa.selenium.By.ByLinkText (implements java.io.Serializable)
o org.openqa.selenium.By.ByName (implements java.io.Serializable)
o org.openqa.selenium.By.ByPartialLinkText (implements java.io.Serializable)
o org.openqa.selenium.By.ByTagName (implements java.io.Serializable)
o org.openqa.selenium.By.ByXPath (implements java.io.Serializable)
o org.openqa.selenium.Cookie (implements java.io.Serializable)
o org.openqa.selenium.Cookie.Builder
o org.openqa.selenium.DeviceRotation
o org.openqa.selenium.Dimension
o org.openqa.selenium.ImmutableCapabilities (implements java.io.Serializable)
o org.openqa.selenium.MutableCapabilities (implements java.io.Serializable)
o org.openqa.selenium.Point
o org.openqa.selenium.Proxy
o org.openqa.selenium.Rectangle
o java.lang.Throwable (implements java.io.Serializable)
o java.lang.Exception
o java.lang.RuntimeException
o org.openqa.selenium.WebDriverException
o org.openqa.selenium.ImeActivationFailedException
o org.openqa.selenium.ImeNotAvailableException
o org.openqa.selenium.InvalidArgumentException
o org.openqa.selenium.InvalidCookieDomainException
o org.openqa.selenium.InvalidElementStateException
o org.openqa.selenium.ElementNotInteractableException
o org.openqa.selenium.ElementClickInterceptedExce
ption
o org.openqa.selenium.ElementNotVisibleException
o org.openqa.selenium.ElementNotSelectableException
o org.openqa.selenium.JavascriptException
o org.openqa.selenium.NoSuchSessionException
o org.openqa.selenium.NotFoundException
o org.openqa.selenium.NoAlertPresentException
o org.openqa.selenium.NoSuchContextException
o org.openqa.selenium.NoSuchCookieException
o org.openqa.selenium.NoSuchElementException
o org.openqa.selenium.InvalidSelectorException
o org.openqa.selenium.NoSuchFrameException
o org.openqa.selenium.NoSuchWindowException
o org.openqa.selenium.ScriptTimeoutException
o org.openqa.selenium.SessionNotCreatedException
o org.openqa.selenium.StaleElementReferenceException
o org.openqa.selenium.TimeoutException
o org.openqa.selenium.UnableToSetCookieException
o org.openqa.selenium.UnhandledAlertException
o org.openqa.selenium.UnsupportedCommandException
Interface Hierarchy
o org.openqa.selenium.Alert
o org.openqa.selenium.Capabilities
o org.openqa.selenium.ContextAware
o org.openqa.selenium.HasCapabilities
o org.openqa.selenium.JavascriptExecutor
o org.openqa.selenium.OutputType<T>
o org.openqa.selenium.Rotatable
o org.openqa.selenium.SearchContext
o org.openqa.selenium.WebDriver
o org.openqa.selenium.WebElement (also extends org.openqa.selenium.TakesScreenshot)
o org.openqa.selenium.TakesScreenshot
o org.openqa.selenium.WebElement (also extends org.openqa.selenium.SearchContext)
o org.openqa.selenium.WebDriver.ImeHandler
o org.openqa.selenium.WebDriver.Navigation
o org.openqa.selenium.WebDriver.Options
o org.openqa.selenium.WebDriver.TargetLocator
o org.openqa.selenium.WebDriver.Timeouts
o org.openqa.selenium.WebDriver.Window
Enum Hierarchy
o java.lang.Object
o java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable)
o org.openqa.selenium.Proxy.ProxyType
o org.openqa.selenium.ScreenOrientation
o org.openqa.selenium.Platform
o org.openqa.selenium.Architecture
o org.openqa.selenium.Keys (implements java.lang.CharSequence)
o org.openqa.selenium.PageLoadStrategy
o org.openqa.selenium.UnexpectedAlertBehaviour
2. WebElement ele=driver.findElement(By.xpath(".//*[@id='month']"));
List<WebElement> x = ele.findElements(By.tagName("option"));
for(WebElement ele1 : x) {
String y=ele1.getAttribute("innerHTML");
System.out.println(y);
}
Testng Annotation:
1. It gives the ability to produce HTML Reports of execution
2. Annotations made testers life easy
3. Test cases can be Grouped & Prioritized more easily
4. Parallel testing is possible
5. Generates Logs
6. Data Parameterization is possible
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@BeforeMethod
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite
Below are the lists of attributes that we can pass to our Test method:
alwaysRun: This is used when we want to make sure a method always runs even if the
parameters on which the method depends, fails. If set to true, this test method
will always run. Eg: @Test(alwaysRun = true)
dependsOnGroups: It is the list of groups this method depends on. Eg: @Test (groups
= { “City” ,”State” })
priority: This command sets the priority of the test method. Lower priorities will
be scheduled first. Eg: @Test (priority =1)
Test Case Grouping:
Dependent Test:
@Test
public void OpenBrowser() {
System.out.println("This will execute first (Open Browser)");
}
}
}
} <test name="IETest">
driver.findElement(By.id("login")).click(); </suite>
}
@AfterClass public void afterTest() {
driver.quit();
}
}
Action Class:
Method Description
clickAndHold() Clicks (without releasing) at the current
mouse location.
contextClick() Performs a context-click at the current
mouse location.
doubleClick() Performs a double-click at the current mouse
location.
dragAndDrop(source, Performs click-and-hold at the location of
target) the source element, moves to the location of
the target element, then releases the mouse.
Parameters:
source- element to emulate button down at.
target- element to move to and release the
mouse at.
dragAndDropBy(source, x- Performs click-and-hold at the location of
offset, y-offset) the source element, moves by a given offset,
then releases the mouse.
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Parameters:
Robot Class:
//press enter
rb.keyPress(KeyEvent.VK_ENTER);
rb.keyRelease(KeyEvent.VK_ENTER);
It is the direct way to find the element, but the disadvantage of the absolute
XPath is that if there are any changes made in the path of the element then that
XPath gets failed.
The key characteristic of XPath is that it begins with the single forward slash(/)
,which means you can select the element from the root node.
=> html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]
/div/h4[1]/b
For Relative Xpath the path starts from the middle of the HTML DOM structure. It
st`arts with the double forward slash (//), which means it can search the element
anywhere at the webpage.
You can start from the middle of the HTML DOM structure and no need to write long
xpath.
//*[@class='featured-box']//*[text()='Testing']
Type of Xpath:
Contains():
Contains() is a method used in XPath expression. It is used when the value of any
attribute changes dynamically, for example, login information.
Xpath=//*[contains(@type,'sub')]
Xpath=//*[@type='submit' OR @name='btnReset']
Start-with function:
Start-with function finds the element whose attribute value changes on refresh or
any operation on the webpage. In this expression, match the starting text of the
attribute is used to find the element whose attribute changes dynamically. You can
also find the element whose attribute value is static (not changes).
Xpath=//label[starts-with(@id,'message')]
Text():
In this expression, with text function, we find the element with exact text match
as shown below. In our case, we find the element with text "UserID".
Xpath=//td[text()='UserID']
Xpath=//*[@type='text']//following::input[1]
Xpath=//*[text()='Enterprise Testing']//ancestor::div
Child : Selects all children elements of the current node (Java) as shown in
the below screen.
Xpath=//*[@id='java_technologies']/child::li
Preceding: Select all nodes that come before the current node
Xpath=//*[@type='submit']//preceding::input
xpath=//*[@type='submit']//following-sibling::input
Xpath=//*[@id='rt-feature']//parent::div
Self: Selects the current node or 'self' means it indicates the node itself
Xpath =//*[@type='password']//self::input
Xpath=//*[@id='rt-feature']//descendant::a[1]
Selenium Grid
Selenium Grid is a part of the Selenium Suite that specializes in running multiple tests
across different browsers, operating systems, and machines in parallel.
There are two main elements to Selenium Grid — a hub, and nodes.
Hub
the hub is a computer which is the central point where we can load our tests into. Hub
also acts as a server because of which it acts as a central point to control the network
of Test machines. The Selenium Grid has only one hub and it is the master of the network.
When a test with given DesiredCapabilities is given to Hub, the Hub searches for the node
witch matches the given configuration.
Node
a node is referred to a Test Machine which opts to connect with the Hub. This test
machine will be used by Hub to run tests on. A Grid network can have multiple nodes. A
node is supposed to have different platforms i.e. different operating system and
browsers. The node does not need the same platform for running as that of hub.
Open the command prompt and navigate to a folder where the server is located. Run the
server by using below command
The hub will use the port 4444 by default. This port can be changed by passing the
different port number in command prompt provided the port is open and has not been
assigned a task.
Go to the other machine where you intend to setup Nodes. Open the command prompt and run
the below line.
For Instance, if you want to use only IE you can start the node by using below command
For Chrome:
There are few scenarios where you may need the browser from each type i.e.: IE, Chrome
and Firefox.
For instance, you may need to use 1 IE and 1 Firefox and 1 Chrome browser
maxSession
maxSession is used to configure how many numbers of browsers can be used parallel in the
remote system.
java -jar selenium-server-standalone-2.41.0.jar -role webdriver -hub
http://localhost:4444/grid/register -port 5556 -browser browserName=chrome,maxInstance=3
-browser browserName=firefox,maxInstance=3 –maxSession 3
Similarly, you can start multiple nodes and configuration can be verified in the console.
Here I have taken sample test to login to Gmail and enter username and password
As in the example, you have to use RemoteWebDriver if you are using GRID and you have to
provide capabilities to the browser. You have to set the browser and platform as above.
In this example, I have used the platform as WINDOWS. You can use any platform as per
your requirement.
Version of browser can also be set by using dr.setVersion(“version”)
For Instance, you need to run this test serially in multiple browsers you have to
configure your testng.xml.Below is the testng.XML suite for above test to run your test
serially.
Here in the testng.XML you have to specify the parameter as parllel=“tests” and thread-
count=“3” describes the maximum number of threads to be executed in parallel.
Framework:
Repository
(GitHub) Launch
Launch
Script Automation Scripts
Script
Test
Management
Tool
(JIRA)
Reporting
Test Data Test
Object
(Excel, Controllers
(Excel, Management
emails,
Database (Elements
(POM) Database,
, .csv) Path)
Testng)
AUT