Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Thursday, August 10, 2023

Why should Test Automation Engineers learn Python?

 Introduction:

This question could be bothering a lot of test automation strategists. Java, C#, Groovy and JavaScript’s are the major programming or scripting languages dominating the test automation space for long. I also explained how a programming languages are chosen for test automation in my previous blog. Checkout this link, here.

So, what’s special about Python? In short, Python is an interpreted language, supports majority of operating systems with .NET framework installed, supporting high level programming, including object-oriented programming and offers numerous choices of powerful libraries for AI and ML, which could be integrated into your automation framework to make it AI/ML enabled. Both PyTest and RobotFramework are very popular, easy to learn, powerful test automation frameworks built on Python. RobotFramework supports a wide range of automation capabilities, like UI, E2E, RPA, Salesforce, Workday, SAP, API and Mobile. PyTest backed frameworks are extensible using Python libraries.

The dilemma on Test Automation Engineers minds:

First is assertiveness about there won’t be any decline on Java/C#/JavaScript automation demands. For example: “I have been working with Java backed test automation from past 10 years, it won’t be easy to acquire Python skills and become proficient in it within few weeks” – such proposition is not always true. Because, you might have worked with only core-java with Selenium / Appium without Spring or Hibernate frameworks, you might have only used TestNg and not Junit, you might used Junit 4 but not Junit 5. You might not try Lombok annotations, running batches with Jsch and reading console logs, connecting to JDBC and executing SQL queries, using JMS for message queues, integration with Swager/pact, JSON/XML parsing. These all are related to Java and required for E2E automation, if you did not work in all these areas in your 10 years journey, and you are not confident on your proficiency in these areas, then you cannot justify your love and commitment with Java.

In today's world, the test automation demands are volatile, recently the curve is going up for C# and JavaScript backed test automation, and it’s going down for java. Python backed automation demand is at equilibrium.

Second, “the syntax is completely different and not easy to remember, not as friendly as java” – such proposition is also not always true. The basic of all programming languages remain same, if you create own mental barriers, then you will never be able to focus on the learning. The Generative AI, can write better code than most of us, if it can learn, then why can’t we?

Our future automation will include more of AI/ML:

As more and more organizations undertaking their AI/ML enablement journeys, our future automation work will involve a lot more testing around AI/ML training data models, predictable complex api’s, big data analytics and numerical analysis. Python is in forefront, and a language of choice for AI/ML programming. So, the more delay we do to appreciate these facts, we will be fallen behind and will repent missing out on the growth opportunities in our career.

Is Python easy to learn:

I would say yes, otherwise in India it should not feature in School level curriculum. From my personal perspective also, yes, it is easy to learn with an open mind, overcoming our preferred programming language biases and psychological resistances, focusing on important semantics which helps us learn by analogy.

Below example explains a simple python program to help you learn by analogy:

#Copy the code in a file and save with .py extension

#Ensure Python 3.11 is installed in your system

#To execute the file, use any command line tool, type: python <filename>.py

#At first, we are creating a class file, with two methods, "init" represent a parameterized constructor method, and "str" represent a special method which instructs how to print the class objects in output, similar to overriding "toString()" method in java. As you can see, there is no need to specify access modifiers, return type, semicolon, curly braces. Python follows strict indention, as long as you are adhering to it, everything works fine. The "brand" and "engineCapacity" are the instance variables.

class Car:

    def __init__(self, brand, engineCapacity):

        self.brand = brand

        self.engineCapacity = engineCapacity

    def __str__(self):

        return f"Brand = {self.brand} and Engine_Capacity = {self.engineCapacity}"

#The "main" method is equivalent to Java/C# main method, but lot simpler in its declaration. The below code is responsible for running the Python program

if __name__ == "__main__":

    #Creating two Car objects

    firstCar = Car("Maruti","1000CC")

    secondCar = Car("Lamborgini","2500CC")

    #Creating a list with the two Car objects created above

    cars= [firstCar, secondCar]

    #Loop construct is similar to "for each" in java,

    for x in cars:

        print(x)

    #The len(list/string) method returns the length of a list or string

    print("Total items in cars list: ", len(cars))

    #Python lists support pop method, which can remove an item from a list with the specified index

    cars.pop(1)

    print("Removed 2nd item from cars array using list pop method, so Lamborgini will no longer be listed")

    for x in cars:

        print(x)

        print("index of "+ str(x) +" is "+ str(cars.index(x)))

    print("Using list append method to add one car to the cars list, the item will be added at last")

    #We can append an item to the tail of a list using the append method

    cars.append(Car("Hyundai","1299CC"))

    for x in cars:

        print(x)

    print("Using list insert method to add one more car to the cars list, at index 1")

    #We can append an item to a given index in a list using the append insert method

    cars.insert(1,Car("Kia","1200CC"))

    print("Present items in cars list")

    for x in cars:

        print(x)

    #Below code iterates a string in a reverse method, there are more simple techniques available

    #to achieve the same

    ms = "Hello"

    for x in range(len(ms)-1, -1, -1):

        print(x)

        print(ms[x])

    #Below code removes duplicate numbers from the list

    my_list = [1, 2, 4, 4, 1, 4, 2, 6, 2, 9]
    for i in range(0,len(my_list)):
        for j in range(i+1,len(my_list)):
            if (j<len(my_list) and (i == my_list[j] or my_list[j] in my_list[0:j])):
                del my_list[j]
    print("The list with unique elements only:")
    print(my_list)

