Skip to main content

Posts

Showing posts with the label Selenium WebDriver

How do you deal with multiple form objects in selenium

We all have come across forms containing multiple fields. My next video tutorial deals with solving this issue. Hence data object like following can be made more comprehensible and less error prone - BigUser1 bigUser1 = new BigUser1( "firstName" , "lastName" , "userName" , "address2" , "address1" , "phone1" , "phone2" , "password" , "confirmPassword" ) ; Head over to video tutorial to learn more :)

How can you save resources when instantiaing driver?

I asked on my previous post about what was wrong in instantiating driver on set up method? And here is the solution video on my YouTube channel (After 5 years of gap I finally added new video tutorial :)) The solution described on video tutorial uses following set up - public class BaseClassOnDemandDriverSetup { private WebDriver driver ; @BeforeMethod public void setupTest () { // Any other set up goes here } @AfterMethod public void teardown () { if ( driver != null ) { driver .quit() ; } } public WebDriver getDriver () { if ( driver == null ) { WebDriverManager. chromedriver ().setup() ; driver = new ChromeDriver() ; } return driver ; } }

Cypress (yet another) Selenium WebDriver killer

There is no perfect tool, there are tools which satisfy specific requirements and Cypress is one such tool. I have not used Cypress and my assessment on this post is limited to information I have gathered reading about Cypress. Cypress appeared to me Selenium Remote Control (aka Selenium 1) repackaged with Chrome browser at it target. Cypress target audience is different than of Selenium's, let's see what requirements they cater to. Cypress target audience seems to be front-end developer. Its power lies in being able to test front end without having real back end or a mocked backend. Selenium's power lies in its integration capability with various other tools and APIs. Imagine testing on staging system which requires java based API to be invoked to create customer account following which using WebDriver to login to frontend and creating a transaction following which data base assertion to verify transaction attributes. Not all of these operations can be carried out using...

Do you check for absence of element on page

When writing automated tests we often check presence or absence of element for assertion conditions. This is usually written as -  assertTrue("Element is missing. Bug!!!", pageObject. isSomeElementDisplayed()); And when element is not displayed then above mentioned assert statement fails. In the similar manner we can write following assert statement to check for absence of element -  assertFalse("Element is present. Bug!!!", pageObject. isSomeElementDisplayed()); Above mentioned assert statement would fail if element is displayed on page. Everything looks ok, is not it. Not really, there is catch. Let's have a closer look at assertFalse statement we used above -  assertFalse("Element is present. Bug!!!", pageObject. isSomeElementDisplayed()); This assert statement would also succeed even if webpage results in 404/500 or any other error page, since error page would also be missing the element on which we are p...

File upload and WebDriver (Where is my File?)

You may have come across file upload use case when working with WebDriver. File upload is quite easy since it is same as typing in a text box but herein we need to pass path of file to be uploaded. I used to keep a static file in src/test/resources folder of maven project and would use it for upload operation. But you can also generate file during run time using java.nio.file.Files class. Files class has createTempFile(java.lang. String, java.lang.String, java.nio.file.attribute. FileAttribute...) method which can be used to generate temporary files. For ex, you can generate a temporary pdf file and get back the File object as following - File file = Files. createTempFile ( "test-" + accountNumber, ".pdf" ).toFile(); generatePDF (file, StringUtils. repeat ( "Dummy PDF" , 10 )); And this is how generatePDF looks - public static File generatePDF(File file, String content) { try { Document e = new Document(); ...

Marionette Web driver and STF

If you were also stuck with Firefox 47 and Selenium 2.53 issue then this is right time to start experimenting with Marionette.   But Before delving into Marionette, let’s see what a web browser engine is. Web browser engine is a program which renders markup content (i.e. html, xml, images etc) and the format information (i.e. css, xsl etc). It is also known as layout or rendering engine. In simple words, web browser engine is responsible for how you are able to see a web page in a browser, email client or e-book reader. Some of the most popular web browser engines are - Webkit which is used in safari and chrome browsers Gecko used in Firefox, Thunderbird email client Marionette is WebDriver version for Mozilla’s Gecko engine. It can control both the browser (menu, function etc) also known as chrome (don’t confuse with google chrome browser ;-)) and the content within the browser (something which is of immense value for test automation). Marionette also follow...

How to handle duplicate element locators?

Have you come across use cases when you have create multiple element locators for almost similar element locators? Consider following text box, which gets date filled when user clicks on - expired, today, end of week etc links - This is how page html looks - And the element locators for expired, today etc link could be - "#coupon_expiryAt~a:nth-of-type(1)" "#coupon_expiryAt~a:nth-of-type(2)" There are other possible element locators but each link requires its own element locator. Now considering earlier example, the only difference in element locator is index number 1, 2 etc So what if we could get rid of creating different element locators and pass index number depending on the link we want to interact with? Let’s create base element locator - private static LinkElement getExpiryLinkElement( int index) {    return new LinkElement( "Expired Link" ,           By. cssSelector (St...

Selenium Tests Framework is now open source

What next, after diligently following  Java training videos  and  Selenium training videos  ? How about a Selenium Test Framework which gives detailed step by step report of each action carried out on web page? something like -  Selenium Tests Framework (STF) is behind such awesome report and not just this, there are tons of other features. STF is available on  git hub You can clone the project and build STF jar to use in your selenium project Or better, fork it, make modifications and submit pull request. This way your features to STF would be available for other to use. Is not open source wonderful? So what are you waiting for ? ;-)  

Return only first or last element from webelements collection

Note: If you are new to java and selenium then start with selenium java training videos .     We often come across situation when there are multiple elements on a page and we probably like to exercise only a few of them using selenium webdriver. May be just first and last element. For example on a search result page we may like to click on only first and last link and not all. This is when Iterables API comes handy. (By the way I am assuming that you have already completed watching selenium training videos :)). Once we have collection of web element then we can use Iterables to get only first or last element as following - Consider that we fetch collection of element as - List< WebElement > webElements = getDriver().findElements(By. id ( "htmlID" ));   Now we can get the first web element from this collection as -  WebElement firstElement = Iterables. getFirst (webElements,  getDriver().findElement(By. id ( "defaultElement" )));   Herei...

Working with database using JDBC

This is 12th java training video in the series of learning java for selenium webdriver. This session covers - establishing connection  executing select query    executing update query Java training video can be watched on line. If you have any questions then please post it in comment section

File systen and selenium webdriver

This is 11th java training video in the series of learning java for selenium webdriver. This session covers - retrieving absolute file path copy file to another file read txt file read property file parsing xml file Java training video can be watched online. If you have any question then please post it in comment section