Skip to main content

Posts

Showing posts from December, 2019

Download Restrictions option in Selenium

At times, we need to visit a page in our application that automatically starts downloading the file which is as per the feature of that page. But we're navigating to this page (A) only to further navigate to the other page (B) by clicking on some link given on this page (A) which redirect us to the page (B) but at the same time, we don't want to download the file on visiting this page (A) as it's not required every time while running our Selenium automation script. Did you know there is a preference option "download_restrictions" that can help us achieve this? Let say A is this: http://selenium-release.storage.googleapis.com/2.41/selenium-java-2.41.0.zip HashMap<String, Object> prefs = new HashMap<String, Object>(); prefs.put("download_restrictions", 3); ChromeOptions opt = new ChromeOptions(); opt.setExperimentalOption("prefs", prefs); WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(opt); ...

What happens when you also need to test how your application behaves on a slow connection using Selenium?

Execute Selenium test suite on a slow network connection : public class SetNetworkConditions { public static WebDriver driver; @Test public static void setSlowNetwork () throws IOException { WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); driver.manage().window().maximize(); CommandExecutor executor = ((RemoteWebDriver) driver).getCommandExecutor(); // Setting the slow network conditions Map<String, Comparable> map = new HashMap<String, Comparable>(); map.put(“offline”, false); map.put(“latency”, 5); map.put(“download_throughput”, 5000); map.put(“upload_throughput”, 5000); Response response = executor.execute(new Command(((RemoteWebDriver) driver).getSessionId(), “setNetworkConditions”, ImmutableMap.of(“network_conditions”, ImmutableMap.copyOf(map)))); driver.get(“https://testersdigest.blogspot.com"); long navigationStart = (long) ((JavascriptExecutor) driver) .executeScript(“return window.performa...

Use of Copy styles from Dev Tools (Extract all CSS values of any element)

At times, we need to test many CSS values of an element on the page and look for a quick option to copy every attribute at once. Going to Styles tab in Dev Tools and copying 1 by 1 is a tedious thing. You can follow below-mentioned steps to extract all the CSS for any selected element using Chrome Dev Tool in one shot: 1. Right-click on a DOM node in the Elements Panel 2. Select Copy > Copy styles Sample for the image given below : font-style: inherit; font-family: "Open Sans",Helvetica,Arial,sans-serif; font-size: 18px; font-weight: 400; color: #333; display: inline-block; max-width: 170px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; white-space: nowrap; text-decoration: none; height: 24px; line-height: 24px;

Copy Data From One Excel To Another Using Apache POI

In case there is a requirement where you need to copy the data from one excel file into another excel using test automation, we can use Apache POI open-source library to do that. Here's the self-explanatory code but do let me know if you have any queries. For other details, you can go through https://www.javatpoint.com/apache-poi-tutorial import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Iterator; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.testng.annotations.Test; public class CopyExcel { @Test public static void CopyOneWBookToOther() throws IOException { // Step #1 : Locate path and file name of target and output excel. String TargetSheetPathAndName = "/Users/dheerajgambhir/Desktop/O...

A road map to learn Web Automation (SDET)

Good developers are rare, good SDETs are rare as well and always high in demand. Without a doubt, Automation testing has become a need of the hour. You need to take baby steps as you plan to start automation testing from scratch. I wrote this article - "A Road map that will help you learn Web Automation", see if this helps: https://www.linkedin.com/posts/dheerajgambhir_automation-selenium-git-activity-6568387687412273152-SjE8/ Always remember, Test automation is a development discipline.

How to discard Jenkins old builds from project or Pipeline?

When we work with Jenkins, we surely run our project(s) multiple times and this will result in a long queue of the build History list that mostly is of no use after certain numbers. How to discard Jenkins old builds from project or Pipeline? 1) If you have access to the " Manage Jenkins " section of your Jenkins then you can run the below-mentioned script to clean your project Build History. Note* This will reset the build number to 1 on your next run. a) Access your Jenkins HP > Manage Jenkins > Script Console b) Copy-Paste this script to your Console Script text area and update the " myproject_name " with your project name where you need to clean the build history and hit the " Run button ". def yourJobName = "myproject_name" def job = Jenkins.instance.getItem(yourJobName) job.getBuilds().each { it.delete() } job.nextBuildNumber = 1 job.save() This should clean your Build History for that particular project but if you...

Salesforce login OTP feature automation

Of course, there are many ways to tackle "the Salesforce login OTP feature" for automation but the easiest one is to change the Trusted IP Range i.e. Add the IP address of the server where you are executing your script to trusted IP range in SF. Under Setup menu, go to Security Controls - Network Access and here you need to enter the IP address ranges of your machine/server as shown below. After lightning upgrade, I agree that execution against dynamic content and Shadow DOM still poses some challenges that usually end up consuming a lot of time than any other usual web application but with correct XPATH strategy it can be solved.

Real-time test execution metrics (time-series)

