Skip to main content

Posts

Showing posts from 2020

Making SOAP Requests with Postman

  Even after following what is mentioned here: https://learning.postman.com/docs/sending-requests/supported-api-frameworks/making-soap-requests/ i.e., set Content-Type = text/xml in the Headers and setting POST as a call, at times we get 500 internal server error or bad request with the message like " error message: The message with Action '' cannot be processed at the receiver... " So, what are we missing here? Setting SOAPAction in Headers is worth giving a try... How do we get that? 1. Open your WSDL in a browser with the service URL appended by “?WSDL" and find soapAction for which you want to execute your SOAP call. Like for the "Add" method in http://www.dneonline.com/calculator.asmx?WSDL , soapAction should be set to http://tempuri.org/Add 2. Copy the value of soapAction attribute of your SOAP method. Add a new key, provide Key as “SOAPAction” and the value that you copied in the above step i.e., http://tempuri.org/Add 3. Set “Content-Type” hea...

AWS Signature with RestAssured

  AWS Signature authentication support is not something that is available in RestAssured as out-of-box feature. At least I wasn't able to find any good documentation for the same. So, how we can implement AWS Signature Headers with Rest Assured? Signing AWS requests with Signature Version 4... This explains step by step how to create a signature and add it to an HTTP request to AWS: https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html Below given source code (AWSV4Auth.java) helps to calculate signature based on given data and return the headers. Once you get headers suing aWSV4Auth.getHeaders(), you just need to add these headers in your Rest API call (Sample for the same is given below: RATest.java) AWSV4Auth.java: public class AWSV4Auth {     private AWSV4Auth() {     }     public static class Builder {         private String accessKeyID;         private String secretAccessKey;      ...

Pickles- Living doc generator of your Gherkin feature files

  You have a set of BDD feature files written in the Gherkin language but your stakeholders doesn’t really like the text-only format? Plus they don’t want to open each feature file by one by one to go through it? Start using Pickles, it generates a document containing all features in a single documentation in just one step and it’s an opensource too. Pickles has a lot of other ways and parameters, do checkout more details here:  http://docs.picklesdoc.com/en/latest/,   https://github.com/picklesdoc/pickles  and  https://www.picklesdoc.com/# P.S. It can generate your documentation in a variety of formats like JSON, Excel, Word, etc. and not only HTML. #pickles #gherkin #bddAutomation

Monitor your APIs in postman

If you are not using any CI/CD tool like Jenkins, Azure DevOps, etc. but still want to schedule your postman automation collection suite to check the health and performance of your APIs; then you can use Monitor option provided by Postman.   You can also enable email notifications for failures and can configure the available integrations to receive alerts in tools like Slack, PagerDuty, etc. Check here for more details: https://learning.postman.com/docs/designing-and-developing-your-api/monitoring-your-api/setting-up-monitor and https://www.postman.com/pricing/   Note* With the FREE plan, we get only 1000 hits/requests per month as of writing this post.   You can monitor the performance on your account web dashboard as shown below.

Steps to execute postman collection through newman

  Here is what you need to do to start executing the postman collection through newman on your system: 1. Install NodeJS – https://nodejs.org/en/download . Click on the 32-bit or 64-bit Windows Installer package, depending on your machine configuration. Skip this if NodeJS/npm is already installed on your system. 2. Open a command prompt, and type “node -v” and "npm -v". These commands should work and provide version number if nodeJS installation is successful. 3. Run this command to install newman:   npm install -g newman 4. Install npm package newman-reporter-htmlextra for creating reports.   npm install -g newman-reporter-htmlextra 5. Pull/Export the collection, environment json (if any), test data csv (if any) files from the Postman UI or code repo (git) to your local and run this command through the folder on your local where you have these files: Command where you have collection json and environment json file : newman run "<<your_collectio...

Tips and tricks for automation using Postman/Newman

   1. How do we run multiple newman/postman collections sequentially (back to back) at one run ? Batch running multiple newman/postman test collections : Create a batch file like this and run: call newman run Collection1.postman_collection.json -e qa1.postman_environment.json -r htmlextra --reporters cli,junit,htmlextra --reporter-htmlextra-export TestReport1.html -d TestData1.csv call newman run Collection2.postman_collection1.json -e qa2.postman_environment1.json -r htmlextra --reporters cli,junit,htmlextra --reporter-htmlextra-export TestReport2.html -d TestData2.csv   Side note : Give a shot to https://medium.com/@mnu/run-multiple-postman-collection-in-parallel-stress-ee20801922ed in case you would like to run it in parallel (P.S. haven’t tried this yet)   2. How can we set environment variable based on another environment variable value ? Like for QA1, we need accountNo say "123" but for QA2, we need accountNo say "345", etc.   pm.tes...

Best practices for API automation using Postman

1. Always use Collections and organize tests into folders for testing : Even Though the collection is the top-level of organization, we should have folders that can group together related to requests or demonstrate a detailed workflow. As our API grows in number and complexity, it will become important to organize our tests so they make sense and can be found easily. Therefore, we suggest using folders/sub-folders to group requests by resource, module type, test suite, and workflows. P.S. If require, we can run specific folder(s) inside a collection using “ –folde r ” argument. 2) Use global/environment/collection variables :  Postman also allows us to store data from previous tests into global/collection variables. These variables can be used exactly like environment variables. For example, there is an API that requires data received from another API ( chaining/correlation ). We can store the response attribute (or part of the response) and use that as part of a request ...

