home Archives - Indium https://www.indiumsoftware.com/blog/tag/home/ Make Technology Work Thu, 30 May 2024 10:03:28 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 https://www.indiumsoftware.com/wp-content/uploads/2023/10/cropped-logo_fixed-32x32.png home Archives - Indium https://www.indiumsoftware.com/blog/tag/home/ 32 32 How can Gen AI accelerate and transform your SDLC? https://www.indiumsoftware.com/blog/how-can-gen-ai-accelerate-and-transform-your-sdlc/ Mon, 08 Apr 2024 11:11:32 +0000 https://www.indiumsoftware.com/?p=26838 The software development landscape is constantly evolving, and the pressure to innovate and deliver faster than ever is immense. Generative AI, a powerful technology, is reshaping industries, and the SDLC is no exception. It allows machines to create content, transforming repetitive tasks and unlocking unprecedented efficiency and innovation. So, let’s see how exactly generative AI

The post How can Gen AI accelerate and transform your SDLC? appeared first on Indium.

]]>
The software development landscape is constantly evolving, and the pressure to innovate and deliver faster than ever is immense. Generative AI, a powerful technology, is reshaping industries, and the SDLC is no exception. It allows machines to create content, transforming repetitive tasks and unlocking unprecedented efficiency and innovation. So, let’s see how exactly generative AI can accelerate and transform your SDLC.

What is Gen AI and how does it work?

Certain types of Gen AI can generate code, write documentation, and even propose creative solutions based on your inputs. It leverages powerful NLP (Natural Language Processing) models trained on vast data to understand your intent and produce human-quality outputs.

GitHub Copilot, OpenAI CodeX, Microsoft Bonsai, and DeepCode are some of the Gen AI tools that propose relevant snippets, functions, or even entire lines of code. These tools understand natural language descriptions, adapt to your coding style, and can generate solutions for various languages and tasks. They can automatically generate unit tests, fix common bugs, and suggest refactoring improvements based on best practices.

However, these models are still under development, and their generated code might require human review and adjustments.

Key SDLC areas that Gen AI makes an impact

  1. Create intelligent workflows 

  • Automating repetitive tasks: Gen AI can generate boilerplate code, unit tests, and API definitions, freeing your developers to focus on the core logic and complex algorithms.
  • Intelligent code completion: Say goodbye to endless lines of manual coding. Gen AI can suggest relevant code snippets and functions based on context, significantly speeding up development.
  • Rapid prototyping: Generative AI can generate interactive prototypes based on your descriptions or code, accelerating feedback loops and ensuring you’re on the right track early on.

2. Boost software quality 

  • Bug-free code: Generative AI can analyze code and identify potential bugs and vulnerabilities, proactively mitigating issues before they become costly problems.
  • Simplify testing: Generate diverse and comprehensive test cases with the help of AI, ensuring your software is robust and handles edge cases effectively.
  • Security enhanced: Generative AI can identify and suggest solutions for potential security weaknesses, keeping your software safe and secure.

3. Spot code faults 

  • Pattern detection: Like a seasoned code reviewer, AI can scan vast repositories, analyzing syntax, structure, and logic. It identifies patterns associated with common coding pitfalls, flagging potential issues before they become bugs.
  • Bug prediction: Machine learning models trained on mountains of code learn the significant signs of trouble. They analyze your code, compare it to known bug patterns, and highlight areas that need attention.
  • Anomaly detection: AI constantly monitors your code execution. It detects deviations from expected behavior and identifies suspicious code paths, helping you strip off potential bugs in the early stage.
  • Learn from the past: AI taps into a treasure trove of knowledge—bug repositories and best practices databases. It learns from past mistakes and suggests solutions to similar issues in your code, preventing you from reinventing the wheel.
  • Seamless integration: Gen AI can seamlessly integrate into your development environment and provide real-time feedback and alerts during coding, helping you catch errors on the fly.

4. Simplify testing

  • Automated test case generation: Gen AI can create diverse test cases covering various scenarios, edge cases, and potential bugs, ensuring comprehensive testing.
  • Improved test coverage: Identify areas where testing might be lacking and generate additional test cases to achieve thorough coverage.
  • Early bug detection: Train Gen AI on your codebase to identify potential bugs and vulnerabilities before they cause problems in production.

