Where we learn technology

Category: Uncategorised (Page 5 of 7)

Mystery of StaleElementReferenceException in Selenium WebDriver

Mystery of StaleElementReferenceException in Selenium WebDriver


If you are a Selenium developer than you would have surely faced this mysterious exception called “StaleElementReferenceException

Why exactly it occurs? This has been my favorite interview question since last many years and most of the time candidates gets confused it with NoSuchElementException. In case you have never worked on a dynamic ajax based application then there could be a chance that you have never faced it.
Let’s go little deeper and unveils the mystery behind it. When we run a simple code like this:
WebElement searchBox = driver.findElement(By.cssSelector("input[name='q'"));
searchBox.sendKeys("Selenium");
When WebDriver executes the above code then it assigns an internal id (refer the below image) to every web element and it refers this id to interact with that element.
Example image
Now, let’s assume when you have fetched the element and before doing any action on it, something got refreshed on your page. It could be the entire page refresh or some internal ajax call which has refreshed a section of the dom where your element falls. In this scenario the internal id which webdriver was using has become stale, so now for every operation on this WebElement, we will get StaleElementReferenceException.
To overcome this problem, the only choice we have is to re-fetch the element from Dom and this time WebDriver will assign a different Id to this element.
So from the above example what we understood is that if we are working with an AJAX-heavy application where page’s dom can get changed on every interaction then it is wise to fetch the web elements every time when we are operating on them. There are couple of ways to make sure, the element always gets refreshed before we use it:

Page Factory Design Pattern:

