Uploaded by Vignesh Ramkumar

selenium Training

advertisement
Day 1:
New class name(); is an object and it will be created when we provide this.
When we call a method without providing instance of an object then everytime we have use new
command and it will call the constructor everytime.
What is a need of constructor?
Constructor is used to initialize the object. It creates an object in the memory and return a reference
to it.
String is a class
What is an object class?
Object as a Superclass. The Object class, in thejava.lang package, sits at the top of the class hierarchy
tree. Every class is a descendant, direct or indirect, of the Object class. Every class you use or write
inherits the instance methods of Object
Object class is extended in every class in JAVA
All objects in Java are stored on the heap. The "variables" that hold references to them can be on
the stack or they can be contained in other objects (then they are not really variables, but fields),
which puts them on the heap also. The Class objects that define Classes are also heap objects.
Right clicks the project -> export -> create a JAR file so that the classes and methods that you have
created can be used by the external world. They cannot edit the classes or methods. They can just
create mew objects and use the classes and methods in it. This JAR file will act as a API to the other
projects.
How to add external JAR files?
Right click the project -> Build Path -> Add External Archives
Nearly 80% of the applications are becoming web based after the cloud computing. Since the other
tools like QTP are license based and cost more. People are willing to use Selenium which will
automate all the web application similar to the other licensed tools.
Benefits
1. Multi Lang support (JAVA, C#, ruby, python, perl, php, JS) – Licensed tool like QTP uses
JAVASCRIPT which will be only working on windows. It will not work on Linux. SO we can use
QTP only in Windows machines.
2. Multi OS : Selenium is operation system independent ( Windows, Linux, MACOS)
3. Multi Browsers – IE, Firefox, Chrome, Opera, Safari
IDE, RC, Webdriver, Grid
IDE, RC- Selenium 1.0 (Grid 1)
Webdriver – Selenium 2.0 (Grid 2)
Challenges faced in RC:
IE is highly secured browser.
Selenium RC injects java scripts to run in a browser. If the browser does not accept java script
injection, then we cannot run selenium RC code in that browser.
By removing the security from the browser, we can run selenium RC scripts in IE browser.
But when we run any secured website, the browser will not launch the website at all as there
will be some valid certificates that needs to be verified.
Also the libraries is not more in RC
In webdriver, we have AndriodDriver and IphoneDriver which can be used to test the web
applications in the mobiles. We cannot test the native or hybrid applications using this drivers.
Grid – Parallel execution of test cases on multiple machines and browsers. – Compatiability
testing
What is selenium 3.0?
Documentation and W3 standards.
Appium, Selendriod and IOS driver – Used for Native application which may come in 3.0
Day 2:
Pre-requisties:
1.
2.
3.
4.
JDK
Eclipse
Selenium API
Firefox – Firepath and Firebug
When we start using framework, we will not be using main method
Architecture: the package/method will interact with the native method of the browser. So the
method in one package will not be used for other browsers.
For launching a browser, the code will be written in constructor.
Naming conventions for a package : The company name in reverse manner , Project name and
the package name
E.g. Company name is way2automation.com
Project is selenium and the module is register
Then the naming convention must be com.way2automation.selenium.register
Org.openqa.selenium.firefox
Org , openqa, selenium & firefox are folders in order to maintan the files properly.
1. About the standalone server jar files
2. About the system set property for the IE and Chrome browsers.
cannot get automation extension – This error will be caused when the
browser EXE is not updated.
Day 3:
All the locators are in the form of methods in the By Class
These methods are static methods
What are static and non-static?
Non-Static: Only when an object is created for a class, we can call non static methods
Static: Static method can be called without creating an object of the class also
E.g
Staticandnonstatic is a class which has static add method and non static sub method
In our Test class, we can use staticandnonstatic.add();
Why the password element is not locatable?
The field might not be enabled because of which it is displaying that the element cannot be found
There are n number wait elements in webdriver.
Thread.sleep is a JAVA utility method which can be used for wait option. But it will definitely put the
system to sleep/wait for the time that is mentioned. Even if the system is ready before the time
provided in the sleep, selenium will not perform the action.
Hard code WAIT is not recommended in webdriver. So we can use Implicit and Explicit WAIT.
Both Implicit and Explicit
Implicit : the time mentioned will be the maximum time that the webdriver will wait for until the
element appears.
e.g. driver.manage().timeouts().implicitlyWait(10L,TimeUnit.SECONDS);
Implicit WAIT will be applied only when the element is present on the page (if it not visible in the
page). If they are present in the HTML and not displayed in the UI then Implicit WAIT will not work.
EXPLICIT: When the visibility in UI is not present, then we can use EXPLICIT. This will be for a
particular element’s condition and not for the whole driver/code. We can provide various
conditions/Options for the elements.
e.g.
WebDriverWait wait = new WebDriverWait(driver, 10L);
Wait.until(ExpectedConditions.visibilityofElementLocated(By.xpath(Xpath expression)))
When to use Implicit and Explicit WAIT?
It completely depends on the elements. It comes only based on experience.
There are times when we type something, the element will be updated. E.g. when we type the first
three letters, it will display the place in many websites. In such case the whole page is not loaded. It
is only the list is loaded. Such kind of elements are called as AJAX elements.
There will be some java script/Jquery elements that loads on the client end.
There is no need for the page to validate from the server.
When we provide a wrong username/password, it checks the server, validates it and then throws a
error. (Page load happens)
Where ever the page load happens, the time is handled by the webdriver itself. Wait for page to load
is in-build in webdriver. No need to provide any wait.
When the element is loaded then we need to apply WAIT and when the whole page is loaded we DO
NOT need to apply WAIT.
Normally the actions like sendkeys, Click will be directly done using findelements method itself. They
will not assign it to a webelement and do it from there.
Why do we need to store the element in a webelement when we can directly perform the actions?
There are many things that cannot be done when we are not storing it in a webelement. In RC we
cannot store a webelement. Many actions was very difficult or limitation
Driver.close() will close the current browser window.
Driver.quit() will close the current browser + all related session windows
How to handle a drop down list?
Instead of driver.get() we can also use driver.navigate().to(URL)
The only difference in using the navigate. To function is instead of going directly to the webpage we
can go to the back page, refresh the page etc. there are other features available that can be usedin
navigate.to which is not available in driver.get
Select option:
WebElement dropdown = driver.findElement(by.xpath(“Xpath Expression”));
Select select = new Select(dropdown);
Select.selectByValue(“Values from the dropdown”);
qa.way2automation.com
Image validation is not allowed in Selenium. That can be done only via Java
Download