5. Automate documentation 

  • Auto-generated documentation: Manually churning out user guides and technical specs is time-consuming. Generative AI can analyze your code and user data to create accurate and up-to-date documentation, saving valuable time and resources.
  • Consistent and accurate information: Eliminate inconsistencies and outdated documentation with AI-powered real-time updates that reflect your code changes.

Ready to explore further? Let’s take a call to discuss any questions you have about Gen AI implementation.

Book a call!

How Gen AI transforms your SDLC?

Gen AI isn’t just about automation; it’s about augmentation. Imagine a tool that can:

  • Increase speed: Eliminate repetitive tasks and streamline workflows, leading to faster development cycles and quicker time to market.
  • Enhance quality: Gen AI can identify potential bugs, suggest optimizations, and write comprehensive tests, resulting in more robust and reliable software.
  • Spark innovation: Explore new possibilities with AI-generated ideas and prototypes, pushing the boundaries of what your software can achieve.
  • Improve collaboration: Break down knowledge silos by automatically summarizing documentation and generating clear communication materials.
  • Empower developers: Shifting the focus from repetitive tasks to creative problem-solving and higher-level thinking fosters a more engaged and productive team.

The true power of Gen AI lies in its adaptability. By suggesting correct syntax and best practices and even fixing common bugs, these tools help prevent errors and improve code quality.

AI-powered coding is the future of software development—why?

The software development landscape is poised for a seismic shift. Generative AI promises to transform the way we code. This cutting-edge technology isn’t just impressive; it’s rapidly evolving, and it holds the key to unlocking next-generation software developers who are:

Extremely efficient: Imagine developers working twice as fast, churning out high-quality code with the help of AI. Generative AI can handle repetitive tasks like boilerplate code generation, freeing developers to focus on complex problem-solving and innovation.

Quality champions: With AI-powered tools, developers can quickly identify and fix bugs. Imagine your code being scanned in real-time, with potential issues highlighted before they become nightmares. It’s like having a built-in quality assurance team working tirelessly to ensure your software is clean.

Cost-conscious: Time is money, and Generative AI saves you both. Automating repetitive tasks and accelerating development brings your software to market faster and at a fraction of the cost.

Why Indium for implementing Gen AI in SDLC?

As an innovation-driven company, Indium is at the forefront of this exciting revolution. We understand the immense potential of Generative AI and are actively exploring its responsible implementation in the SDLC. Our dedicated AI experts are ready to unlock this technology’s power while addressing any security and compliance concerns you may have.

We can help transform your ideas into tangible results faster and better than ever before. Let’s work together to create the future of software development!

Finally

Gen AI is still evolving, but its potential for the SDLC is immense. By embracing this technology, you can unlock faster development cycles, high-quality software, and a more innovative future for your projects. So, step into the future and let Gen AI be your partner in transforming your SDLC!

Ready to explore how Gen AI can transform your SDLC?

Call us

The post How can Gen AI accelerate and transform your SDLC? appeared first on Indium.

]]>
Go vs. Rust in 2023: Choosing the Right Language for Your Tech Venture https://www.indiumsoftware.com/blog/go-vs-rust-in-2023-choosing-the-right-language-for-your-tech-venture/ Wed, 20 Mar 2024 12:11:00 +0000 https://www.indiumsoftware.com/?p=26916 As we are near the end of 2023, pursuing optimal tech solutions remains as crucial as ever. For startups navigating this dynamic environment, the choice of programming language can significantly impact operations, particularly in application engineering, product engineering, and low code. In this context, the debate between Go and Rust takes center stage, offering distinct

The post Go vs. Rust in 2023: Choosing the Right Language for Your Tech Venture appeared first on Indium.

]]>

As we are near the end of 2023, pursuing optimal tech solutions remains as crucial as ever. For startups navigating this dynamic environment, the choice of programming language can significantly impact operations, particularly in application engineering, product engineering, and low code. In this context, the debate between Go and Rust takes center stage, offering distinct advantages for those willing to explore beyond the mainstream options.

