Posts

Showing posts with the label WebDriver Java Concepts

Google has implemented a headless option for Chrome

New Headless Chrome With Selenium WebDriver So if you hadn't heard, Google has implemented a headless option for Chrome. This will be included from version 59, however you can download it now and a play using the Canary install. So I did just that. Happy testing!

WebDriverManager - Solution to the selenium binaries

Image
What is WebDriverManager ? Problem:   In order to use some browsers (for example  Chrome , Internet Explorer ,  Opera ,  Microsoft Edge ,  PhantomJS , or  Marionette ) you need to download a binary which allows WebDriver to handle the browser. In addition, the absolute path to this binary must be set as Java variables, as follows: System . setProperty( " webdriver.chrome.driver " , " /absolute/path/to/binary/chromedriver " ); System . setProperty( " webdriver.opera.driver " , " /absolute/path/to/binary/operadriver " ); System . setProperty( " webdriver.ie.driver " , " C:/absolute/path/to/binary/IEDriverServer.exe " ); System . setProperty( " webdriver.edge.driver " , " C:/absolute/path/to/binary/MicrosoftWebDriver.exe " ); System . setProperty( " phantomjs.binary.path " , " /absolute/path/to/binary/phantomjs " ); System . setProperty( " webdriver.gecko.driver " , ...

Marionette ?

Image
Background: Mozilla has been working on a project called Marionette which will become a future version of FirefoxDriver. Official link -  https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette Read more here  http://www.theautomatedtester.co.uk/blog/2012/marionette-the-future-of-firefoxdriver-in-selenium.html Now called the GeckoDriver https://github.com/mozilla/geckodriver If you want to perform UI tests with browser chrome or content, Marionette is the tool you're looking for! Using Marionette with Webdriver -  https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver Future: Marionette will be turned on by default from Selenium 3 Ideally when Firefox 52 comes around you will just update to Selenium 3 Happy Testing!

slf4j failed to load class

Image
Problem:  If you are getting this error message every time you run your slf4j failed to load class framework org.slf4j.impl.staticloggerbinder Solution: If you use maven just add the following Happy Testing!

IntelliJ - Convert the Java project into a Maven project/module

Image
IntelliJ - Convert the  Java project into a Maven project/module: Right-click on the module, select "Add framework support...", and check the "Maven" technology. (This also creates a pom.xml for you to modify.) Maven repositories you need: http://mvnrepository.com/ Maven Information If you're using Maven, you will find all Selenium Maven artifacts directly in the central Maven repository here:  http://repo1.maven.org/maven2/org/seleniumhq/selenium/ In order to start using  DefaultSelenium  or one of the new  WebDriver  implementations in your Maven project, just add the following dependency to your  pom.xml : org.seleniumhq.selenium selenium-java 2.48.2 Note : 2.48.2 : The version at the time the post was written Source: http://www.seleniumhq.org/download/maven.jsp

POM file Maven Dependency Injection - CheatSheet

Image
When you depend on a plugin or a dependency, you can use the a version value of LATEST or RELEASE . LATEST refers to the latest released or snapshot version of a particular artifact, the most recently deployed artifact in a particular repository.  RELEASE refers to the last non-snapshot release in the repository. A square bracket ( [ & ] ) means "closed" (inclusive).  A parenthesis ( ( & ) ) means "open" (exclusive). Best Practice: In general, it is not a best practice to design software which depends on a non-specific version of an artifact. If you are developing software, you might want to use RELEASE or LATEST as a convenience so that you don't have to update version numbers when a new release of a third-party library is released. When you release software, you should always make sure that your project depends on specific versions to reduce the chances of your build or your project being affected by a software release not under your cont...

TestNg v/s JUnit Annotations

Image

Copy Maven dependencies to lib folder

Image
Problem : How can I copy all maven dependencies to a target folder say lib sometimes all you want is to copy all dependencies (jars) to a destination-folder. The Maven Dependency Plug-In  will kindly assist you to copy maven dependencies to a target folder. Include the following plugin in your pom file: org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies ${project.build.directory}/alternateLocation false false true From command prompt run : mvn dependency:copy-dependencies You will now have a target folder with all your jars!

"GC overhead limit exceeded" Eclipse

Image
"GC overhead limit exceeded" is what you see when you are trying to import a new project or when Eclipse just runs out of memory! Solution: Allocate more memory to your Eclipse instance.  How?: Locate the eclipse.ini file in your Eclipse's installation directory. The content would be something similar to the following: Change these: Restart your eclipse :)

Parameterize properties file in Java

Image
If you are using a properties file and passing key value pairs, there are instances when you would want to parameterize the values passed. In my case the dynamic xpaths need to be parameteized for more flexibility Solution:  MessageFormat Steps to achieve this : Your properties file should have the key value as : HomePage.DynamicObject.Button=//*[@text= ''{0}'' and @width>0]  In the above statement {0} is the parameter  In your class file that calls the property Properties obprop = new Properties(); String Locator= MessageFormat.format(obprop.getProperty(Object_Identifier), params); where Object_Identifier is HomePage.DynamicObject.Button and params is the parameter you want to pass Note:   Within a String, a pair of single quotes can be used to quote any arbitrary characters except single quotes. For example, pattern string "'{0}'" represents string "{0}", not a FormatElement. ... Any unmatched quote is tr...

Eclipse Referenced Libraries disappear

Image
Automating using Java Eclipse?  Problem:   In Java projects in Eclipse sometimes the folder "Referenced Libraries" disappears from the "Project Explorer" view. All third party jars are shown directly in the root of the project folder Solution 1:   B ring up the "Package Explorer" view (instead of the "Project Explorer" view). Solution 2:   C lick on the little "down arrow" icon in the top-right corner of the Package Explorer view. In the context menu that appears, one of the items on the menu is "Show 'Referenced Libraries' Node." Click on that menu item.

Performance testing with Selenium Webdriver - Navigation Timing API

Image
In continuation to my previous post on performance testing with Selenium Webdriver , I found the " Navigation Timing API " the best way as it has loads of parameters that we can slice and dice the way we want to get different performance parameters like: "Total Time:"+(loadEventEnd - navigationStart)/1000 + " seconds"+ " "Server Render Time: "+ (responseEnd - requestStart) + " milliseconds" "User Experience: "+ (domComplete - requestStart) + " milliseconds" "Network:"+ (connectEnd - navigationStart)/1000 + " seconds" "Server:"+ (responseEnd - requestStart)/1000 + " seconds" "Browser:"+ (loadEventEnd - domLoading)/1000 + " seconds" The properties you can play with are: The meaning of these events is described in Microsoft's performance.timing documentation  a nd more formally in the W3C Recommendation ...

Performance Testing using Selenium Webdriver

Image
Yes we know that Selenium Webdriver is a functional testing tool and is not a recommended option to do performance! But then there are times that you want to just do a quick performance check and find the bottlenecks in your application, here is how: The solutions here are organised based on the complexity and detail you want to achieve: Solution 1:   Measuring performance using a Timer in Selenium WebDriver We can use the the StopWatch class for measuring the time taken for the page to load or any inbuilt date time calendar feature: StopWatch pageLoad = new StopWatch(); pageLoad.start(); //Perform your test pageLoad.stop(); System.out.println("Total Page Load Time: " + pageLoad.getTime() + "milliseconds"); Or Calendar cal = Calendar.getInstance(); Date d1 = cal.getTime(); //Perform your test Calendar cal2 = Calendar.getInstance(); Date d2 = cal2.getTime(); long diff = d2.getTime() - d1.getTime(); long diffSeconds = diff / 1000 % 60; long di...

Appium - Mobile test automation on a real device

Image
If you are looking to perform test automation on a real device (iPhone in my case) and you have had problems with the documentation on the official Appium website , the following post will help you for sure: Prerequisites:  Apple account with valid apple ID  Download and Install Eclipse on your Mac – A link that might help you with the installation process http://www.cs.dartmouth.edu/~cs5/install/eclipse-osx/ Download and Install Xcode Download Selenium Jars for java from the Selenium website Download the java client libraries from http://appium.io/downloads.html Download and install appiumD download the latest version from Appium.io. Mount the disk image.   Drag Appium.app to your Applications folder Download and Install brew (The missing package manager for OS X) It's on the bottom of the Homebrew homepage. http://brew.sh/  ( Yeah, it would be helpful if it was listed at the top, instead.) From a Terminal prompt:    ruby -e "$(curl -...

Testing the Page Layout with Selenium Webdriver

Image
If you are looking to test Overlapping objects with selenium webdriver? page layout of a website? Easiest way to do that: webelement.getPosition() and webelement.getDimension() . These two methods are quite good when it comes to testing the layout of a webpage. I did a quick test and found that the location would return the location of the element relative to the left top corner of the page. That means this should always return the same value irrespective of monitor resolution or window size. If you can record the location and element dimension once and store these values somewhere, You can then run automated tests using selenium to find whether the position or dimension of the element changed. If that change is greater than a delta value, then it means the alignment of the element has changed and the test has Failed!