Automate Your Web Testing with Ease
Mendix applications are built to run smoothly across various web browsers. For developers working with Mendix, a leading low-code development platform, integrating comprehensive testing frameworks like Playwright can significantly enhance the quality of their applications. This article explores why and how Playwright can be integrated into Mendix applications.
Testing applications is crucial for maintaining their robustness and reliability. By incorporating unit tests, integration tests, end-to-end tests, performance tests, and cross-browser tests, developers can ensure their applications are functional, performant, and deliver a seamless user experience. Leveraging tools like Playwright enhances the testing process, allowing developers to identify issues early and deliver high-quality Mendix applications.
We will integrate Playwright into Mendix and after that we will be able to run playwright scripts directly from Mendix.
One may use the setup to preproduction checks of the application or use the setup to leverage other test processes. This configuration lets you automate your playwright scripts and leverage your playwright portfolio using Mendix.
In order to do that, we will first retrieve Playwright Maven dependencies.
Retrieving Playwright Maven Dependencies into JAR Files in Eclipse IDE
Setting Up Your Eclipse Project
- Create a Maven Project in Eclipse:
- Open Eclipse IDE.
- Go to File > New > Other > Maven > Maven Project.
Click Next and choose a workspace location. Select an archetype, such as maven-archetype-quickstart, and click Next.
- Fill in the group ID, artifact ID, and other project details, then click Finish.
- Add Playwright Dependency:
- Open the
pom.xml
file in your project. - Add the Playwright dependency inside the dependencies section.
<dependencies>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.45.0</version>
</dependency>
</dependencies>
Save the jar files to use inside Mendix.
Using JAR Files in Mendix
To extend your Mendix application with custom Java functionality or third-party libraries, follow these steps to use JAR files effectively.
1. Navigate to the root folder of your Mendix project. Find the userlib
directory and Copy the saved JAR files into the userlib
directory.
2. Create and Use Custom Java Actions
- Add a New Java Action:
- In Mendix Studio Pro, go to
Project Explorer
. - Right-click on
Java Actions
and selectAdd Java Action
. - Define the action’s name, parameters, and return type.
- Write Java Code:
- Click
Edit Java Code
to open the Java editor. - Import and use classes from your JAR files. Example:
package playwright.actions;
import com.microsoft.playwright.*;
import com.microsoft.playwright.options.AriaRole;
import java.util.regex.Pattern;
import com.mendix.core.Core;
import com.mendix.logging.ILogNode;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
public class JavaTest extends CustomJavaAction<java.lang.Void>
{
public JavaTest(IContext context)
{
super(context);
}
@java.lang.Override
public java.lang.Void executeAction() throws Exception
{
// BEGIN USER CODE
ILogNode LOG = Core.getLogger("Playwright");
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch();
Page page = browser.newPage();
page.navigate("https://ardakirankaya.com/");
LOG.info(page.title());
}
return null;
// END USER CODE
}
/**
* Returns a string representation of this action
* @return a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "JavaTest";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}
Save and compile your Java action and use it in your Mendix microflow.
Conclusion
Integrating Playwright with Mendix allows developers to harness the power of Playwright’s automation capabilities while working with Mendix. With Playwright’s robust features and Java’s widespread use in enterprise environments, this combination offers a powerful solution for automated web testing. By following the setup and examples provided, you can start leveraging Playwright inside Mendix to ensure the quality and reliability of your web applications or even use it as a web based Robotic Process Automation tool.