Golang and Rust hold a unique distinction in programming languages, having emerged in the early 2000s and 2010s. This sets them apart in a landscape dominated by languages with roots stretching back centuries.

When thoroughly examining Golang versus Rust, it becomes evident that these two languages share notable similarities. However, a closer inspection of six important categories revealed that
This head-to-head comparison delves into the languages’ attributes, including:

  •  Performance
  •  Features
  •  Ease of Development
  •  Maintenance
  •  Popularity
  •  Community

This article aims to shed light on the distinctions between each language, providing valuable insights to guide your decision-making process for your tech stack. Continue reading to discover the key differentiators!

Golang vs. Rust: Side-by-Side Comparison

Explore this direct comparison between Golang and Rust. This detailed analysis ensures that you can make an informed decision based on the specific features and capabilities that matter most to you in your chosen programming language.

Performance:

Go and Rust both put a strong emphasis on performance. Being relatively new languages, they are designed to perform well and surpass their predecessors.

While both languages excel in terms of speed and efficiency when compared to other programming languages, the crucial question is: how do they measure up against each other? Through rigorous benchmark testing, it becomes evident that Go and Rust each have their areas of strength, with neither consistently outperforming the other.

TLDR: Regarding speed and performance, both Go and Rust demonstrate commendable capabilities, each with its areas of proficiency.

Features:

While Go brings notable strengths to the table with its efficient binaries and reliable package management, Rust offers an extensive set of equally impressive features. These encompass zero-cost abstraction, obvious error messages, move semantics, robust data race prevention, and comprehensive pattern-matching capabilities.

TLDR: Both Go and Rust offer robust capabilities, each catering to specific programming needs without significantly overshadowing the other.

Ease & Speed of Development:

Go’s emphasis on readability and simplicity renders it a highly accessible language, making the learning curve relatively smooth. In contrast, Rust introduces intricate concepts like borrowing and ownership, which can pose a steeper learning curve for developers. Rust openly acknowledges its learning curve.

TLDR: Go offers a more straightforward learning experience, and Rust’s advanced concepts contribute to a steeper learning curve. The choice ultimately depends on your comfort with these concepts. It’s not a clear-cut win for either language in this category.

Maintenance:

Maintenance encompasses the tasks required to ensure your programs’ smooth operation and longevity. In this regard, Go holds an advantage, as its codebase is inherently simpler, making maintenance tasks more straightforward. With its added complexity, Rust may entail a more intricate maintenance process.
TLDR: Go’s simplicity lends itself to easier maintenance than Rust, which involves more intricate upkeep due to its inherent complexity. In this category, Go holds an advantage.

Community:

The open-source languages community is a thriving community of developers that is instrumental in aiding newcomers in mastering the language’s nuances and best practices. Evaluating the strength of a community, however, is subjective. If we see both Rust and Go communities, both communities often garner significant praise, underscoring their vibrancy and support. This recognition indicates a solid and active community.

TLDR: Rust and Go benefit from thriving communities, but Rust’s community visibility stands out in this comparison. It’s important to note that both communities are strong in their own right. This category is more evenly matched.

Popularity:

Defining the popularity of relatively young languages like Go and Rust can be challenging. Despite their impressive features and advantages, they have yet to reach the widespread adoption of more established languages like JavaScript, Python, or Java.

According to Stack Overflow, less than 10% of developers currently utilize Rust or Go. However, it’s worth noting that Go holds the 14th position in the rankings for top languages, while Rust trails behind in the 26th spot, as per the TIOBE Index for January 2022. This index considers various factors, including search engine popularity, presence in computer science courses, and endorsements from skilled engineers.

TLDR: In comparing Golang and Rust, Go enjoys more popularity than Rust.

Now that we’ve explored the side-by-side comparison of Golang and Rust, let’s explore deeper into each language individually.

What Is Golang?

Golang, also known as “Go,” is a computer language that is statically typed and compiled. It is positioned as a competitor in contemporary programming languages and was created by Google developers, drawing inspiration from C and C++. Because of its simple syntax, some people often compare Golang to Python.

