Skip to content

[Feature]: Selenium Migration to Power Fx Function extension #522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Grant-Archibald-MS opened this issue Jan 9, 2025 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@Grant-Archibald-MS
Copy link
Contributor

Grant-Archibald-MS commented Jan 9, 2025

Is your feature request related to a problem? Please describe.

Many organizations have made significant investments in Selenium for automated testing, and it is essential to leverage these existing test components within the Power Apps Test Engine.

Describe the solution you'd like

Propose adding migration guidance and samples for integrating Selenium-based test components into the Power Apps Test Engine. This would allow users to utilize their existing Selenium tests, which are often written in Java, within the Test Engine.

This guidance could cover steps migrating these tests to Playwright and a language bridge from Java to C# would also be beneficial to facilitate a smooth transition.

It could cover:

  • Login / Security model code can be removed as handled via Test Engine
  • Page navigation and start up model handled by Test Engine
  • Changes from WebDriver to Playwright Page
  • .Net to Java Interop
  • Extensions using No cliffs extensibility model

Describe alternatives you've considered

No response

Additional context?

No response

@Grant-Archibald-MS Grant-Archibald-MS added the enhancement New feature or request label Jan 9, 2025
@Grant-Archibald-MS
Copy link
Contributor Author

Consider the following possible case

mport org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class PowerAppAutomation {
    public static void main(String[] args) {
        // Set the path to the ChromeDriver executable
        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

        // Initialize the ChromeDriver
        WebDriver driver = new ChromeDriver();

        try {
            // Navigate to the Power App URL
            driver.get("https://powerapps.microsoft.com");

            // Call the runTest method with the open driver
            runTest(driver);
        } finally {
            // Close the browser
            driver.quit();
        }
    }

    public static void runTest(WebDriver driver) {
        // Example interaction: Find and click a button
        WebElement button = driver.findElement(By.id("button-id"));
        button.click();

        // Example interaction: Enter text into a text field
        WebElement textField = driver.findElement(By.id("text-field-id"));
        textField.sendKeys("Sample text");

        // Add more interactions as needed
    }
}

Which might be something similar to the following with Playwright

import com.microsoft.playwright.*;

public class PowerAppAutomation {
    public static void main(String[] args) {
        try (Playwright playwright = Playwright.create()) {
            Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
            BrowserContext context = browser.newContext();
            Page page = context.newPage();

            // Navigate to the Power App URL
            page.navigate("https://powerapps.microsoft.com");

            // Call the runTest method with the open page
            runTest(page);

            // Close the browser
            browser.close();
        }
    }

    public static void runTest(Page page) {
        // Example interaction: Find and click a button
        page.click("#button-id");

        // Example interaction: Enter text into a text field
        page.fill("#text-field-id", "Sample text");

        // Add more interactions as needed
    }
}

Assuming that page navigation and authentication is done using Test Engine the following class

public class PowerAppAutomation {
    public static void runTest(Page page) {
        // Example interaction: Find and click a button
        page.click("#button-id");

        // Example interaction: Enter text into a text field
        page.fill("#text-field-id", "Sample text");

        // Add more interactions as needed
    }
}

Given this class is already public and static it could be called via a No cliffs extensibility model. For example using JNI

using System;
using System.Runtime.InteropServices;

class Program {
    [DllImport("jvm.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int JNI_CreateJavaVM(out IntPtr pvm, out IntPtr penv, IntPtr args);

    static void Main(string[] args) {
        IntPtr jvm, env;
        JNI_CreateJavaVM(out jvm, out env, IntPtr.Zero);

        // Load the Java class and call the method
        IntPtr classHandle = env.FindClass("PowerAppAutomation");
        IntPtr methodId = env.GetStaticMethodID(classHandle, "runTest", "(Lcom/microsoft/playwright/Page;)V");
        // Assuming you have a way to get the Page object
        IntPtr page = ...; // Obtain the Page object

        env.CallStaticVoidMethod(classHandle, methodId, page);
    }
}

@Grant-Archibald-MS Grant-Archibald-MS changed the title [Feature]: Selenium Migration [Feature]: Selenium Migration to Power Fx Function extension Jan 9, 2025
@Grant-Archibald-MS
Copy link
Contributor Author

Also could consider Playwrightium

Playwrightium is the implementation of Webdriver interface with Playwright Java inside.
This combination allows us to run Selenide tests with Playwright without rewriting the code.

@aliyoussefi
Copy link

Ideally, Test Engine will be able to handle Selenium and Playwright. As mentioned, significant investment in Selenium by organizations in the past, the present in the future indicate this is needed. Selenium offers features not available in Playwright, and vice versa. Selenium includes a very robust community and is the base for an existing UI automation framework for Dynamics 365.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants