Skip to main content

Posts

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.