Go’s statically typing imposes stringent guidelines on variable declarations. This feature makes error detection more reliable, especially regarding syntactic instances. This accuracy helps to make coding more dependable and secure.

Compilers play a fundamental role in enforcing static type-checking. They convert code into machine-executable instructions, a process that occurs before execution. Consequently, compiled languages exhibit higher overall speed than their interpreted counterparts. In addition to speed, compiled languages afford more excellent command over hardware elements. This and Go’s intentional design highlight its strengths in memory management and multithreading capabilities.

An integral aspect of Go’s memory management is its garbage collection feature. This mechanism ensures efficient memory allocation by utilizing managed heaps. It’s worth noting that Go addresses a concern seen in C regarding memory safety, marking an improvement. Including a garbage collector adds a layer of security and stability to Go’s memory handling.

In essence, this signifies that in Go, memory no longer used is repurposed for new objects, while unused things are efficiently cleared from memory. Programs with garbage collection tend to exhibit superior performance as they are not prone to memory leaks.

Another standout feature in Go is the concept of goroutines. These allow for creating functions or methods concurrently alongside other processes or procedures. This concurrency emphasis underlines Go’s multithreading prowess, enabling a central processing unit (CPU) to handle multiple tasks simultaneously. This capability translates to heightened speed and overall efficiency in Go programs.

Advantages of Golang

When weighing the pros and cons of Golang vs. Rust, understanding the strengths of Go is essential. Here are some distinct advantages that position Go as a favourable choice for your next project:

Comprehensive:

Go impresses with its all-encompassing ecosystem, from robust tools to extensive libraries and well-documented resources. Its toolset boasts minimalistic dependencies, simplifying development workflows. A notable mention goes to GoDoc, a package facilitating real-time documentation generation while you code.

Fast:
Go’s notable performance is attributed to many factors, including efficient garbage collection, swift compilation, and robust concurrency support. This speed, often considered one of Go’s hallmark features, is substantiated through benchmarks, showcasing Go outperforming Python by up to 100 times in certain areas. It consistently rivals or surpasses Java in terms of speed.

Portable:
Go’s versatility shines through its seamless compilation across multiple platforms. Compatibility issues have become a thing of the past, allowing developers to work on their preferred operating system without hindrance.

Readable:
While Go inherits runtime efficiency like C, its readability draws inspiration from Python. The syntax is highly approachable for programmers, especially those proficient in English. Essential formatting elements like indentation and spacing are automated by tools like gofmt, supplemented by golint for additional style checks. This user-friendly design makes Go particularly appealing to newcomers.

Recommended Use Cases for Golang

Golang finds its application across a diverse range of project types. According to the 2019 survey results, web development, databases, and network programming emerge as the primary domains where Go shines. The language’s inherent proficiency in concurrency positions it as an excellent choice for networking services.

Go is highly esteemed as a top-tier language for backend web development. Swift execution on a webpage plays a pivotal role in establishing brand presence and user engagement online, underscoring its significance.

Considering Go for your next project? Contact Indium for expert Go developers who can bring your vision to life.

Book a call!

Furthermore, Go boasts official support for the Google Cloud Platform, aligning perfectly with the cloud computing paradigm integral to various services within the platform. This makes Go a stellar choice for high-performance cloud applications.

 

Companies Utilizing Golang

While the choice between Golang and Rust shouldn’t solely hinge on popularity, understanding why major corporations opt for Go provides valuable insights into the language’s potential.

Google:
As the birthplace of Go, Google’s unwavering support underscores the language’s stability. Many of Google’s internal projects, including flagship products like Google Chrome, Google Earth, and YouTube, are built using Go. This endorsement from one of the tech giants speaks volumes about Go’s robustness.

Twitch:
Twitch, a leading live streaming platform for gamers, handles massive amounts of real-time chats and video streams concurrently. By implementing Go, Twitch enhanced its garbage collection process, resulting in a smoother and more responsive user experience.

SoundCloud:
SoundCloud, a renowned music streaming service, has become a launchpad for emerging artists. The platform employs both Golang and Ruby on Rails in its tech stack. Go’s static analysis capabilities, allowing for code debugging before execution, played a pivotal role in SoundCloud’s choice of Go.
The fact that these major players in the business have embraced Go demonstrates its versatility and efficiency in a range of contexts, enhancing its appeal as a feasible option for high-volume, high-performance applications.

What Is Rust?

Rust is a statically typed, compiled programming language supporting various programming paradigms. Its design places a premium on safety and performance, particularly emphasizing secure concurrency.

In terms of syntax, Rust aligns closely with C++. Unlike languages like Go or C++, Rust does not employ garbage collection. Instead, it uses a borrow checker to verify memory safety. The borrow checker enforces rules regarding data ownership and prevents data races – situations where two or more pointers attempt to access the exact memory location simultaneously.

Rust is tailored for what’s known as “programming in the large.” This entails coding for large teams or small groups over an extended duration. Rust is engineered to accommodate and promote highly concurrent and exceptionally secure systems to facilitate this approach.

The inception of Rust dates back to 2006 when Mozilla employees-initiated experiments that would eventually lead to the development of the language. Approximately three years later, a stable release of Rust emerged, and it is now integral to critical components of the Firefox browser.

Since 2016, and in each subsequent year, Rust has earned the distinction of being voted the “most loved programming language” in the Stack Overflow Developer Survey. This accolade attests to its popularity and the positive sentiment it garners within the developer community.

Advantages of Rust

In a fair assessment of languages, including the comparison of Golang vs. Rust, it’s essential to provide an impartial evaluation of each language. With a brief overview of Rust in mind, here are its key advantages:

Performant:

Rust’s compilers use inherently leads to impressive speed, surpassing many interpreted languages like Python. Even when compared to languages like Java, known for its JIT compiler optimized for performance, Rust still maintains a speed advantage.

Intentional:

Rust exhibits characteristics that underscore a deliberate effort by its designers to create a disciplined language that enhances the developer experience. Notably, Rust pledges zero-cost abstractions. These abstractions, which involve translating high-level code to low-level language or machine code for execution, typically incur a performance penalty. However, in Rust, there is no discernible difference in speed between low-level code and abstracted programs. This means abstractions come without a performance cost.

Safe:

One of Rust’s standout features is its stringent compiler, which meticulously scrutinizes each variable to ensure memory safety. Type safety is a cornerstone of Rust, ensuring that programs run without the occurrence of segfaults (illegal memory access errors). Rust’s ownership system analyses memory at compile-time, effectively preventing these issues.

Concurrent:

Concurrency is a well-known strength of Rust, akin to Go. What sets Rust apart is its borrower checker, which distinguishes it from other languages. Rust’s unique approach to concurrency ensures multithreading without the risk of undefined behavior.

These advantages collectively position Rust as a language that excels in performance, intentional design, safety, and concurrency, making it a compelling choice for various projects.

Recommended Use Cases for Rust

Rust’s versatility allows for its application in a wide array of scenarios. However, there are specific domains where Rust truly excels:

Systems Programming:

Rust shines in systems programming, a field that requires high performance and precise control over hardware resources. Systems programmers, who closely interface with the hardware, benefit from Rust’s impeccable performance and zero-cost abstractions. Given Rust’s heritage with C++, it’s well-equipped for middle-level capabilities, balancing low-level and high-level languages.

Middle-Level Capabilities:

Rust’s middle-level capabilities make it an excellent choice for tasks requiring a nuanced approach to memory management and hardware interaction. Middle-level languages serve as a strategic compromise between low-level languages (which offer detailed control over hardware) and high-level languages (which provide abstraction for ease of development). This makes Rust an ideal candidate for projects involving operating systems and complex computer applications. Despite its proximity to low-level operations, Rust remains human-readable, a quality seldom found in machine code.

Companies Using Rust

While Go enjoys support from major corporations, it’s essential to acknowledge the impressive roster of companies that have embraced Rust. Here are some notable examples:

Firefox:

Rust’s integration with Firefox, known as ‘oxidation,’ underscores its significance in the browser’s development. This collaboration is so substantial that it has a dedicated wiki page detailing the project. Firefox’s efficient handling of multiple tabs owes much to Rust’s involvement.

Yelp:

Yelp, a prominent platform for business recommendations and reviews, leverages Rust for critical operations. The company’s developers have created their Rust framework for A/B testing, a pivotal tool for optimizing page performance. This framework is deployed across all Yelp applications and websites. Yelp’s choice of Rust stems from its impressive speed, on par with C, and enhanced safety.

Dropbox:

Dropbox, a leading cloud service provider, relies on Rust for its core file storage system. This strategic implementation of Rust has significantly enhanced the efficiency and performance of Dropbox’s services.


Get ahead with Go Lang! Keep an eye out for our upcoming whitepaper on Go Lang! Packed with insights to elevate your business. Stay tuned with Indium Tech.

Book a call!

 

Wrapping Up

Go and Rust, despite their youth, share significant commonalities. Both intentionally designed languages prioritize memory safety and concurrency, demonstrating superior performance to their peers.

However, the distinctions between these languages are pronounced. Go is characterized by its simplicity, while Rust embraces complexity. Their respective features and priorities diverge in meaningful ways.

In the Golang vs. Rust comparison, we arrive at a draw. This means the choice between the two ultimately depends on your business needs and preferences. Both languages offer unique strengths and advantages, and the decision should be based on carefully considering your project’s requirements.

As we conclude this comparison, stay tuned for our upcoming whitepaper on Go Lang. Discover how harnessing the power of Golang can drive your business forward. Watch this space for insights that can reshape your development strategy.

The post Go vs. Rust in 2023: Choosing the Right Language for Your Tech Venture appeared first on Indium.

]]>
Automation using Playwright Library with Cucumber JS. https://www.indiumsoftware.com/blog/automation-using-playwright-library-with-cucumber-js/ Thu, 14 Mar 2024 09:48:30 +0000 https://www.indiumsoftware.com/?p=26584 This tutorial will walk you through using the Playwright library with Cucumber JS...

The post Automation using Playwright Library with Cucumber JS. appeared first on Indium.

]]>
Topics:
  • About
  • Extensions required
  • Project setup
  • Modules/Libraries required
  • Features
  • World (Hooks)
  • Steps
  • Script execution
  • Reporting
  • Attach screenshot for failure
  • Feature file navigation support
  • Conclusion

About

This tutorial will walk you through using the Playwright library with Cucumber JS. Playwright supports TypeScript out of the box. We conducted effective end-to-end tests with the best possible narration by integrating the Playwright library with Cucumber- a test automation tool.

Extensions required

  • Cucumber (Gherkin) Full Support

The VS code requires this extension to recognize the .feature files and provide snippet support. Some of the primary support functions are auto-parsing of feature steps, auto-completion, syntax highlight, and type validations.

npm:

This extension purely supports running npm scripts as defined in the package.json file. It also is equipped to validate installed modules against dependencies as defined in the package.json file

It would be a great piece to read on 10 Open Source Automation Tools For Your Automation Needs

Project setup:

Precondition: Node JS and Visual studio code should be installed.

  • Navigate to C: or D: drive.
  • Create a folder with the name ‘Playwright_BDD_Demo.’
  • Create subfolders. vscode, features, and steps within ‘Playwright_BDD_Demo’.
  • Open Visual Studio code.
  • Click File ->Open Folder->Locate the created folder and select folder (now project is loaded).
  • Open Terminal->New Terminal.
  • Type the command ‘npm init’ in the terminal and press enter for all the suggestions. (package. json is created where project dependencies are maintained).

Now your project structure looks similar to the below picture:

Modules/Libraries required:

As our project base is ready, modules related to Playwright and Cucumber have to be added to the package.json file. The required modules can be added under the file’s dependencies section by running npm commands to install the respective modules.

  • Run the command ‘npm i playwright’ in the terminal – This command will install the playwright library and browser dependencies required for testing.
  • Run the command ‘npm i @playwright/test’ in the terminal – This command will install the modules required for validations with built-in automatic waits.
  • Run the command ‘@cucumber/cucumber’ – This command will install the Cucumber, a tool for running automated tests written in plain language.
  • Run the command ‘npm i typescript’ – This command will install the typescript.
  • Run the command ‘npm i ts-node’ – This command will install the typescript dependencies to support with node.

