Skip to main content

Posts

Showing posts with the label testAutomation

Code-based versus Low-Code/No-Code test automation solutions: Which one to Choose?

In today's world, where new automation test solutions are being released monthly, enterprises are looking for ways to expand and accelerate their software delivery processes. The key to success is choosing the right solution that balances your team’s skill sets and expertise and simultaneously meets your organization’s objectives. This blog details out the pros and cons of code-based vs. low-code/no-code test automation solutions. Author: Dheeraj Gambhir Blog Link Enjoyed reading this article? Please share the knowledge with your friends and colleagues.

Test Automation Fundamentals

 

How to upload a pdf file using REST Assured?

 If you use this code as mentioned in few other blogs and videos:   Map<String, String> headers = new HashMap<String, String>(); headers.put("Content-Type", "multipart/form-data"); byte[] fileContent = FileUtils.readFileToByteArray(new File(filePath)); RestAssured.given().headers(headers).body(fileContent).post(url);   There are high chances that you will get errors related to content-type or "400 - Request is not a multipart request". So, the solution is to use: .multiPart("file", new File("/path/to/file"),"application/pdf"). Please note that I have used "application/pdf" as 3rd param in the multiPart method and this value should be passed as per the file type that you are uploading like for the png file it should be "application/octet-stream", for JSON file it should be "application/JSON". multiPart is an overloaded method that can take max 3 parameters:   a) ...

How to integrate TestNG Test Automation Results (Selenium/RestAssured/Appium) with TestRail?

  To integrate TestRail with any automation suite, we can use the TestRail APIs with the following basic flow: Create test cases in TestRail.   Provide those unique Test IDs from TestRail to your TestNG tests. Run automation: Create a test suite in TestRail before test execution using the TestRail API. And then post the run results according to test automation results using the TestRail API. Create test cases in TestRail:        2.  Creating a custom annotation and calling it as TestRails:      3.  After that, we associate our test cases with actual Test Rails ID’s like:     4.  These ids 1, 2, 3, and 4 are test case ID that we got from TestRail test cases, you can hover over your test case and see that ID in the URL (as shown below):     5. Create a Test Run in TestRail through code,  as you can look at that we have not created any Test Run manually (see below): Snapshot of TestRail before execution of...

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

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']...

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

Benefits of running your automation suite

In the agile world, the deployment window will continue to grow narrow and for sure you can’t catch every bug- so, always use the power of both i.e. on-demand (including webhook on every change) and scheduled automation test suite run.  On one hand, your on-demand test run will make sure that you get fast feedback (i.e. which change and by whom broke it) and also you will get the complete test coverage. And, on the other hand, your scheduled runs ensure that you get continuous feedback, don't push any broken pieces to the next environment and hence confidence in your code changes especially after the integration with the larger system(s). Keep your builds green (Organically).

Test Data Strategies in test automation

Your test results are mostly as good as the test data it consumes. What should be our Test data cleanup strategy in automation? -> Should we clean up the data immediately after each and every run? OR, Should we perform the clean slate periodically? It's hard to find one strategy that can solve all our test data issues in our automation suite. So, instead of focusing on finding that silver bullet, think thoroughly about your own test requirements and see which strategy can bring in max stability in your automation suite instead of following blindly what others are doing. I know you are still not sure that which particular strategy is right for your automation suite or not? Don't rush, after a few tests run your test suite itself will let you learn by generating issues like flaky tests/intermittent failures, false positives, slowness/performance issues, etc. etc. Please go through this well-crafted article on "Test Data Strategies" by @Joe Colantonio/@P...

Should not call "automate testing"

You can’t automate testing; you automate only the checks (tests)... Still baffled? Checks can be automated for sure but testing can NOT. When we interact with any application, we use our human brilliance to know the functionality of that application and then based on our intelligence we judge whether the behavior (use case) of that application is right or wrong — Can that judgment be automated? So far- Nope. Can we automate whether the behavior of that application is right or wrong on performing certain action/test? Yes.

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); ...

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