We run most of the automated suites in a remote machine and thus the test results are accessible only at the end of the execution OR else, we need to check the console for the results for the progress. What if we can have a way that gives us the execution results while the tests are actually being executed in the remote machines? Yes, it's possible by using time-series database like InfluxDB, Graphite, etc. that supports insertion and real-time querying of data via a SQL-like query language, so we can use it to collect all the test metrics and then use Grafana or Kibana which is an excellent and powerful visualization tool to form a dashboard. How to install InFluxDB and Grafana on windows: Please go through these well elaborative articles by Antoine Solnichkin: https://devconnected.com/how-to-install-influxdb-on-windows-in-2019/ https://devconnected.com/how-to-install-grafana-on-windows-8-10/ For Sample queries, please go through these links: https://docs.i...

Soft Assertions: Where and when we can use it?

To tackle the disadvantage of Hard Assertions where we want to continue the execution even if some assert fails and see the result at the end of the test. Soft Assertions are the type of assertions that do not throw an exception when an assertion fails and continue with the next step after assert statement. This is in the case where our test requires multiple assertions to be executed and we want all of the assertions to be executed first before marking (failing/skipping) the tests. Consider these 2 examples: 1) We're verifying many CSS values of the same element like background-color, font-family, and color in a single test case. element.getAttribute("background-color") element.getCssValue("font-family") element.getCssValue("color") Obviously, if any one of these fails we would like to catch it and mark the test case as fail but that doesn't mean if background-color verification fails it should mark the test case fail with...

The Base class in the Selenium framework

Authoring automated tests is quite easy but authoring easily human-readable and maintainable tests is much tougher. Especially, when your project grows in size and complexity. There are many approaches that can help you build your tests in a Selenium framework like correct handling of your Base Class well. The Base class should have these things: - the setup() and teardown() test methods. - the WebDriver object. - load your configuration/properties file here (can be a part of its constructor) - common aspects of all tests like handling sync issues, ScreenshotOnFailure, etc. - have a method to visit the site that returns the Index page object. - and All test classes should inherit it. P.S. My view on this topic is purely subjective. And in many cases, you may not be able to apply this type of approach to your framework.

3 Selenium classes that are not so popular to locate elements

Here we have discussed 3 Selenium classes that are not so popular but that can help you locate elements in Selenium: - ByIdOrName - ByChained - ByAll 1) ByIdOrName - This helps the driver to locate an element either by name or by id. This is present under org.openqa.selenium.support package and to use this we have to call the constructor of the ByIdOrName class and pass the Name or ID. This method tries to find the element using ID first and it waits till the max implicit wait time for the element to locate using ID and if it is not able to find the element with ID then only it tries to locate with the Name. As soon as the driver finds the element with id, it will not check the element with a name attribute and won't want for max implicit wait time either. driver.findElement(new ByIdOrName("username")).click(); 2) ByChained - This helps the driver to locate the element based on the parent element, and it accepts an unlimited number of locators. This is prese...

Transitive and Excluded dependency in Maven

Transitive dependency in Maven: Let say you have a library A1 that depends on library A2 and this A2 library further depends on the library A3. So your library A3 is a Transitive Dependency of your library A1. Excluded dependency in Maven: Let say you have a library A1 that depends on library A2, and this A2 library further depends on the library A3. If required,  we can explicitly exclude library A3 for the library A1. We can use the “exclusion” element to exclude it. Such dependencies are called Excluded dependencies in Maven.

TestProject- https://testproject.io/

I admit this when it comes to automation, I'm still old school and prefers using direct APIs/JARs but as TestProject is creating so much buzz recently so I thought of doing Hands-On to it by using their "free forever plan". Apart from being the first free community-powered cloud test automation platform, there are many things that intrigued me: - It collaborates very well with other popular frameworks such as Selenium and Appium. - Oh man, execution speed is really fast. - Addons: It supports lots of awesome addons that help to make our tests very powerful like "jRand" that lets you access random data generators for a variety of test data. - Most of the basic functionalities like scheduled execution using CI/CD pipeline with out-of-the-box integrations to Jenkins and other tools, scripting, etc. can be learned in a week max. For Novice test automation engineers to learn the programming syntax can take up to max 2 weeks. - Always wanted features lik...

Installing and Uninstalling Add-ons in Firefox Browser

Almost a month back, we discussed how we can install an extension in Selenium 3: https://www.linkedin.com/posts/dheerajgambhir_seleniumautomation-chromeext-automationtesting-activity-6587948591678095361-Lr7m Or https://testersdigest.blogspot.com/2019/10/need-extension-while-running-your-se.html And now in Selenium 4, we have direct method installExtension and uninstallExtension for the firefox Driver. The installExtension installs a new addon with the current session which inturn will return an ID that may later be used to uninstallExtension the addon using uninstallAddon.

javax.mail APIs Auth fail error for Gmail

If you are using javax.mail APIs and provided correct credentials for your Gmail account and still getting “javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid credentials (Failure)” error then there are high chances that you might have forgotten to relax the security of your Gmail account. You can use this link to allow less secure apps to access your Gmail (which obviously makes your account vulnerable and thus isn’t recommended) https://myaccount.google.com/lesssecureapps?pli=1