After installing all the required packages, your package.json looks similar to the below picture:

Features:

Features files are the test case files written in Gherkin language, which explains the motive of the tests in plain English, making it easier for non-technical people to understand the context of the test.

A feature can have ‘n’ number of scenarios, and each can have an ‘n’ number of steps.

A step has to start with the Gherkin keyword ‘Given,’ ‘When,’ ‘And,’ or ‘Then.’

Let’s create a sample feature using Gherkin keywords and derive the logic using Playwright.

  • A feature file should always end with a .feature extension.
  • Create a sample feature under the features folder with the name ‘demo_blaze.feature’ (feature named after the demo site will be using).
  • Add feature and scenario details as per the below image, based on the demo site’s functionality.

  • From the above image, we have created one general ‘scenario’ to verify the title of the products and another ‘scenario outline’ to verify products under the category as part of the data-driven test.
  • Tag the scenario and scenario outline as ‘demo’ for now (later sections demonstrate how to use these tags).
  • Yellow lines indicate a warning as our steps have not been implemented.
  •  Implementation of steps will be discussed in detail under the ‘Steps’ section.

World (Hooks):

The word ‘World’ describes the steps where we can declare and invoke the objects/variables that can be used globally. The Java/C# version of Cucumber is said to be Hooks.

Hooks are primarily used to specify pre and post-conditions globally across the features. Here, we will create two global variables, one for the browser and another for the page.

The ‘Before’ and ‘After’ functions launch the app before each scenario and then kill it. The goal is to make the scenarios independent. The Before function captures the browser and page variables from the initializer and exports.

  • Create a file with the name ‘world.ts’ under the steps folder.
  • Initialize the browser and page variables.
  • Set default timeout as 60 seconds (default wait till promise gets resolved).
  • Create a ‘Before’ function to launch the chromium browser and assign the session id to the browser object.
  • Create a browser context and assign it to the page variable.
  • Navigating the URL is specified here as part of the precondition.

Create an ‘After’ function and close the chromium browser using the browser reference created.

Export the page and browser variables as given in the above image to use for further actions.

Steps:

Steps from the feature file have to be implemented as definitions to specify your business logic.

Gherkin’s steps from the features are initially considered undefined by Cucumber, and when running the script command defined in package.json, Cucumber generates the undefined snippets which could be used in the steps file instead of writing them, which saves time for us.

Firstly, Cucumber needs to know where to look for the steps to notify us with the snippets of unimplemented ones (In case already implemented, it will directly run the matching step).

The below procedure helps you to run the script and get the status from Cucumber.

  • Create a file named cucumber.js to define the Cucumber options where the path to the feature and step are defined.

Declare the options and export them as a module with the name ‘test_runner.’

  • From the above image, the specific name of the feature is not mentioned. We will run the scenarios based on tags, a best practice with Cucumber.
  • Now navigate package.json and remove the error from the test command under scripts.
  • Paste the command ‘npx cucumber-js -p test_runner –tags  @demo’ .
  • (Here, we have specified the module name ‘test_runner’ where the Cucumber options are mentioned, which the cucumber-js module will identify. Following that, we note our tags from the feature where Cucumber identifies all the tests based on the tag and runs them.)
  • Run the command ‘npm test’ in the terminal to execute the scripts.
  • Now, Cucumber generates all the undefined steps in the terminal.
  • Create a step file under ‘demo_blaze.steps.ts’ under the ‘steps’ folder. Copy the snippets from the terminal and paste them into the steps File.
  • Import ‘Given, When, and Then’ from the Cucumber module.

  • As snippets are now in place, the relevant business logic can be written below each snippet.
  • Import ‘page’ from ‘world’ to perform actions on the page.
  • Import ‘expect’ from ‘@playwright/test’ to perform validations.

The following image shows that locators and logic are scripted below each step.

