Skip to main content

Posts

Showing posts from November, 2019

@FindBy Limitation to accept only Static String

Completely agree with Simon, we should get something better here. @FindBy annotations accept String constant values. You can't compute them at runtime and always have to go with mix and match approach here like PageFactory annotations for static ones and By's in for dynamically created element(s). There are few workarounds that we’ve tried but nothing solid yet. hashtag # FindBy hashtag # testautomation hashtag # Selenium

Screenshot using Chrome DevTools

1. Open a Chrome browser. 2. Open Dev Tools (Press F12). 3. Press CTRL+SHIFT+P (in windows) or cmd+SHIFT+P (in mac). 4. Type "screenshot" into the Command Menu and you will see options like "Capture area screenshot", "Capture full-size screenshot", Capture node screenshot" and "Capture screenshot". 5. Select your desired option and hit enter. Done... If you wish to, you can also emulate a device mode first and then take the screenshot- this way it will capture as per the device dimensions. Isn't it really handy when you want to take the screenshot of the entire page on any device like iPhone X?

Zoom In And Zoom Out In Selenium using JavascriptExecutor

Zoom In And Zoom Out In Selenium using JavascriptExecutor: public void zoomInOut(String value) { JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.style.zoom='" + value + "'"); } And use the above function as per your need like: public void validateZoom() { WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get("https://testersdigest.blogspot.com"); zoomInOut("150%"); zoomInOut("10%"); zoomInOut("40%"); }

Automation Test Data using jFairy

A few weeks back, I wrote about how we can come up with the automation test data that look more or less like real application data. There we have discussed the test data generation library Java Faker: https://testersdigest.blogspot.com/2019/10/automation-test-data.html (https://github.com/DiUS/java-faker).  We have a similar Java library "jFairy" which can generate test data for our automation scripts: https://github.com/Devskiller/jfairy Usage of jFairy is quite simple and similar to java-faker. #automationTestData   #JFairy   #testautomation   #automationTesting  

Code Review: SonarQube

The automation scripts that we write might not go to production but it ensures that high-quality product is pushed into Production. So, we all should use Static Code Analysis tools like SonarQube, SonarLint, etc. that helps us: - detect any potential bugs and performance issues, security vulnerabilities - meet the code quality, detects the duplicate code and help detects the complexity level of the code logic, etc. And with the advent of docker, it's super easy to install and play with it, like for SonarQube: https://hub.docker.com/_/sonarqube/ #automationtesting   #sonarqube   #dockerSonarqube   #codereview

How to make sure that your Selenium automation test works fine even for slow loading web pages?

Rather than using methods like waitForPageToComplete() or document.readyState property etc. to wait for a page to load in your Se tests, the better way is to use the LoadableComponent and SlowLoadableComponent pattern in Page Object Model. You need to make sure that your Page Object classes extends the abstract LoadableComponent class which in turn provides the implementation for the following methods: - load() //The load method is used to navigate to the page - isLoaded() throws java.lang.Error //The isLoaded method is used to determine whether we are on the right page. The get() method from the LoadableComponent class will ensure that the page/component is loaded by invoking the isLoaded() method. If the check fails here, load() method is called followed by isLoaded(). If your site loads very slow, then we should consider using SlowLoadableComponent instead of LoadableComponent. SlowLoadableComponent verifies the page is loaded until the given maximum timeout.

Fillo: Query your excel

Recently came across a really cool Java API called Fillo. It is an open-source API that lets you query Excel files (xls & xlsx) and it supports select, insert & update queries. Maven dependency for Fillo: https://mvnrepository.com/artifact/com.codoid.products/fillo My requirement is to fetch the APIs Name where Type=Regression and Run=Yes from below shown Excel table. I have given a shot to simple queries and it works fine. Please check more details here: https://codoid.com/fillo/ P.S. I'm a strong believer in 'we should use Public APIs instead of creating utilities from scratch' unless we have some other restrictions like legal etc. #testautomation   #automationtesting    #tipsandtricks   #fillo   #queryExcel

Eclipse: Refresh workspace automatically

When we run a test case or execute the entire script directly within Eclipse - we would like to see the fresh execution Report or log file or any other refreshed resource but by default, projects don't automatically refresh. I find it very useful to turn on the "Refresh" option so that Eclipse can automatically perform the refresh. This option is shown below: Windows-->Preferences->General-->Workspace-->Select "Refresh using native hooks or polling" I wonder why this preference isn't selected by default when it's very friendly. Check this out to find the difference between "Refresh using native hooks or polling" and "Refresh on access": https://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-9.htm Note* Have heard that at times it does require force refresh on Mac especially with Mars and lesser versions.

Selenium Event Listener

Selenium provides an API for various events that occur when our scripts are executed like click, switch to a window, navigation, onException, etc. and these can be registered using WebDriverEventListener interface or EventFiringWebDriver class. These events play a pivotal role in analyzing results and in debugging issues (if any). EventFiringWebDriver class takes care of all events that are occurred while the execution of your script. EventFiringWebDriver class can be bind to more than one listener but all event listeners should be registered with the EventFiringWebDriver class so that it can be notified. EventFiringWebDriver eventFiring =new EventFiringWebDriver(driver); FirstEventCapture firstListener =new FirstEventCapture(); //FirstEventCapture implements WebDriverEventListener SecondEventCapture secondListener =new SecondEventCapture(); //SecondEventCapture implements WebDriverEventListener eventFiring.register(firstListener); eventFiring.register(secondListener); Check t

Measuring page load time using Selenium

There are many tools that are designed specifically to measure a load of your web pages such as LoadRunner, JMeter, WebLoad, etc. and preference should be given to these tools only. But in case, there is an ask to do it using Selenium, we can use Performance Timing and Navigation Interface APIs to measure the page load time on client-side: - https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming - https://www.w3.org/TR/navigation-timing/#sec-navigation-timing-interface The first image shows when we are executing it manually on the Chrome Dev Tools console. We can use the output generated by these APIs in our Se framework (if required) as shown in the Second Image. P.S. As from Se4 alpha-3 onwards, we can directly play with Dev Tools- I will check if we can directly use it instead of capturing time using these APIs.  #selenium   #loadTime   #devTools   #testAutomation   #seleniumautomation  

The use of Verbose attribute in testNG or POM.xml (maven-surefire-plugin)

At times, we see some weird behavior in your testNG execution and feel that the information displayed is insufficient and would like to see more details. At other times, the output on the console is too verbose and we may want to only see the errors. This is where a verbose attribute can help you- it is used to define the amount of logging to be performed on the console. The verbosity level is 0 to 10, where 10 is most detailed. Once you set it to 10, you'll see that console output will contain information regarding the tests, methods, and listeners, etc. <suite name="Suite" thread-count="5" verbose="10"> Note* You can specify -1 and this will put TestNG in debug mode. The default level is 0. Alternatively, you can set the verbose level through attribute in "maven-surefire-plugin" in pom.xml, as shown in the image. #testNG #automationTesting #verbose # #testAutomation