Please refer the below code.
GoogleSearchPage page = PageFactory.initElements(driver,GoogleSearchPage.class);
public class GoogleSearchPage {
@FindBy(how = How.NAME, using = "q")
private WebElement searchBox;

public void searchFor(String text) {
searchBox.sendKeys(text);
}
In the above example, a proxy would be configured for every Web Element when the page gets initialised. Every time we use a WebElement it will go and find it again so we shouldn’t see StaleElementException. This approach would solve your stale element problem at most of the places except some corner cases which I will cover in the next approach.

Refreshing the Element whenever it gets stale:

When you work on a modern, reactive, real-time application developed in technologies like Angularjs/Reactjs which has hell lot of data and there is a persistent web-socket connection which keep pushing data to your browser and which makes your dom to change. Let’s take an example of a stock exchange where there a data grid which displays real-time information and data keeps changing too frequently. In this case, whenever the data gets changed at server-side, the changes will be pushed automatically to your UI grid and depending on your data your respective rows or cells will get stale.
Here, Page factory can not help as most of your grid elements are dynamic and you cannot configure their locators while initiliazing your page. Also if you have created your own data model to prase data, than it is difficult to configure Page Factory accross all your data model classes.
To deal with this problem I decided to develop a generic method to refresh the element in case it gets stale. To refresh an element, we first need to figure out its By locator but Selenium API has not exposed anything to re-construct the locator from an existing web element. I was fortunate that they have exposed a toString method on WebElement which print all the locators being used to build that element. Let’s see the below example where we are finding an element which is a child of another element:
WebElement elem1 = driver.findElement(By.xpath("//div[@id='searchform']"));
WebElement elem2 = elem1.findElement(By.cssSelector("input[name='q'"));
System.out.println(elem2.toString());
Output of the above code would be:
[[[[ChromeDriver: chrome on XP (bd6a0d83229c67d5f7e6060b1bd768e9)] -> xpath: //div[@id='searchform']]] -> css selector: input[name='q']
Now we have to apply all the reverse-engineering to build the element again from this String. Thanks to Reflection API in Javawhich can help us to dynamically execute the code to build the element.
Here is the final implementation:
WebElement refreshedElement = StaleElementUtils.refreshElement(elem2);
This refreshElement method will check if the element is stale then it will re-fetch the element from the dom. So for all the data grid elements which can get stale anytime, we can use this method as a precautionary measure to avoid stale element exception.
Please feel free to share your thoughts on my approach and would love to know, how you have handled this interesting exception.
import com.sahajamit.selenium.driver.DriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class StaleElementUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(UIUtils.class);
public static WebElement refreshElement(WebElement elem){
if(!isElementStale(elem))
return elem;
Object lastObject = null;
try{
String[] arr = elem.toString().split(->);
List<String> newStr = new ArrayList<String>();
for(String s:arr){
String newstr = s.trim().replaceAll(^\[+, ).replaceAll(\]+$,);
String[] parts = newstr.split(: );
String key = parts[0];
String value = parts[1];
int leftBracketsCount = value.length() value.replace([, ).length();
int rightBracketscount = value.length() value.replace(], ).length();
if(leftBracketsCountrightBracketscount==1)
value = value + ];
if(lastObject==null){
lastObject = DriverManager.getDriver();
}else{
lastObject = getWebElement(lastObject, key, value);
}
}
}catch(Exception e){
LOGGER.error(Error in Refreshing the stale Element.);
}
return (WebElement)lastObject;
}
public static boolean isElementStale(WebElement e){
try{
e.isDisplayed();
return false;
}catch(StaleElementReferenceException ex){
return true;
}
}
private static WebElement getWebElement(Object lastObject, String key, String value){
WebElement element = null;
try {
By by = getBy(key,value);
Method m = getCaseInsensitiveDeclaredMethod(lastObject,findElement);
element = (WebElement) m.invoke(lastObject,by);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return element;
}
private static By getBy(String key, String value) throws InvocationTargetException, IllegalAccessException {
By by = null;
Class clazz = By.class;
String methodName = key.replace( ,);
Method m = getCaseInsensitiveStaticDeclaredMethod(clazz,methodName);
return (By) m.invoke(null,value);
}
private static Method getCaseInsensitiveDeclaredMethod(Object obj, String methodName) {
Method[] methods = obj.getClass().getMethods();
Method method = null;
for (Method m : methods) {
if (m.getName().equalsIgnoreCase(methodName)) {
method = m;
break;
}
}
if (method == null) {
throw new IllegalStateException(String.format(%s Method name is not found for this Class %s, methodName, obj.getClass().toString()));
}
return method;
}
private static Method getCaseInsensitiveStaticDeclaredMethod(Class clazz, String methodName) {
Method[] methods = clazz.getMethods();
Method method = null;
for (Method m : methods) {
if (m.getName().equalsIgnoreCase(methodName)) {
method = m;
break;
}
}
if (method == null) {
throw new IllegalStateException(String.format(%s Method name is not found for this Class %s, methodName, clazz.toString()));
}
return method;
}
}

WHY SHOULD WE USE JMETER FOR PERFORMANCE TESTING

WHY SHOULD WE USE JMETER FOR PERFORMANCE TESTING

JMeter is one of the most popular, open source performance testing tools among the software testing professionals around the world. There are number of reasons for JMeter to be popular. We shall share some of the reasons in this post.

Scripting knowledge is not required to build test plans

Test scripting is not essential to build performance testing test plans. Test plans can be built by adding and configuring  available components in JMeter IDE. This allows beginners to create effective performance test plans without any scripting.
Learning or mastering a tool is not sufficient for a successful performance testing projects. Good understanding of the context, test planning, test design, test execution and test reporting is essential for a successful performance testing project.

JMeter supports multiple scripting languages 

JMeter do support the scripting. Advance users can use the scripting (example Java, Groovy, BeanShell scripting) to extend the ability of JMeter.
JMeter support number of scripting languages out of the box. It can support JSR223-compatible languages not configured with default settings. There are other languages supported than those that appear in the component drop-down list. Others may be available if the appropriate jar is installed in the JMeter lib directory

JMeter is free and open source

JMeter is an Apache project. The source is available to the community. JMeter source code can be modified and built for specific needs if required.

It can run on any platform 

JMeter is developed using Java. Java applications can run on any platforms. Hence JMeter can be used on Windows, Mac , Linux or any other operating system when compatible JVM is available. 

Free support 

There is a huge community around the tool. There are active user groups in LinkedIN, Facebook , StackOverflow etc. Questions are answered within acceptable time period. The users can rely on the community for support questions.
There are organizations who provides commercial support too. 

Customized reports can be generated 

Reporting is one of the poor feature available in open source tools as compared to the commercial tools. Fortunately JMeter supports various reporting formats through available listeners and plugins. Also the test results can be upload to external reporting tools and generate commercial grade elegant reports.
There are number of listeners available out of the box for saving the test results. Test results can be loaded into the listeners to view the test results later too. 
The test results can be loaded into third party tools (example blazemeter ) and generate the test reports.
There are number of plugins available for reporting.

Real world workloads can be simulated

It is possible to simulate various workloads using ThreadGroups, timers ,Logical controllers and config elements. Different users’ dynamic thinking timing can be simulated using wide range of available timers and third party plugins 
User concurrency ,number of virtual users can be simulated using thread groups.
Throughputs ,

JMeter supports many protocols

Jmeter supports not only the web applications.  It supports wide range of applications, protocols and servers. Here is the list extracted from the official site.
  • Web – HTTP, HTTPS (Java, NodeJS, PHP, ASP.NET, …)
  • SOAP / REST Webservices
  • FTP
  • Database via JDBC
  • LDAP
  • Message-oriented middleware (MOM) via JMS
  • Mail – SMTP(S), POP3(S) and IMAP(S)
  • Native commands or shell scripts
  • TCP
  • Java Objects

Easy to create the test plans

Test plans creation can be started with recording feature available with JMeter. Also BabBoy software can be used for exporting the recorded flows into JMeter test plans. Some commercial tools based on Jmeter can be used for creating the JMeter scripts easily. Fore example Blazemeter’s Chrome plugin.

Distributed Testing 

JMeter can be used for simulating large number of users accessing the system concurrently or simultaneously. Virtual users will have to be distributed among few load agent as one machine may not be able to create all required threads (virtual users)

Mobile application testing is supported 

JMeter can be used for recording the requests sent from the device to the servers through its proxy configuration. Hence JMeter can be used to record the requests from mobile applications and web applications running on Android and iOS devices.

Comprehensive documentation 

JMeter has comprehensive documentation available online. It covers from installation, configuration, creating basic test plans , components reference, best practices , extending JMeter and much more. 
Component references, function references etc can be accessed readily from context menu, shortcuts or menu. A copy of user manual and api documentation is shipped with the installation and available for offline access.

User friendly IDE 

JMeter GUI is very user friendly. Components can be added by just right clicking a node in the test plan. Components can be configured easily by filling the placeholders (input boxes ). 
GUI can be customized further for user need by configuring the properties ( in bin/JMeter.properties file). For example toolbar  display, look and feel, proffered GUI language can be customized by updating the respective properties in the property file.

Free learning material

A beginner can start with JMeter through self 
There are good collection of free online documentation , blogs , Q&As and videos available. There are paid online and public training programs available around the world.

Third party plugins

JMeter capabilities can be extended through pluggable components (samplers , timers , listeners etc). Free custom JMeter plugins can be accessed from https://jmeter-plugins.org/. The plugins can be managed (install, uninstall) easily through the plugin manager interface.
User has access for commercial plugins covering custom features. For example UBIK Load Pack Plugins. https://ubikloadpack.com/. UBIK also do custom JMeter plugin development on demand too. 

Highly customizable

Test Cases – Game Testing – By Naveen AutomationLabs

Test Cases – Game Testing



Mobile Game Testing
Check for background music
and sound effects
ON/OFF sound & background music
Receive the call and check
Verify if sound effects are in sync with action
ON/OFF device sound(native sound) and check
Check for vibration effect if present
User Interface Check in Landscape/Portrait mode
Check for animation, movement of character, graphics, Zoom In/Out (all gestures) etc
There should not be any clipping (cutted background)
Test whether one object overlaps with another
Verify if loading indicator is displayed wherever required
Character should not move out of the screen/specified area
Test for enable and disable images/icons/buttons etc
Check for screen title
Check for message title, message description, label (should be appropriate)
Check scrolling
Font displayed (color, size etc)
Check other objects too (ex -if its a car race- you need to look at road, people, other objects like buildings etc)
Performance Check the loading time of a game
Make sure that any action is not taking considerable time, game flow should be fast
Score score calculation
Verify leaderboards General/All time/Weekly/local etc
Check the score registration functionality
Check the format (whether, comma is required in score etc ideally if customer is a foriegner coma should be in millions not in thousands )
Check for level completion syncs with the score
Time Out Check for time out
Do the actions when time-out yet to happen
Multitasking Switch b/w different apps and play game , check for sound, score, UI, time-out etc
Pause Check if game is paused when call received or multitasking or sleep mode
Save Settings Turnoff and ON device, check if settings are saved
Log out /On , check same
User should not loose his game in above conditions
User profile Put a all types of images in Player profile and check
Put special character, numbers,space in username and check
Password should be in masked
Chat feature Check the profile images
max limit of chat description
Enter empty string, special character and check
For a opponent , there should be a notification that he has received a message
Functionality Check game area, game logic
play till last level
get the cheat codes from development team and check all the levels
Check for the features that will be unlocked level-wise
Check for bonus score
Check the score hike when level gets increased
Check for multi-tap action (example in a car race we hold accelerator and left/right turn button simultaneously)
Menu options
Different game modes/location
Help & About Screen Should be in easily understandable format
free from spelling mistakes
URL should be hyperlinked (depends)
Multiplayer game Session expiry check
login/log out
Registration (Sign Up)
Verify account (receive verification mail)
login with registered but not verified account (without clicking verification link)
Forgot password checks (many cases here)
Game flow
Check for WIN/lost/Draw
Check user statistics graph
Challenge/Decline challenge/receive challenge
Check for forfeit
Check when player 2’s turn is on Player 1 is not able to do actions (should not be able to forfeit also)
Check for pass turn
Check for time-out (for one player)
Check the score for both the players till game ends
Memory leak Check the game when device memory is low
Network (n/w) check N/w messages if n/w is not present
check if what happens when n/w not present and user plays a move (whether score submitted for that move etc)
Check for localization Should be Support of different languages
Check for time format Change the device time , format etc
Size User wont like if your game takes lot of device space, so keep one eye on game file size
Device , OS Check in supported screen sizes and os versions (basicaly depend upon Client requirement)
Depends on platform Sometime we need to check as per OS guidliness as well. For ex in Wp7 we need to check in 2 background (light/dark).
Check Share options Post score via mail/FB/Twitter
Check the posted/sent messages in FB/Twitter/Mail. Check links are hyperlinked and application icon is displayed in
the post (depends)
If twitter integration is a manual ( custom UI developed by developer), check what happens when u enter more than
140 chars (as twitter limit is 140)
Music playing during app
launche
If music player running and we start installing any game app, music player should pauses without prompting for the user permission.
Steps for checking this:
1. Play a music file.
2. Launch the application.
3. Verify that while the application loads, it does not pause, resume or stop the actively playing music.
Interuption If app(game) is in running mode, then Check the behaviour of interuption like like Bluetooth, Infra red and CALL/SMS/MMS.
Upgrade the game
/ Battery effect
Upgrade of Games to the latest version and while migration all data should persist [ score, user profile etc ]
What if Battery goes down/switched of the cell while playing, Wheter the score wil get saved?

Web Services – API Automation Tutorials

Web Services – API Automation Tutorials

Hello Guys,
~~I’m launching my first video web series on Web Services – API automation on Vimeo. These videos are totally based on API – WS automation using HTTP Client and Rest Assured with framework designing step by step.

~~Interested people can buy these video directly on Vimeo. You will get life time access on these videos and will get full access on all upcoming videos at free of cost. Here is the link:


Course Content: 1. Manual Testing of WebServices/API: Introduction of API and WebServices: What is API What is WebService What is Backend Architecture Rest vs SOAP APIs What is CRUD operation What are different HTTP Calls – GET/POST/PUT/Delete Different Live Projects Examples 2. Postman: Introduction How to call Rest API in Postman How to pass path parameter in Request How to pass query parameter in Request How to set Headers in Postman How to pass JSON/XML Payload How to check response status code How to check JSON/XML response message What is response header 3. Rest Client and Advance Rest Client: Introduction How to hit REST APIs in Rest Client Basic and Advanced Settings in Rest Client How to check APIs at the network layer using developer tools of browser: How to check Backend services – APIs running behind What is developer tool in Chrome How to check request/response of any API in Firefox/Chrome browsers 4. What are different HTTP Status Response Codes: 100 series 200 series 300 series 400 series 500 series 5. Automation Testing of Back End Services: Learn HTTP Client: All CRUD – GET/POST/PUT/Delete Calls How to send Request with Payloads What is JSON Payload How to validate JSON response using JSON Parsers Common Utilities 6. Learn Rest Assured API in Java: Introduction Rest Assured methods: GET/POST/PUT/Delete BDD Framework in Rest Assured 7. API functional Testing using Jmeter Tool (only functional part) 8. API functional Testing using SOAP UI Tool 9. Maven: Build Automation Tool 10. TestNG (TDD) Framework for API automation 11. Cucumber (BDD) Framework for API automation 12. How to run API automation using Jenkins – CI tool (Continuous Integration) 13. Interview Questions: How to crack Product Companies interviews 14. Life Time Free Access on all Videos/Recordings

https://vimeo.com/ondemand/webservicesapiautomation

Cheers! Naveen AutomationLabs

How Much Java you need to learn for a good Selenium Scripting ?

How Much Java you need to learn for a good Selenium Scripting ?



As far as Selenium is concerned we have our SeleniumHQ Site with frequently updated documentation we can go through that to get the selenium concepts much strong also there are many blogs on selenium wherein you can get to learn from the basics even this blog is one among that, when considering the Language based client drivers if you use Java then here are some Java topics that you need to know for a better understanding and good selenium scripting.
    OOP’s concept – Class, Objects Polymorphism, Inheritance and Encapsulation
    Java Programming essentials– Object Instances, method overloading/overriding concepts and packages
    Control Statements – While, do-While, Switch, If statements – This will help us in writing the scripts for a multiple scenario statements and decision making scenarios.
    Looping statements – This will help us in scenarios like, iterating through a large table to find a record that you want and Running the same test for multiple number of times.
    Arrays Concepts – This will help us in having some set of datas of same type in a static way.
    Threads and MultiThreading Concepts – This will help us in making run our scripts in different threads that will help us in achieving better performance.
    Java Collections Framework – ArrayLists and HashMaps – This will help us in maintaining a collection of data’s. Particularly useful for scenarios where you need to compare the data from Web app UI with the DB. [OR] From UI to another UI
    File Streams – This will be helpful in externalization of data through CSV, Excel or Java Properties file.
    The above mentioned topics in java is will make you a pretty good selenium coder :). I will try to cover all these concepts with some real time examples. Until then please go through the Java concepts, there are many java tutorials on my YouTube channel:
    Cheers!
    Naveen AutomationLabs

    Why world is moving towards open source automation tools


    Why world is moving towards open source automation tools

    Testunity
    • Cost effective but matured solution: As the market growth has pushed up the overall expense for testing tools,
    •  it is directing IT organizations towards less expensive open source testing tools which offer the same 
    • functionality. With low licensing costs and fairly minimal hardware requirements, organizations get 
    • the extra benefit of flexible pricing plans as per the use of specific cloud storage.
    • Flexibility as per business strategy: As the open source tool can be altered as per particular requirement 
    • it reduces dependencies, unlike traditional tools. For example in Jira, the tester may include specific java 
    • code for some test scenarios. This promotes faster time around time of testing and resulting quick promote 
    • of the deliverables.
    • Open source community support and collaboration: It is easier to seek guidance and help from open
    •  source community. It is a centralized collaboration across the globe with the specific strategy and attention
    •  to contribute to the community.
    • Fast and frequent testing: As the automated test cases are short, those run faster and frequently as 
    • programmed by the testers. Hence, it is a very effective solution to find the bugs when you are testing 
    • your software in an agile environment with changing requirements. You can continuously add new test cases 
    • over the time to existing automation while development is on the go.
    • The paradigm shift: The software industry is facing the continuous threat of recession which ultimately 
    • has tightened the organizational budget. As open source tools are easy to learn and even a programmer 
    • can also work as a tester, organizations are stressing on their existing resources to learn it rather than 
    • hiring traditional testers.
    • Enable Agile testing: The traditional model of testing lifecycle follows “V” model. However, organizations 
    • now have recognized promising success by using open source tools in the Agile development environment. 
    • These tools significantly help in enabling early unit tests and also integration mechanisms which are very 
    • effective for time-sensitive Agile projects.
    • Freedom with greater security: Using open source automation tools frees organizations from vendor-specific 
    • restrictions like their availability for support, usage rules and much more. With open source tools, 
    • the user can make the decisions themselves and have the freedom to enhance the overall execution 
    • speed of the testing process. Also, in terms of security, open-source software is definitely superior to 
    • traditional frameworks.
    • Leverage cross platform and cross language testing: One of the major criteria of your testing tool 
    • must be its cross-platform and cross-browser support as  today’s applications are mostly run on mobile 
    • devices. Open source tools like Selenium, Appeium supports these features covering any kind of mobile 
    • app whether it is native, web-based or hybrid.





    In today’s fast-moving demanding world, it is a challenge for any software company to sustain 
    at the same performance level with constant quality and efficiency. The major challenges here 
    are time and cost and of course market competitors. Hence to sustain your business, whether 
    it is a product or service, quality delivery with optimized cost is the only solution. Otherwise,
     it leads you to customer dissatisfaction, and ultimately you will end up with bad market 
    reputation. And when you are in the software business, testing is the key to assure the quality.

    Over the past decade, the software industry has witnessed the revolutionary change in 
    the software testing and QA domain with the boom of automation testing. As the automation 
    testing has the ability to hit the core bottleneck areas of traditional manual testing, like poor
    test strategy, delay in testing, enhanced cost due to wrong effort estimation etc, companies are 
    leaning towards it. Moreover, with the upcoming open source automation tools like Selenium, 
    Appium, JUnit and much more, the trend is following this path with a rapid pace. 
    Even most of the renowned software companies are enforcing their employees to learn these tools.

    A number of industry-standard open source automation testing tools is now available 
    to fit with different stages of the testing process, from unit testing to complex user testing. 
    Open source tools have become an integral part of the IT spectrum in nearly every area of 
    software testing domain. Here is a bar chart for a rough overview of these tools in terms of 
    trending popularity across the globe –
    Mostly used open-source automation tool

    Mostly used open-source automation tool
    Advantages those drive business to select Open Source Automation tools 
    A real-time case study of an entertainment site by a market leading software company shows 
    how open source testing accelerated testing:
    Real-time example of automation

    Real-time example of automation
    Conclusion
    Although open source tools can drive significant quality and predictability in the testing life cycle,
    proper approaches must be taken care before using it. Every app is different, hence proper feasibility 
    study and pilot implementation are required before stepping into a live experiment. In some cases, 
    open source and commercial testing tools are blended together to get the overall better outcome and testing reliability.

    Locator Strategies in Selenium WebDriver

    Locator Strategies in Selenium WebDriver

    Introduction

    Now a days Selenium is vastly used as web automation tool across industry. It has its own advantages whether it might be an open source tool or freedom of scripting language. Selenium WebDriver mimics the actual user operations, so it gives the actual user experience while execution.
    Selenium have wide range of locators which helps to locate elements on a web page.
    Today we will talk about them.

    Selenium Locators

    Selenium gives user options to locate elements in 9 different ways.
    • Id
    • Name
    • Linktext
    • Partial Linktext
    • Tag Name
    • Class Name
    • CSS (Cascaded Spread Sheets)
    • XPath (XML path)
    • DOM (Data object modeling) (Not supported by WebDriver)
    The sequence of the operator shows how much your script is going to be efficient while execution. To elaborate this lets take one example.
    We will try to locate field User ID by Id and XPath.
    5
    Locator by id : Id= txtUserName Locator by xpath : XPath= //input[@id=’txtUserName’]
    (xpath might have different combination we will see them in xpath section.)
    If we execute script using both locators, to locate the field using Id will take less time compared to Xpath. In this way we will able to increase the efficiency of script by reducing execution time.
    Now we will see all locators in detail.

    Selenium Locators: Locate element by Id

    The most preferred, the easiest and efficient way to locate an element on a web page is By ID. Id will the attribute on the page which will be unique like you bank account number or employee id. Ids are the safest and fastest locator option and should always be the first choice even when there are multiple choices.
     Example 1:  <input id="txtUserName" type="text">
     Example 2:  <input id="txtUserName" name="userName" type="text">
    In first example its straight forward we only have Id, but in second we have Id as well as Name as an attribute. We can write the script as
     WebElement Ele = driver.findElement(By.id("txtUserName "));
    But in many cases we found that we have common Id or dynamic Ids (like in case of google, Gmail or the application using GWT). In that case we need to use different locators.

    Selenium Locators: Locate element by Name

    This is a fall back option when Id for element is not present. But mostly the names are used again and again, so make sure that the name is unique on the page before using it.
    Example:
    <input id="txtUserName" name="userName" type="text">
    WebElement ele= driver.findElement(By.name("userName "));

    Selenium Locators: Locate element by LinkText

    Finding an element with link text is very simple. This locator is used in case you want to locate any hyperlink only. But make sure, there is only one unique link on the web page. If there are multiple links with the same link, in such cases Selenium will perform action on the first matching element with link on page.
    Example:
    2
    In above image we have three hyperlinks. If we want to locate the Forgot Password? Link. The locator will be
    <a href="#">Forgot Password? </a>
    WebElement hyperlink = driver.findElement(By.linkText("Forgot Password?"));
    We have 2 links with text Forgot Email. If we try to locate 2nd link with locator
    LinkText=*Forgot Email. Selenium will locate 1st link.
    3
    In this case if we want to locate the 2nd link, we will need to use exact keyword with colon (exact:). The locator in that case will be
    linkText= exact:*Forgot Email
    <a style="background-color: transparent;" href="#">*Forgot Email</a>
    WebElement hyperlink = driver.findElement(By.linkText("exact:*Forgot Email"));
    4

    Selenium Locators: Locate element by Partial LinkText

    Partial LinkText works same as LinkText, only difference is you can use a part of the text from link.
    Example:
    <a href="#">Forgot Password? </a>
    WebElement hyperlink = driver.findElement(By. PartialLinkText ("Password"));

    Selenium Locators: Locate element by Tag Name

    Tag Name we can use for the elements like drop downs, check boxed, radio buttons. Following html is for drop down with 3 values. To select that drop down we will use tagName locator.
    Example:
    <select name="selCity" id="selCity">
    <option value="none">--Select--</option>
    <option value="PUNE">Pune</option>
    <option value="ADI">Ahmedabad</option>
    </select>
    WebDriver command:
    Select select = new Select(driver.findElement(By.tagName("select")));
    select.selectByVisibleText("Pune");
    or
    select.selectByValue("PUNE");

    Selenium Locators: Locate element by Class Name

    This locator we can use as a fall back option for either name or Id. But the same condition applied here Class name should be unique or selenium will locate the first element present on the page with the class name we have used to locate element.
    Example:
    <input id="txtName" class="textboxcss" tabindex="1" type="text">
    WebElement classtest =driver.findElement(By.className(“textboxcss”));

    Selenium Locators: Locate element by CSS selector using html tag attributes

    This a fall back when all options fail, you can use parent child relation in tags, in case you need to use complex strategy to locate elements. CSS selectors are string representation of HTML tags, attributes, Id, Class. It’s somewhat complex strategy compared to the previous we seen. But we can locate the elements which don’t have even Id or name or class using CSS selectors.
    We can use different combinations of attributes to locate an element using CSS selector.
    • Tag and ID
    • Tag and class
    • Tag and attribute
    • Tag, Id and attribute
    • Tag, class, and attribute
    • nth-child()
    • Inner text (Not supported by WebDriver)
    These are commonly used combinations, for more combinations you can refer this
    URL: http://www.w3schools.com/cssref/css_selectors.asp
    But you need to check first that the combination you are going to use is supported by Selenium WebDriver.

    Tag and ID

    In this case you need to follow this syntax css=tag#id. For Id we need to use sign before id value.
    Example:
    <input id="txtName" class="textboxcss" tabindex="1" type="text">
    css=input#txtName
    WebElement cssele = driver.findElements(By.cssSelector("input#txtName"));
    Here input is tag name and Id is txtName with # sign.

    Tag and Class

    In this case you need to follow this syntax css=tag.classname. For class we need to use dotbefore class value. If there is space between classname like classname you need to use dot in between space.
    Example 1:
    <input id="txtName" class="textboxcss" tabindex="1" type="text">
    css=input.textboxcss
    WebElement cssele = driver.findElements(By.cssSelector("input.textboxcss"));
    Example 2:
    <input id="txtName" class="textboxcss top" tabindex="1" type="text">
    css=input.textboxcss.top
    WebElement cssele = driver.findElements(By.cssSelector("input.textboxcss.top"));
    Here input is tag name followed by dot and class name textboxcss. In example 2 class name is
    textboxcss<space>top in that case we put dot in between textboxcss and top.

    Tag and Attribute

    In this case when we don’t have both Id or class name we go for html attributes given in tags.
    Syntax for this combination is css=tag[attribute=’value’]. We need to use square brackets to specify the attribute and its value. Put the value between single quotes when you are writing script in Java.
    Example:
    <input value="Reading" type="checkbox">
     css=input[type=’checkbox’]
    or
     css=input[value=’Reading’]
    Here in first case type is attribute and checkbox is its value, in other case value is an attribute and its value is Reading.

    Tag, ID and Attribute

    In this case when we have common id but other attributes are different, we go with this combination. Syntax for this combination is css=tag#id[attribute=’value’].
    Example:
    <input id="txtName" class="textboxcss" tabindex="1" name="taComment" type="text">
    <input id="txtName" class="textboxcss" tabindex="1" name="tbComment" type="text">
    css=input#txtName[name=’taComment’]
    WebElement cssele = driver.findElements(By.cssSelector("input#txtName[name=’taComment’]"));
    Here for both textboxes id is same ever class name is also same, only name is different for both. So if we want to locate first text box we will go with locator given in above example. For second text box we need to change value of name attribute in same combination.

    Tag, Class and Attribute

    In this case when we have id but we have class name which is common around other elements but other attributes are different, we go with this combination. Syntax for this combination is css=tag.classname[attribute=’value’].
    Example:
    <input class="textboxcss" tabindex="1" name="taComment" type="text">
    <input class="textboxcss" tabindex="1" name="tbComment" type="text">
    css=input.textboxcss [name=’taComment’]
    WebElement cssele = driver.findElements(By.cssSelector("input.textboxcss [name=’taComment’]"));

    nth-chilld()

    In this case we have same Id or class name and other attributes for different elements, we can go with nth-child().
    Syntax for this combination is css=tag:nth-child(n). Here in syntax we can use any combination discussed above. With that we need to use: nth-child(n). n represent child number.
    Example:
    <ul>
    <li>C</li>
    <li>C++</li>
    <li>C#</li>
    <li>Java</li>
    <li>Python</li>
    <li>Ruby</li>
    </ul>
     css= li:nth-child(n)
    WebElement cssele = driver.findElements(By.cssSelector("li:nth-child(n)"));
    Here if we can see the ul li parent child structure. We have only tag names which are common to everyone. Here if we want to locate sat Java we will put n=4 in above command.
    6

    Inner text

    This is right now not supported by WebDriver in case of CSS, but most probably will support in upcoming Selenium 3 or 4.
    Syntax: css= tag:contains(‘inner text’), Here in syntax we can use any combination discussed above. With that we need to use (:) contains(inner text).
    Example:
    <span>Upload you pic :</span>
      css= span:contains(‘Upload you pic ‘)
    WebElement cssele = driver.findElements(By.cssSelector("span:contains(‘Upload you pic‘)"));

    Absolute and Relative Path

    The Examples we have seen till now are related to only single tag and its attribute. But when we require to build path using parent child relation we need to give its either absolute or relative path.
    Example:
    <div>
    <ul>
    <li>C</li>
    <li>C++</li>
    <li>Python</li>
    </ul>
    </div>
    Consider here we want to locate Python using parent child relation. In that case relative path will be
    Relative path: css=div<space>ul<space>li:nth-child(3) or css=div<space>li:nth-child(3). In second combination we have removed ul. Space denotes it’s a Relative path. Here WebDriver will search 3rd li inside given div and ul.
    And if we want Absolute path for same, it will be
    Absolute path: css= div>ul >li:nth-child(3) or css=ul> li:nth-child(3). Here angular bracket denotes Absolute path. It’s an exact path for given element.
    To know the difference between both let’s consider the example.
    Someone asked you where is your office? Most common answer is Hinjewadi. But if a courier boy asked you the address you will tell full and exact address of your office. 1st one is relative path to your office but 2nd is absolute one.

    Security Testing Test Scenarios – By Naveen AutomationLabs

    Security Testing Test Scenarios – By Naveen AutomationLabs



    1. Check for SQL injection attacks

    2. Secure pages should use HTTPS protocol

    3. Page crash should not reveal application or server info. Error page should be displayed for this

    4. Escape special characters in input

    5. Error messages should not reveal any sensitive information

    6. All credentials should be transferred over an encrypted channel

    7. Test password security and password policy enforcement

    8. Check application logout functionality

    9. Check for Brute Force Attacks

    10. Cookie information should be stored in encrypted format only

    11. Check session cookie duration and session termination after timeout or logout

    11. Session tokens should be transmitted over secured channel

    13. Password should not be stored in cookies

    14. Test for Denial of Service attacks

    15. Test for memory leakage

    16. Test unauthorised application access by manipulating variable values in browser address bar

    17. Test file extension handing so that exe files are not uploaded and executed on server

    18. Sensitive fields like passwords and credit card information should not have auto complete 
    enabled

    19. File upload functionality should use file type restrictions and also anti-virus for scanning uploaded files

    20. Check if directory listing is prohibited

    21. Password and other sensitive fields should be masked while typing

    22. Check if forgot password functionality is secured with features like temporary password expiry after specified hours and security question is asked before changing or requesting new password

    23. Verify CAPTCHA functionality

    24. Check if important events are logged in log files

    25. Check if access privileges are implemented correctly



    ~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

    Follow me on my Facebook Page:

    Let’s join our Automation community for some amazing knowledge sharing and group discussion:

    Database Testing Test Cases – By Naveen AutomationLabs

    Database Testing Test Cases 


    1. Check if correct data is getting saved in database upon successful page submit

    2. Check values for columns which are not accepting null values

    3. Check for data integrity. Data should be stored in single or multiple tables based on design

    4. Index names should be given as per the standards e.g. IND_<Tablename>_<ColumnName>

    5. Tables should have primary key column

    6. Table columns should have description information available (except for audit columns like created date, created by etc.)

    7. For every database add/update operation log should be added

    8. Required table indexes should be created

    9. Check if data is committed to database only when the operation is successfully completed

    10. Data should be rolled back in case of failed transactions

    11. Database name should be given as per the application type i.e. test, UAT, sandbox, live (though this is not a standard it is helpful for database maintenance)

    12. Database logical names should be given according to database name (again this is not standard but helpful for DB maintenance)

    13. Stored procedures should not be named with prefix “sp_”

    14. Check is values for table audit columns (like createddate, createdby, updatedate, updatedby, isdeleted, deleteddate, deletedby etc.) are populated properly

    15. Check if input data is not truncated while saving. Field length shown to user on page and in database schema should be same

    16. Check numeric fields with minimum, maximum, and float values

    17. Check numeric fields with negative values (for both acceptance and non-acceptance)

    18. Check if radio button and dropdown list options are saved correctly in database

    19. Check if database fields are designed with correct data type and data length

    20. Check if all table constraints like Primary key, Foreign key etc. are implemented correctly

    21. Test stored procedures and triggers with sample input data

    22. Input field leading and trailing spaces should be truncated before committing data to database

    23. Null values should not be allowed for Primary key column



    ~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

    https://www.youtube.com/c/Naveen%20AutomationLabs?sub_confirmation=1

    Follow me on my Facebook Page:
    https://www.facebook.com/groups/naveenqtpexpert/

    Let’s join our Automation community for some amazing knowledge sharing and group discussion:

    https://t.me/joinchat/COJqZQ4enmEt4JACKLNLUg

    Selenium & Java Training – WeekEnd Batch

    Selenium & Java Training Course Content (WeekEnd Batch)


    Next Batch Starting from: 7th Jan, 2017

    Duration: 2 months

    Registration Fee: 3000 INR (60 USD)

    Location: Online

    Timings: 
    • 9:00 AM IST (Indian Time)
    • 10:30 PM EST (Eastern Time)
    • 7:30 PM PST (Pacific Time)

      Note:
      • There will be 2 demo sessions. If you don’t like the sessions or if you want to leave. Full Registration amount will be transferred back to you.

      • After 2 demo sessions, pending amount (13000 INR/290 USD) must be paid.

      Selenium WebDriver – 3 is a leading web automation testing tool in industry. It is one of the most popular tool. Selenium WebDriver jobs are on a rise and are highly paid and highly valued. Industry is shifting towards automation rapidly.
      Today, every start up, product based and service based companies need Automation QA Engineer to automate their web apps.
      With more and more applications becoming accessible through browser it becomes very important to learn Selenium WebDriver.
      This course is designed to teach in depth concepts of Selenium WebDriver 3 and Java. We focus on the basics first and then move towards the advance concepts of Selenium, Java and framework development.
      Part -1: Basics of Java & Selenium
      1) Automation : A brief introduction to automation and the need for automation. How automation will enable you to beat competition and make you get the better jobs in market.
      • What is Automation Testing
      • Use of automation Testing
      • Tools for Automation Testing
      • Why automation is important for you career?
      • What is Selenium
      • Advantage of Selenium
      • Introduction to IDE, RC WebDriver & Grid
      • Interview Questions
      2) Core Java/Programming : This class will set you up for understanding Basic OOPs and java concepts. These concepts will be extremely important for you to become a good Automation tester. This section is specially designed so that can be followed by any Manual test very easily.
      • Data Types and Variables
      • String Class
      • Arithmetic Operators & Concatenation operators
      • Conditional & Decision Making
      • Single Dimensional Array
      • Double Dimensional Array
      • Loops (For, While)
      • Classes and Objects
      • Class Constructors
      • Functions in Java 
      • Function Input Parameters 
      • Function Return Types
      • Inheritance
      • Polymorphism
      • Method Overloading
      • Method Overriding
      • Abstract class
      • Interface
      • Super/This Keywords
      • Final/Finally/Finalize Keywords
      • Wrapper Classes
      • String Manipulation
      • Collections Basics (Array List, HashMap, HashTable)
      • Interview Questions
      3) Eclipse IDE : This topic might seem little off place here but it’s very important topic to understand the tool you are using. Eclipse will the primary choice of development environment and we will discuss features of eclipse here.
      • How to use Eclipse
      • How to run, stop, pause
      • How to debug in Eclipse
      • Understanding console output
      • How to put a break point
      • How to add Watch variables
      • How to find errors from Problem window
      • Usage of step into and Step over debug functionality
      • Interview Questions
      4) Set up Eclipse : We will start with setting up WebDriver, so that every participant start flaunting off their newly learnt skills by writing some cool test programs:
      • Download and install java
      • Download and start Eclipse
      • Download and configure WebDriver java client
      • Set up a project
      • Create packages
      • Create a First Java test case
      • Import WebDriver Source file
      • Interview Questions
      5) WebDriver Interface : This topic will make you familiar with the concept of browsers in WebDriver and how to launch basic Firefox browser using WebDriver. Here we will also talk about WebDriver & WebElement interface which will enable us to answer many complicated Interview Questions about WebDriver Implementation.
      • Architecture of WebDriver
      • WebDriver Interface
      • WebElement Interface
      • Launching Firefox/Chrome/Safari
      • Interview Questions
      6) Browser & Navigation Commands : This is something which everybody do very first thing when they learn Selenium. Opening & closing of browser and some navigation function on top of it.
      • How to Open a URL
      • Verify Page title
      • Strategy to get the Page Source 
      • Difference between Close & Quit
      • Ways to Navigate Back & Forward
      • How to Refresh Page
      • Another way of Navigating to specific Page
      • Interview Questions
      7) WebElement Commands : An important and basic need of Selenium Automation. This part enables every participant to start writing automation test in their organizations. These are the most commonly used operations on any website.
      • Difference between FindElement & FindElements
      • Enter & Clear text from Input field
      • How Click action works differently on different elements
      • Managing Input fields, Buttons & Links
      • Finding all links on the Page
      • Strategy to check dead links on the page
      • Extracting More than one object from a page 
      • Extracting Objects from a specific area of a web page 
      • Check if element is Present, Displayed, Enabled or Selected
      • Interview Questions
      8) Locators : In this class we will start learning about HTML, how elements are defined inside HTML document and what are the different attributes that are associated with an HTML element. We also try to find elements based on its attribute values.
      • What are locators
      • HTML Basics
      • HTML language tags and attributes 
      • ID, Name, Xpath, CSS etc
      • Difference between Absolute & Complete Xpath
      • Finding your first element
      • WebElement Commands
      • Interview Questions
      9) Element Identification : This part explains the lifesaver Add-Ons & tools for Selenium. Finding elements are the most common activity carried out in Selenium. These tools give us power to easily identify complex elements and help us in saving lot of time.
       Element Inspector in Mozilla, Chrome and IE
      • Element locator tool for FF
      • FireBug & FirePath Add-Ons in Mozilla 
      • Various HTML locator strategies
      • XPath Helper Plug-in for Chrome
      • Selection of Effective XPath
      • Handling Dynamic objects/ids on the page
      • Interview Questions
      10) Tables, Checkboxes & Radio buttons : Many applications involve use of web tables and list boxes. These skills will help participant to get the expertise on complex tables structures and write effective automation test.
      • Identify table rows and columns
      • Extracting values from a cell
      • Dynamically Identify Tables Data
      • Select class in Selenium
      • Drop Down Handle
      • Select multiple values from the list
      • Select & Deselect operations by Index, Value & Visible Text
      • Interview Questions
      11) Selenium Waits, Alert & Switch Windows : A little complexity will start now onwards. To use Waits effective is very important for every automation tester. Wait helps us in switching windows, handling pop-ups, operating alerts correctly.
      • Implicit and Explicit waits
      • How to use Expected Conditions with Waits
      • PageLoadTimeout & SetScriptTimeout property
      • Simple use of Thread Sleep
      • Concept of Fluent Wait in Selenium 
      • Strategy to poll for an object
      • WebDriverWait and its uses 
      • Different WaitUntil Conditions 
      • Managing Ajax based components 
      • Ways to handle Simple, Confirmation & Prompt Alert
      • Concepts of Set Interface in Java 
      • Difference between Window Handle & Handles 
      • Switching & Closing Windows, Tabs & PopUps
      • Concept of window ID 
      • Extracting window IDs with Selenium Object reference
      • Interview Questions
      12) Action Class
      This gives us power on recently build Application with latest and complex object features. Hovering mouse or simulate Mouse and Keyword operations can be done by using Action Class. A necessary thing to learn in Selenium journey.
      • What is Action Class & What can we do with Action Class
      • Mouse Hover & Mouse Movement with Action
      • Finding Coordinates of a Web Object
      • Drag and Drop Action
      • Interview Questions
      13) Browser Profile: Different types of browser profiles and user authentication models with examples will be discussed in this class. You will need these to test secured websites and user authenticated websites.
      • What is Browser Profile
      • How to set up FireFox profile
      • Interview Questions
      Part -2: Advanced Selenium
      14) TestNG Framework
      TestNG is a wonderful off the shelf framework that can be used directly to create your test framework. We will learn about this framework here.
      • What is TestNG
      • Benefits and Features of TestNG
      • How to download TestNG
      • Annotations in TestNg
      • How to run Test Suite in TestNG
      • Groups in TestNG
      • Depend On in TestNG
      • Test Case sequencing in TestNG
      • TestNG Reporters
      • TestNG Assets
      • TestNG Parameters
      • Multi Browser testing in TestNG
      • Parallel testing in TestNG
      • Interview Questions
      15) Automation Framework
      This class will cover the concepts of Frameworks. After this the participant would got to know that which type of Framework works best for their Application and the pros & cons of the selected framework. Knowledge of frameworks is key skill to learn.
      • What is Automation Framework
      • Features of Automation Framework
      • Benefits of using Automation Framework
      • Different types of Automation Framework
      • What is Data Driven Framework
      • What is Hybrid Framework
      • What is Page Object Model Design Pattern
      • Interview Questions
      •  
      16) Real Time Live PROJECT – Selenium Hybrid Framework (POM)
      In this class we will explore some major frameworks by looking at the code and understanding the key component of the framework. A demo website will be taken and framework will be built on top of that which will simulate actual project scenario.
      • Introduction and Component of Frameworks
      • Designing Test Data Provider (Excel)
      • Designing Run Data Provider (Text/Property file) 
      • Setting up Maven Build Tool
      • Data Provider Factory Design
      • Creating Page Objects & Object repository
      • Writing Test Script and Fetching Test Data
      • Designing Test Runner for Framework
      • Asserts, Test Fails & Error logging
      • Reporters, TestNG Listeners and Log file Generation
      • Running test with different Test Data
      • Generating the HTML reports 
      • Emailing test reports 
      • Interview Questions


      17) Dev Ops & Continuous Integration
      • Jenkins Setup
      • Running Script via Jenkins
      • Report Generation using Extent Report
      • GIT Repo/GIT HUB
      • My First Code Check-in to GIT
      • Interview Questions
      18) Interview Preparation/Mock Interviews/Live Sessions
      19) Life Time Access on all YouTube Videos


      Cheers!
      Naveen AutomationLabs
      « Older posts Newer posts »