Script execution:

It is time to execute the completed scripts as we are done with the logic implementation. This time we won’t see an undefined warning from Cucumber as the implementation is done. To execute the scripts, let’s repeat the steps to get undefined snippets:

  • Open the terminal and run the command ‘npm test.’
  • Now browser launches (headless mode set to false), and the test starts running.

Once the tests are completed, you will see the scenario/step count details as in the image below.

Reporting:

Though we have results displayed in the terminal, a report implementation is required to share the results as an html file with your colleagues/teammates.

Cucumber provides an html reporter plugin to generate the reports based on Gherkin’s steps, which can be customized using metadata.

The following steps will walk you through setting up the Cucumber report:

  • Open the terminal and run the command ‘npm i cucumber-html-reporter’ and ‘npm i @types/cucumber-html-reporter.’
  • The above commands will install the dependencies related to the reporter.

Add a file ‘htmlReportGenerator.js’ under the root folder to define the report options per the image below.

  • A bootstrap theme is generally preferred for the report. The paths to the json file and output are defined.
  • The current date is appended next to the output to avoid the html report overriding the previous one.
  • The screenshot is set as accurate where it could be attached for failure scenarios which we discuss later in this section, and the remaining metadata are user-defined.
  • To store the json data, create a folder named ‘Reports’ and create a file ‘cucumber_report.json’ inside the folder, which the Cucumber requires to parse to the html file

Navigate to the cucumber.js file and add the below option to format json data’– format json:./ Reports/cucumber_report.json.’

  • Navigate to package.json and edit the ‘test’ command under scripts as

‘npx cucumber-js -p test_runner –tags  @demo & node ./htmlReportGenerator.js’.

  • Rerun the tests using the command ‘npm test’ to ensure reports are generated.
  • After completing the test run, you can find the message in the terminal as the report has been generated successfully.
  • The report will be automatically launched in the default browser (Edge/Chrome).

Also, the report file .html will be auto-generated in the Reports folder, which can be shared with others.

Attach screenshot for failure:

Attaching the screenshots for failed steps helps us identify what went wrong with the application under test.  To achieve it, we can make use of the ‘world.ts’ file to define the same as post-condition.

  • Navigate to steps->world.ts file.
  • In the ‘After’ function, remove the arrow signature and add a function keyword next to async, which supports the attached screenshot interface.
  • Add the ‘Status’ module to Cucumber’s import to track the status of the scenario.

Add the ‘Scenario’ as a hooks parameter and define the condition to attach a screenshot of the scenario fails.

Now let’s test whether the reporter adds the screenshot in case of failure.

  • Navigate to the demo_blaze.feature and change the product name from ‘Samsung galaxy s6’ to ‘Samsung galax s6’ to fail the test.

  • Run the command ‘npm test’ to execute the scripts.
  • A failure is recorded, and a screenshot is attached to the report

Feature file navigation support:

VS code does not provide the default support to navigate from feature to step. However, it can be achieved by adding additional Cucumber options such as sync features and auto-complete in the .settings.json file.

  • Add a file ‘settings.json’ inside the ‘.vscode’ folder.
  • Add the below content as per the image.

Now, navigation from feature to step can be done by right-clicking step->Go To Definition or using the F12 key.

Conclusion:

Playwright is now considered a sensational tool for modern web apps. Integration of Cucumber with Playwright attracts a broader audience already using Cucumber with their deprecated tools such as Protractor/Spectron.

Below are some advantages of using Cucumber with Playwright:

  • It helps the business team understand the automation coverage by visiting features written in plain language.
  • Using world/hooks helps to hide the logic related to precondition to the business team, which might reduce confusion.
  • Maximum re-usable code can be achieved.
  • Maintenance will be easier.
  • The feature files can be shared as automation coverage and backups instead of entire logic.
  • Transparent reporting with actual narration in plain language. 

Modernizing QA with life-cycle automation and AI practices to address scale, speed, security and innovation in the cloud is a prerequisite for Digital Transformation.

 

The post Automation using Playwright Library with Cucumber JS. appeared first on Indium.

]]>