Automation Using Playwright – Part 2
Introduction: Playwright is an open-source automation tool that allows developers to write reliable and efficient browser automation scripts. In Dynamics 365 implementation projects, automated end-to-end testing plays a crucial role, streamlining the process by rapidly validating code, replicating business workflows, and expediting code deployment with enhanced reliability. In the past, configuring automated tests has proven to be a challenging task. This article aims to introduce Playwright as a solution for end-to-end automation testing specifically tailored for Dynamics 365 Customer Service. The Playwright Library offers a unified set of APIs for browser management and interaction, while Playwright Test further enhances the experience by introducing a comprehensive, fully managed end-to-end test runner. It was developed by Microsoft for automating web browsers to provide a better alternative to other automation tools. Advantages Of Playwright: Playwright Architecture: Playwright works on Web socket connection protocol, it means once you will trigger the test, the code will be converted into JSON format and will be sent to the server using Web socket protocol. Browser Contexts: Playwright operates within the concept of browser contexts. A browser context represents an isolated environment within a browser instance. You can think of it as a separate tab or window in a browser. Each browser context has its own cookies, local storage, and session state. This isolation allows for parallel test execution and prevents interference between different automation tasks. Browser: Browser is encapsulated in a separate browser instance. You can launch multiple browser instances simultaneously. Playwright takes care of downloading and managing the appropriate browser binaries for you. Browser and Page Instances: Within a browser instance, you can create multiple page instances. A page corresponds to a single tab in a browser. Each page has its own DOM, network, and JavaScript context. Drivers: Playwright uses a driver architecture to communicate with browsers. Each browser has its own driver, which is responsible for controlling the browser and executing commands. The drivers interact with the browser’s protocol to perform actions and retrieve information. Protocol Clients: Playwright uses Protocol Clients to communicate with the DevTools protocol of the underlying browsers. These clients are responsible for sending and receiving messages between Playwright and the browser. Protocol Clients enable Playwright to control browser behavior and retrieve data from the browser, such as DOM structure, network activity, and more. Language Bindings: Playwright provides language-specific bindings for JavaScript, Typescript, Python, and C#. These bindings allow you to write automation scripts in your preferred programming language. (Typescript is the most recommended way though) The language bindings provide a high-level API that abstracts away the complexities of interacting with the browser’s Dev Tools Protocol. Automation Scripts: You write automation scripts using Playwright’s API in your chosen programming language. These scripts can perform various tasks such as navigating to web pages, interacting with page elements, filling out forms, capturing screenshots, and more. The scripts execute commands through the language bindings, which in turn communicate with the appropriate Protocol Client and browser driver. Cross-Browser and Cross-Platform: Playwright is designed to work consistently across different browsers and platforms, making it a powerful choice for cross-browser testing and automation. Comparison with other popular automation tools: Playwright, with its cutting-edge design and powerful capabilities, stands as the pinnacle of modern web automation tools, surpassing even the most popular alternatives like Selenium and Cypress. Here’s why Playwright shines as the preferred choice for browser automation: Unmatched Cross-Browser Versatility: Playwright effortlessly outperforms its competitors with its support for multiple browsers, including Chromium, Firefox, and Web Kit. This breadth of compatibility makes it the unbeatable champion for cross-browser testing, ensuring your web applications work seamlessly across various browser environments. Sleek, Multi-Language Compatibility: Playwright offers an elegant solution for developers of all backgrounds, with language bindings available in JavaScript, Python, and C#. This flexibility empowers you to harness the power of automation using the language you’re most comfortable with, amplifying your productivity. Swift, Asynchronous Automation: Say goodbye to slow, outdated automation scripts. Playwright embraces the future with its asynchronous approach, effortlessly handling complex web interactions with grace. This modern pattern allows you to create efficient, high-performance automation scripts that execute tasks with unrivaled speed. Stability through Isolation: Playwright’s architecture brings stability to your automation endeavors by providing isolated browser contexts. This innovative feature shields your tests from external interference, ensuring the reliability of your automation suite even in the most demanding scenarios. Incomparable Speed and Efficiency: When it comes to execution speed and efficiency, Playwright leaves its competition in the dust. Thanks to its exceptional performance optimization, your automation tasks complete swiftly and effortlessly, keeping your testing and development processes on the fast track to success. Future-Proofed Technology: Playwright’s commitment to staying at the forefront of browser automation technology means you’ll always have access to the latest features and capabilities. Its continuous development and frequent updates ensure that you’re equipped to tackle any automation challenge that arises. Conclusion: Playwright emerges as the premier choice for modern web automation, surpassing its peers with its cutting-edge features and exceptional capabilities. With unrivaled cross-browser support, multi-language compatibility, lightning-fast asynchronous automation, and stability through isolation, Playwright empowers developers and testers to achieve superior results efficiently and effectively. Its commitment to staying at the forefront of technology ensures that you’ll always be equipped to tackle the evolving challenges of web automation. Choose Playwright to elevate your automation efforts and embrace the future of web automation. Thank you, Aditya for your valuable inputs!!
Automation Using Playwright-Part 1
Prerequisites: Visual Studio Code: Ensure you have Visual Studio Code installed on your machine. You can download it from the official website: https://code.visualstudio.com/download Node.js: Ensure you have Node.js installed on your machine. You can download it from Node.js official website. https://nodejs.org/en/download To check if the node installation is completed: Playwright project setup: Here you go, playwright has been successfully installed for your project. Opening the project in VSCode: In a default Playwright project, the folder structure is typically simple and flexible, allowing you to organize your automation scripts, configuration files, and other resources according to your needs. Let’s break down each component of this folder structure: It will contain an example.spec.ts file to refer to how a test file normally looks like Run the example test file: npx playwright show-report Your report will be generated and will open automatically in a browser and will something like shown in the above image. You can expand each of the tests and view the execution in detail. Config file walkthrough: This playwright.config.ts file is a central place to specify test-related settings, such as test directories, test reporters, test execution modes, and more. We’ll have a look at it in detail: Imports: The configuration file imports necessary modules from Playwright Test to define the configuration. Environment Variables (Optional): It includes the option to read environment variables from a file (using dotenv) if you need to set environment-specific configuration. Configuration Object: defineConfig() is used to define the Playwright Test configuration object. testDir: Specifies the directory where your test files are located. In this example, it’s set to ‘./tests’. Parallel Execution: fullyParallel allows running tests in parallel for improved performance. CI-Specific Configuration: forbidOnly and retries are configured based on whether the tests are running on a Continuous Integration (CI) environment. It forbids the use of ‘test.only’ and retries failed tests on CI. Number of Workers: The workers setting defines the number of workers for parallel execution, using one worker locally and potentially more on CI. Test Reporter: Specifies the test reporter format, in this case, ‘html’. Shared Settings: The use object contains shared settings for all test projects. For example, you can set a base URL for your tests. Test Projects: The projects array defines different test projects for different browsers (Chromium, Firefox, WebKit, etc.). Each project can have its specific configuration, such as browser settings. Local Development Server (Optional): The webServer section allows you to run a local development server before starting tests. This is useful for testing against a locally hosted web application. Feel free to customize and adapt this configuration file to your specific testing needs. You can uncomment and modify sections as necessary, depending on your project’s requirements and testing environment. You can start using Playwright with Typescript in this manner. I hope this makes it easier for you to set up and begin using Playwright without any worries. Thank you, Aditya for your valuable inputs for the blog.
Now Import Projects from Microsoft Project Desktop Client in Project Operations
Problem Definition: In contrast to Project Service Automation, where importing projects is made easy via a ribbon button, it was previously not possible for current Microsoft Project Desktop Client users to do so in D365 Project Operations. Project for the Web is supported by D365 Project Operations, although not all of Microsoft Project Desktop Client’s features are available. It was imperative to establish a connection between the two due to the system’s gap. Solution: Steps to import a file in Project Limitations: Project for the Web works well for the majority of projects, but it doesn’t totally replace Project desktop. The following features cannot be migrated or supported. Before you begin importing your project, make sure it doesn’t rely on these features. Cross-project dependencies, manual tasks, recurring tasks, subprojects, and even some types of selective constraint types like As late as possible, Start no later than, Finish no later than, etc. are a few characteristics. There are many such features which are not supported while importing. Refer given Microsoft link for more information: https://support.microsoft.com/en-us/office/move-your-project-from-project-desktop-to-project-for-the-web-143ab391-002e-451a-aedb-3b6fa1f6ab8b#bkmk_featuresthatdontmigrate Conclusion: Users will have the freedom to utilise any project planning tool of their choice, including Project Desktop Client and Project for the Web, thanks to this import feature. This functionality is a good complement to all the other functionalities in the product and will help D365 Project Operations meet more customer requests. Thank you, Sankalp for your valuable inputs.
Project Operations vs Project Service Automation, A Seamless Comparison to Read
We know that PSA is now known as Project Operations. Well, it’s not just a name change but also some significant improvements that Microsoft has brought in. The following blog will take you through the differences between PSA and Project Operations. The upgrade from Project Service Automation to Project Operations is going to be delivered in three phases. Below are the major changes which will be seen after the upgrade is complete. In this phase, the dependency on WBS has been cut off for projects. With all the modifications from phase 1, we even have WBS that is a part of the project operations limits that are currently supported In addition to the enhancements from phase 2, WBS also includes support for the Project desktop client and extends beyond the present scope of Project Operations. Let’s delve deep in feature wise comparison between PSA and Project Operations. 1] Project Templates: They help you generate the WBS structure from an already pre-defined WBS structure in the form of a template. Project Service Automation: ✔️ Included You can create a project template as shown in below image in PSA: After saving this record, you can add the record while creating a new project as shown in the below image. You can also select ‘Is Template’ field to save the current project as a project template. Project Operations: Not included This feature is not included in Project Operations, but the same functionality can be done with the ribbon button on the Project form named ‘Copy Project’. With this all the task information and the project properties get copied in a new draft project. 2] Project work breakdown structure (WBS) integration with desktop client: A project management tool with automated scheduling, resource management, and built-in reporting is Microsoft Project Online desktop client. Project Service Automation: ✔️ Included This feature is very essential in PSA as with the capabilities of desktop client, Task management can be done efficiently. There is a ribbon button to integrate the system as shown: Project Operations: Not included This feature is not there in Project Operations as it has OOB integration with Project for the web. 3] Constraints – Start no earlier than, finish no later than: When you add a constraint on the tasks it forces you to start or end on that date even if the schedule is changed. Constraint is very useful, but one needs to be careful about the dates Project Service Automation: Not included This is not available in Project Service Automation and is possible if integrated with Project Desktop Client. Project Operations: ✔️ Included This feature restricts the resource to complete the task start and finish the task in the given time. When a constraint is set your calendar icon gets a cross sign stating that it is restricted. Example: If you select Constraint type as ‘Finish No Later Than’ and the Finish date is set as 3rd February 2023. The task then needs to be completed by the specified date. 4] Milestones – Tasks with zero duration: Milestones are key points in the project timeline and serve as markers to indicate that certain objectives have been met and provide an opportunity to review and assess progress. Milestones are typically used to track the progress of a project, to communicate with stakeholders, and to help manage risks. Project Service Automation: Not Included This feature is not available in PSA and is exclusively available in Project Operations Only. Project Operations: ✔️ Included Adding a milestone task with zero duration is now possible in Project Operations unlike PSA. Just add ‘0’ in the duration field and set same start and finish date as shown below: And now the milestone symbol can be seen as shown in the below image: 5] Resource driven tasks will respect the availability of assigned resources Resource-driven tasks are scheduled based on the availability of the resources assigned to them. This means that the start and end dates of a task are determined by the availability of the necessary human, equipment, or material resources. This helps ensure that tasks are completed efficiently and within the given time frame. Project Service Automation: Not Included This feature is not available in Project Service Automation. Project Operations: ✔️ Included The system considers the availability of resources when scheduling tasks and adjusts task dates accordingly. This helps ensure that projects are completed on time and within budget, and that resources are utilized efficiently. It takes into consideration the work hour template of the assigned resources and changes the Start and Finish date according to the availability. 6] Time-phased editing – Edit plans and work on a day-by-day basis This feature provides a detailed view of the project schedule, with tasks and their associated work broken down into daily increments. This level of granularity enables project managers to adjust the project schedule based on daily progress and to account for changes in resource availability or task dependencies. Project Service Automation: ✔️ Included With the help of this feature, we can change the efforts on the resource assignments grid on a day-by-day basics and even by week or month. This makes work easy as changes can be done on the grid itself. Project Operations: Not Included This feature is not yet added in the Project Operations, but we can expect this update in later phases. 7] Automatic/manual scheduling – Use the Project scheduling engine to schedule tasks automatically or manually Project Service Automation: ✔️included The scheduling of tasks for leaf nodes is determined by the task mode. Every activity supported by PSA has two task modes: automatic scheduling and manual scheduling. Automatic Scheduling: Scheduling engine uses the rules on task attributes to determine the schedule for the task. Manual Scheduling: It stops the engine from calculating the values of other scheduling attributes. Project Operations: Not Included This feature is not available in Project Operations. 8] Edit large projects directly in the user interface: There is no limit to the size of plans that are editable Project Service
Advances and Retainers in Project Operations
Problem Definition: Earlier, milestones were used for advance payments which was not the actual purpose of it. But with the introduction of Advances and Retainers, milestones will only be used for their real purpose on fixed price lines. What are Advances and Retainers? The feature Advances and Retainers are seen on the Project Contract form. Advance payment or the retainer fees both means the same. It is used for an advance payment from the customer/client. This feature can be applied on fixed price as well as on time and material contract lines. Solution: Conclusion: This feature is helpful for an organization delivering the project. Because it provides margin to recover the costs incurred due to any increase in scope that a fixed price contract would not have allowed. Thank you, Sankalp for your valuable imputs.
Compressing Image Attached in Notes
Problem Statement: Sometimes user has to upload or attach image inside Notes Section of form. When user uploads any image in Notes, dynamics stores image in Base 64 format. As frequency of uploading/attaching images increase then it will also increase the size requirement in CDS. To reduce the size requirement in CDS, we can compress image while storing it in CDS. Solution: When user attaches Image in Note(annotation), we can trigger Post Operation Async Plugin to Compress Image. When image gets attached to Notes, it gets stored as Base 64 inside “documentbody” field. So, we have to trigger Plugin on ‘Create of Notes’, get Base 64 code of Image, Compress Image and Update New Base 64 Code in Notes. Following Plugin code Converts Base 64 Code to Image format compresses Image without loosing quality and then reconvert it to Base 64 code: Plugin Code: (JPEG) Dynamics store Image attached in Note(annotations) in Base 64 form. Image Body will be stored in “documentbody” field and Image Type will be stored in “mimetype” field. Get Image Body and Image Type using following code: Now, create following method, which will compress Base 64 image. We have to pass Base 64 code and quality to custom method which will be used to compress image. Using this method, we can compress image till 10% – 90%. So, pass Image Quality between 10-90. Add Encoder method in class as it is used in “Base64StringImage” method. Once Base 64 Image Code gets compressed, our method will provide new Base 64 Image Code. Store it in new variable. Now, Update Document Body of Note(annotations) with new Document Body. Plugin Step: After Registering our code as New Plugin Assembly, add Step on Create on annotation (Notes). Make Execution Mode as Asynchronous as there will be chances where multiple users will upload Images as same time. Example: Image with Size: 1465 KB Uploaded Image in Notes: Image After Compression: Conclusion: Using above the plugin on Annotation Entity we can effectively compress image size by 10% to 90%. This will help us to save CDS size. Thanks Mayur Hande for your inputs on this blogs.