Azure DevOps Postman/Newman HTML Report

 In Azure DevOps, if you don't want JUnit Test results and like to have a HTML Report (htmlextra) that newman provides which is very neat and comprehensive, go for this FREE extension: https://marketplace.visualstudio.com/items?itemName=MaciejMaciejewski.postman-report   This lets you create a task for publishing newman HTML Reports in your pipeline into Azure Storage(like shown below in Image 1). And then, embedded reports can be viewed as a tab in Build and Release result page (like shown below in Image 2). Plus, there is an option to download the reports from the same tab.

TestProject smart and powerful recorder

  TestProject already had a smart recorder that was capable of doing fantastic stuff we look for in any record and playback. It can easily generate source code from recorded tests, suggest useful add-ons, allow us to choose from various locator strategies, and view all available properties of any UI components, etc. But have you checked their new versatile and much powerful recorder? You should check it when you get the time and share your feedback. Here are the few enhancements I noticed: 1) Added support for iFrames. I am sure this will be helpful in testing apps that play with so many iFrames. 2) Self-healing feature for the stability of the locators: I have used other tools/frameworks like Canopy(F# library built on top of Selenium) and it wasn't that effective in terms of Self-healing feature but I must say that it works very effectively when I tried using TestProject recorder to record, edit and playback. Also, if a Self-Healing mechanism was used to recover from an error, it...

What all attributes should be there in your automation solution to be called a good solution?

Your automation project should have all of these to be called a good solution : Well drafted Project Design Clear Project Structure and Documentation Defined Page Objects (For UI project) Independent Automated Unit Tests Automated End to End Tests  (Loosely coupled) Reliable Locators (For UI project) Highly effective strategies for managing test data Comprehensive Dependency Management Precise and concise logging and Reporting

Jenkins: Purge Job History Plugin

Download and install: https://github.com/jenkinsci/purge-job-history-plugin This plugin provides the ability to purge all the build records of a job either via a CLI command or via the UI. When this plugin is installed it adds a new action to all Jobs with builds. You can either use UI as shown here (https://github.com/jenkinsci/purge-job-history-plugin) to purge any/all of the following:  Job Pipeline MultiBranch Job (Recursive Flag is Needed) Jobs under a Folder (Recursive Flag is Needed) All Job under Jenkins Instance (Recursive Flag is Needed) Or you can do it via Command line using this command: java -jar jenkins-cli.jar -s http://localhost:8080/jenkins purge-job-history <JobName> -r JobName : Name of the Job whose history you would like to purge r : To reset the next build number to 1 Note* you need super access to perform it.

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 (en...

Locate disappearing elements

You don't have access to the source code and want to inspect elements like HTML5 validation error messages, Wait icon, dynamic search list, or for that matter any disappearing element in your browser that disappears when your mouse moves away?  There are many ways to do that but using below we should be able to capture most of those kinds of disappearing elements/scenarios: Open Chrome Go to that page where you would like to inspect the disappearing element Open dev tools (F12) Select the "Sources" tab While the element you want is displayed, press F8. This should halt the script execution by freezing the DOM (Paused in debugger mode) As the DOM is in the frozen state, now we should be able to hover/select that element to inspect that. #smallAndOldTip #TipsAndTricks #testAutomation #devTools

Where should we keep sensitive information in automation projects?

Of course, nothing can beat encryption/decryption to safeguard our sensitive data but here is one more approach to store your project data and retrieve. Environment Variables are key/value pairs like Properties. We can use this to allow config (sensitive) information to be passed into applications. We can use it in any automation project, not necessarily for Selenium only. Like every approach this too has it’s own pros and cons but for sure, it’s better than keeping your sensitive date in code directly or in a property file. Good read by Alex — https://medium.com/@alexsiminiuc/in-selenium-projects-keep-sensitive-information-in-environment-variables-3c9eb6521080

To perform data-driven testing- which is better (UI/API)?

For sure we can do data-driven testing using automated UI tests (Selenium, Cypress, WebDIO, etc.) but just because it gives us the option, doesn’t mean that we should it for all cases through UI only. Take an example where we visit any website to get a price quote on any policy — let’s say a medical policy, what do we do- we run our test by going through the same page(s) like select value from few dropdowns, select few checkboxes, and enter values in few text fields to get one final output i.e. the “ price quote ” of your medical policy- here the variation was only the “ Test Data ” that finally derive a  certain output . Don’t you think that to test this business logic, the efficient way would be to perform API testing which is better maintainable and powerful? As I mentioned in my previous post too, our UI (end to end) should be meant to confirm that user(s) can use our application in the way it’s intended to do so, perform interactions with it without hitting any issues and alwa...

Mock GeoLocation using Selenium 4

If there is a use case where you need to override the geolocation of the browser before you hit the website, Selenium 4 Alpha version does support that now by using the power of Chrome DevTools and Protocol (CDP) along with setGeolocationOverride method present in Emulation class. To set it back to default, use the clearGeolocationOverride method. #mockGeoLocation #testAutomation #selenium4Alpha @Test private void testGeo() throws InterruptedException { driver .get( "https://www.google.com/maps?q=28.704060,77.102493" ); Builder<String, Object> mapLatLan = new ImmutableMap.Builder<String, Object>(); mapLatLan .put( "latitude" , 40.712776); mapLatLan .put( "longitude" , -74.005974); mapLatLan .put( "accuracy" , 100); ((ChromeDriver) driver ).executeCdpCommand( "Emulation.setGeolocationOverride" , mapLatLan .build()); driver .get( "https://www.google.com/maps?q=40.712776,-74.005974...