Summary:

In this blog, I just tried to establish a proposition, discussed various aspects around it and cited some  examples. Hope you will find the post useful and share with your friends. Do write comments to share your opinion, it matters most.

Friday, August 4, 2023

What should be the ideal programming language for Test Automation?

 

Introduction:

Before beginning, I would like to thank all readers of my blog, for their appreciation and recognition of the important and unique contents that I have been publishing.

The most trivial question that is often asked to a Test Manager / Test Architect / Automation Architect / Test Lead by a Project Manager and/or a Program Manager, is can we achieve test automation by leveraging open-source test automation tools? The obvious answer is yes, but before submitting a proposal, we need to select an open-source tool and need to consider which programming languages does it supports, and out of those languages which will be more suitable for the project. For example: Selenium Webdriver, it comes with multiple language bindings i.e, java, JavaScript, c#, python, php etc.





Even some low-code licensed automation tools require some knowledge in specific programming languages. For example: Test Complete and Tricentis TOSCA requires some knowledge of JavaScript programming to achieve some test objectives by writing custom code.

Technical landscape of a project / program / portfolio, and its influence:

If you have been working in Test Automation, you must have been monitoring the new job postings (in Glassdoor, indeed, linkedIn etc.) and should have developed an idea about the test automation technical stack the employers are looking for. There are increasing demand for Selenium with C# and Python (PyTest), Playwright using JavaScript (or sometimes Java), Cypress with JavaScript. There is a bit saturated demand for Selenium Java and Selenium JS.

So, how does people in an organization decides on the programming language they want to use for automation? They consider the overall technical architecture and landscape, together with the type of application the project is tasked to build / maintain, the programming language chosen by the development team, the selected unit testing tool, the existing test automation capabilities (skilled personnel across the program/portfolio, automation knowledge-base: test archives, master test strategy for the program/portfolio etc.), learning curve for new hires to the project (including freshers, interns, and experienced hires who needs cross training when there is a skill shortage), availability of reliable open-source libraries for integration (example: for Java, we can integrate a wide array of tools PDFBox, Jsch, Json Schema Validator etc).

The alignment between project, program and portfolio are required to achieve strategic business objectives, maximizing resource utilization, maintaining common framework, curating common body of knowledge, sharing business and technology insights. Ultimately, the core objective is to balance the triple constraints, time, cost and quality.


Unit test frameworks, can they influence the Test Automation tools and its associated programming language selection:

Well, some experts may disagree with me regarding how the selected unit testing tool could influence the opensource test automation tool and its programming language selection. Let me elaborate on this, a modern web application is developed in a multilayered approach by multiple teams who work in parallel in Agile, for example: UI layer, API Gateway, Backend Services (API, GraphQL, MQ/Kafka messaging), DB services, Unix batches. UI layers could be built using Adobe AEM, React, Angular, Vue, Flex UI. Both Cypress and Playwright provides faster unit testing of Web UI on modern browsers using JavaScript. Both these tools could be used for E2E automation as well, given the backend technology stack is npm-node.js. But if the ratio of UI developers is less compared to Backend developers, then to avert skill shortage risk, the project managers and test managers most likely to consider the programming languages that the backend developers use. As they could assist the test automation engineers with some coding if needed. 

So, depending on the back-end technology stack, either java, C#, python or npm-node-js with JavaScript gets selected. And now if you just put a little tap on your head, you will recall Cucumber BDD provides Junit runner which is used for unit testing of Java based codes and used by test automation engineers too. Most importantly, overcome the programming language bias, an objective and logical decision making is required, within the given business context.

Can we break the stereotype:

Until unless you have a solid business case, metrics backed poc report, an approximate roi forecast, can handle criticism, and can negotiate all the odds, my advice will be don’t try it at your workplace. It's difficult to foster organizational change, it needs support from both your team members and the leadership.

If you got confused about what is meant by “stereotype”, then you should ask these type of question to yourself:

  • Why my project does not use Robot Framework with Python for test automation, and rather they are using Selenium Java?
  • Why does my project not use WebdriverIO and using Cypress?

 

Saturday, July 29, 2023

How do we sustain in Software Test Automation career?

I am sure that this question often strikes every test automation professional, irrespective of their experience level and skills proficiency. So, in this blog, I am going to do a deep dive with you to share the industry experience which I have gained, and that you can easily relate with your experiences.

The rise and transformation of test automation roles:

From around year 2002, Software Testing as a profession got significant acceleration in India. And within few years, the market demand for Test Automation professionals risen scrumptiously. Popular testing tools of that decade was Quick Test Pro, WinRunner, Silk Test, Rational Robot, SoapUI, Rational integration tester and Ruby on rails. I am not covering ETL test automation tools in this blog, as I do not have practical experience with any of those tools.

Nevertheless, Microsoft Excel based macros and VB Scripts were very popular those days, mostly used for some windows based repetitive tasks automation, including manipulation of Databases. PERL and Shell Scripting provides similar capabilities in more secured Unix/Linux/Solaris platforms.

Many training centres emerged across India, to utilise the opportunity to upskilling a mass and make huge profits out of it. Those days, all training centres used to conduct classroom trainings, some even offered placement assistance. Many who could afford such trainings those days, got benefitted either by switching to new role or by securing a new job. These days, the traditional training centres evolved too, offering hybrid trainings (including classroom, virtual, offline), but now they are facing direct competition from more organized Online training platforms and free training vlogs available on the internet.

In that decade, many did certifications in QTP, WinRunner, Silk Test and RFT tools. Whoever did the certifications earliest, mostly got benefitted.

So, what is challenging our sustainability in test automation roles?

In simple terms, the technological advances in electronics and semiconductor industry, coupled with substantial advances in Cloud computing, mobile platforms, AI, ML, IoT, Responsive Web, Single page/React applications, and new generations of high-speed internet, opensource tools has been destabilising our careers over the past decade, say 2013 to 2023.

Well, one might debate, that the technological advances have impacted all types of job roles, and human lives. Absolutely!!! Our lives have transformed to Digital; Quality Assurance and Test Automation are directly responsible to maintaining and raising the quality of our Digital transformation journey.

Between 2002 – 2012, many organizations used to conduct trainings on test automation tools, beside other technologies, for their employees, and it was optional to participate. They did use to conduct some skill-based exams, offering a certificate to their employees whoever scores 72% (for example) or above. Since, its optional, only people whoever was serious in building a career out of it or who want to be a future manager, were the only participants. In that decade, most roles demanded a manual tester, who can do automation if needed.

From 2012 onward, the optional training started becoming mandatory, and they started featuring in the career paths, yearly learning goals and performance appraisal discussions. From 2015 onward, many organizations revamped the role of manual testers, by upskilling that population to Automation Tester roles, who can perform manual testing if required. In this period, we mostly transformed from using Excel based test data sheets to BDD Examples, API driven data (JSON, XML, and recently GraphQL), Configuration based data (Properties files) etc. Many of us were tasked with doing complex test automation's, for example Mainframe applications, PDF files, image recognition and comparison, Big Data, running Unix batches part of integration test and reading console logs etc.

From 2020, the automation roles now demand knowledge and experience of CI/CD tools (GitLab’s, Jenkins, TeamCity, Terraform, Ansible, Ant, Docker, Kubernetes, Azure/AWS), deployment, Elasticsearch backed log server. That means, an automation tester who can perform DevOps tasks too.

Additionally, introduction and rise of new automation tools (mentioned below) started challenging the test automation professionals who spent most of their career with UFT (QTP), RFT, Selenium (IDE, 2.0 or 3.0) and Silk Test to upskill in these tools, to sustain and stay relevant in the job market.

  • Open source: Playwright, Cypress, WebdriverIO, Puppeter, Selenium Webdriver 4.0, PyTest, Robot Framework, RestAssured
  • Licensed tools (Including SaaS offerings): Copado Provar, AccelQ, Tricentis TOSCA, Test Complete, Ranorex, Katalan Studio, Karate
  • Test Infrastructure providers: BrowserStack, SauceLab, LamdaTest

Accompanied by the language antagonisms Java, C#, Python, JavaScript, and TypeScript.

For hardcore techies, who are having 12+ years of experience, there are other additional challenges to deal with in order to sustain, managing an agile or e2e test automation team, preparing and implementing test strategies, enforcing design patterns and architectural decisions, code reviews, mentoring, managing conflicts, test environments, test data, test logging (Elasticsearch, New Relic), test metrics and test reporting.

Finally, what actions would help us to sustain?

  •  Positive attitude and openness towards learning.
  • A systematic approach, balancing our life priorities and managing at least 4 hrs a week for our personal skills development and practice, with devotion.
  • Taking advantage of our organizations provided/supported learning platforms to identify, register and complete relevant training.
  • Earning digital badges
  • Keeping an eye on market relevant certifications, and earning those
  • Getting accustomed to NLP based machine learning algorithms and trying out tools like ChatGPT
  • Build skills in at least one RPA tool (UiPath, Microsoft Power Automate etc.)
  • Finally, mastering JavaScript. What??? Yes, you read it right. If you master JavaScript, all these tools will become easy for you to learn: Cypress, Playwright, WebdriverJS, WebdriverIO, Test Complete and Tricentis TOSCA.

 

Test Automation Strategy for Oracle Forms application running in Citrix servers

  Context : There are many product based applications developed using Oracle Forms and Java thick-client architecture, and most of them are ...