Skip to main content

Posts

Showing posts with the label Selenium

Execute Selenium Tests (C#) through Azure DevOps (CI/CD) in Browser Stack

  Introduction Prerequisite s  Preparing the YAML Setting up the pipeline Conclusion Introduction : In this article, we will be seeing how we can build a CI/CD pipeline in Azure DevOps to execute selenium test cases with C# language binding and execute tests in Browser Stack. But before we go there let us check what is CI/CD. Continuous integration (CI) is a process in which several team members merge their code repeatedly into a shared trunk. Before every integration, the changes are validated through automated testing. In this manner, we can find issues as quickly as possible and prevent defects from entering our live environments.  Continuous delivery (CD) is the extension of continuous integration that automates deployments by making sure changes that have successfully passed the automated designated tests are made to the next environment automatically as soon as they are ready.  Continuous Integration/Continuous Delivery is a set of best practices and principles that engineering t

Want to clear all inputs in a form quickly?

While submitting a form, at times, we get a use case where we need to first clear the default/pre-filled values of all the fields in the form and then enter our desired value. Usually, we do this for every field: WebElement firstName = driver.findElement(By.id("Form_submitForm_FullName")); email.clear(); email.sendKeys("Dheeraj"); Here we are locating an element, and assigning it to a WebElement. After that, we send commands: > clear() to clear the value into the input field  > And then the sendKeys() to fill it in with a new desired value. But isn’t it time-consuming to find all the fields in the form and then clear each field 1 by 1?  Here is the faster alternative… You can send a Javascript command to clear all the fields in one shot : document.getElementById('Form_submitForm').reset() This is just an alternative to reduce some test execution time. You can use any approach that works best for you. Here is the working example: public class Form { W

Docker restart policy and how to start containers automatically

 Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts.  Note * If you use docker stop or docker kill, it is expected that Docker does not restart the container. In case of docker stop or docker kill, its restart policy is gong to be ignored until the Docker daemon restarts or the container is manually restarted.  Container restart policy : Container restart policy controls the restart actions when Container exits. Following are the supported restart options: no – This is default. Containers do not get restarted when they exit. on-failure – Containers restart only when there is a failure exit code. Any exit code other than 0 is treated as failure. unless-stopped – Containers restart as long as it was not manually stopped by user. always – Always restart container irrespective of exit status. The following example starts a "selenium/node-chrome" container and configures it to always restart unless it is

Best place to add code for taking Screenshots with Selenium and Java

  If your UI automation code takes screenshot on failure in test method or page method, then it’s not good. We should handle that using a listener Or have a base class containing AfterMethod annotation that captures screenshots on failure. Use lateral approach (i.e. base class with afterMethod) if you aren’t using listeners in your framework. Go through this well explained article by Alex Siminiuc for more details: https://levelup.gitconnected.com/the-good-the-bad-and-the-ugly-of-taking-screenshots-with-selenium-and-java-c9da23e09842

Find “Cursor” position or currently focused element in a web page with Selenium

Problem Statement: On your registration page, you entered valid values in few mandatory fields but submit the form with no values in few of the mandatory fields. Now along with the error message(s), you want to verify that your cursor position is in the correct field (current focused element) like in the first blank mandatory field using Selenium. Solution : There are many ways to validate that but the simplest one would be to use:> driver.switchTo().activeElement() Use : Switches to the element that currently has focus within the document currently "switched to", or the body element if this cannot be detected. This matches the semantics of calling " document.activeElement " in JavaScript. Returns : The Web Element with focus, or the body element if no element with focus can be detected. And then you can put assertion based on your expected focused element, something like: Assert.assertTrue(driver.findElement(By.xpath("//input[@type='password']"

How to Unzip files in Selenium (Java)?

1) Using Java (Lengthy way) : Create a utility and use it:>> import java.io.BufferedOutputStream; import org.openqa.selenium.io.Zip; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream;   public class UnzipUtil {     private static final int BUFFER_SIZE = 4096;     public void unzip (String zipFilePath, String destDirectory) throws IOException {         File destDir = new File(destDirectory);         if (!destDir.exists()) {             destDir.mkdir();         }         ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));         ZipEntry entry = zipIn.getNextEntry();         // to iterates over entries in the zip folder         while (entry != null) {             String filePath = destDirectory + File.separator + entry.getName();             if (!entry.isDirectory()) {                 extractFile (zipIn, filePath);            

What topics should we cover if we are planning to appear for an SDET Selenium/Java position (Exp 4-9 years)?

Here are the topics that we should prepare if we are planning to appear for an SDET Selenium/Java position (Exp 4-9 years): Iteration in Java Abstract Class Vs Interface Strings in Java Static Usage in Java Exceptions in Java HashMap in Java Java Annotations Master to Build your own XPATH and CSS Implicit, Explicit and Fluent Waits Handling Frames Data-driven testing using Excel JavaScript Executor Logs Generation (Logging infrastructure with Log4j) Advanced Reporting (Extent, Allure, Klov Report Generation) TestNG Framework Design Pattern (Page Object Model, Fluent, Singleton- Any 1 should be fine) Selenium Grid And finally: BDD Using Cucumber  Build Management with Maven and/or Gradle Git, GitHub, etc. Continuous Integration with Jenkins, Azure DevOps, Team City, etc. (Any 1 should be fine)

How to set the browser's zoom level via JavascriptExecutor in Selenium WebDriver (Java)

Create generic methods like: public void  zoomIn() { zoomValue += z oomIncrement ; zoom(z oomValue ); } public void  zoomOut() { zoomValue -= z oomIncrement ; zoom(z oomValue ); } private static void  zoom( int level ) { JavascriptExecutor js = (JavascriptExecutor) driver ; js .executeScript( "document.body.style.zoom='" + level + "%'" ); } And then call ZoomIn() and ZoomOut() wherever you want. Complete sample code: import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; import io.github.bonigarcia.wdm.WebDriverManager; public class zoomTest { public static WebDriver driver ; private int  z oomValue = 100; private int  z oomIncrement = 20; public void  zoomIn() { zoomValue += z oomIncrement ; zoom(z oomValue ); } pub

Automation RoadMap (Selenium and Rest Assured)

Happy and healthy new year to everyone. A note to all the manual testers out there: Upgrade your skills not only for survival in today's dynamic IT world but mainly to feed your brain with new challenges. Shred your old self completely- Spend at least 45 minutes of the day, no matter how busy you are, block this time off your daily schedule in learning test automation. If you do not have interests per se, develop an interest by going through videos first and then jump to implementation by taking baby steps. Read. Get Mentors. Learn. Observe. Experiment. Reiterate until success. Wish you all the success and prosperity this year. I created this roadmap, see if this helps for Selenium with Java learning: https://www.linkedin.com/posts/dheerajgambhir_automation-selenium-git-activity-6568387687412273152-SjE8/ I created this roadmap, see if this helps for API automation using Rest Assured: https://www.linkedin.com/pulse/roadmap-learn-api-automation-testing-using-dheeraj