A Unified Browser Automation Tool for Test Automation
Selewright brings together the best of Selenium and Playwright, allowing you to write browser automation code once and run it on either framework without any code changes.
- β Write Once, Run Anywhere: Code once and execute with either Selenium or Playwright
- π Future-Proof: Easily adopt new browser automation frameworks under the Selewright umbrella
- π― Focus on Business Logic: Selewright handles the complexities while you focus on your test scenarios
- π οΈ Built-in Conveniences: Automatic waits, POJO setup to mock APIs triggered by browser frontend, boilerplate code handling
- π§ No Tool Lock-in: Switch between automation tools without rewriting your tests
- Project Structure
- Quick Start
- Installation
- Usage
- Core Methods
- Migration Guide
- Contributing
- Acknowledgements
- Roadmap
- Issues and Support
selewright/
βββ src/
β βββ main/java/com/redbus/selewright/
β β βββ Selewright.java # Core interface for browser automation tools
β β βββ PlaywrightImplementation.java # Implements Selewright methods using Playwright
β β βββ SeleniumImplementation.java # Implements Selewright methods using Selenium
β β βββ RequestConditionsToMock.java # POJO to define request conditions for APIs invoked by browser frontend
β β βββ MockResponseToSend.java # POJO to define mock responses for APIs invoked by browser frontend
β β βββ OtherHelpers.java # Utility functions for common test automation tasks
β βββ test/java/
β βββ demo.java # Demonstrates sample setup and usage of Selewright
Note: We recommend Playwright for tests which involve fetching or mocking APIs invoked by the browser frontend. The corresponding methods in
SeleniumImplementationare left unimplemented as Selenium currently supports network interception only in Chrome via the DevTools Protocol.
- Java 8 or higher
- Maven 3.6+
- Git
-
Clone the repository
git clone https://github.com/redbus-labs/selewright.git cd selewright -
Run the demo
cd src/test/java javac demo.java java demo
-
Download the JAR (Coming soon on Maven Central Repository)
Download
selewright-1.0-SNAPSHOT.jarand place it in your project root. -
Add to your
pom.xml<dependency> <groupId>com.redbus</groupId> <artifactId>selewright</artifactId> <version>1.0-SNAPSHOT</version> <scope>system</scope> <systemPath>${basedir}/selewright-1.0-SNAPSHOT.jar</systemPath> </dependency> <!-- Selenium dependency --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.35.0</version> </dependency> <!-- Playwright dependency --> <dependency> <groupId>com.microsoft.playwright</groupId> <artifactId>playwright</artifactId> <version>1.55.0</version> </dependency> <!-- Appium (for mobile web testing) --> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>10.0.0</version> </dependency>
Note: You are free to use any version of Selenium or Playwright. However, make sure the Appium version you choose is compatible with your Selenium version.
For more details, refer here.
import com.microsoft.playwright.*;
import com.redbus.selewright.PlaywrightImplementation;
import com.redbus.selewright.SeleniumImplementation;
import com.redbus.selewright.Selewright;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
/**
* A demo class to showcase the usage of Selewright with both Selenium and Playwright
*/
public class Demo {
public static void main(String[] args) {
Selewright selewright = null;
try {
selewright = setupSelewright("playwright");
boolean result = runSampleTest(selewright);
System.out.println("Test Verification: " + result);
} finally {
if (selewright != null) {
selewright.closeBrowser();
}
}
}
/**
* Setup Selewright with either Selenium or Playwright based on the input parameter
* @param automationTool - "selenium" or "playwright"
* @return Selewright instance
*/
private static Selewright setupSelewright(String automationTool) {
if ("selenium".equalsIgnoreCase(automationTool.trim())) {
WebDriver driver = new ChromeDriver();
return new SeleniumImplementation(driver);
} else if ("playwright".equalsIgnoreCase(automationTool.trim())) {
Playwright playwright = Playwright.create();
Browser browser = playwright.chromium()
.launch(new BrowserType.LaunchOptions().setHeadless(false));
BrowserContext context = browser.newContext();
Page page = context.newPage();
return new PlaywrightImplementation(page);
}
throw new IllegalArgumentException("Invalid tool: " + automationTool);
}
/**
* A sample test to demonstrate the usage of Selewright
* Selects 'selewright' repository on redbus-labs GitHub and verifies readme file presence
* @param selewright
* @return
*/
private static boolean runSampleTest(Selewright selewright) {
selewright.openUrl("https://github.com/orgs/redbus-labs/repositories");
selewright.click("//a[@href='/redbus-labs/selewright']");
return selewright.isDisplayed("(//a[@href='/redbus-labs/selewright/blob/main/README.md'])[last()]");
}
}Refer Selewright-Interface for complete method list with Javadocs.
If you have an existing Selenium helper class:
Before:
public void click(String locator) {
driver.findElement(By.xpath(locator)).click();
}After:
public void click(String locator) {
selewright.click(locator);
}Similar migration process - replace your Playwright-specific code with Selewright method calls.
We welcome contributions from the community! This project can only evolve with open source contributions.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please read our Contributing Guidelines before submitting contributions.
- Clone the repository
- Import into your IDE
- Run tests to ensure everything works
- Start coding!
- Krishna Hegde, Senior SDET, redBus
- Chandrashekar Patil, Senior Director - QA, redBus
- Eesha Karanwal, SDET Engineering Manager, redBus
- Smruti Sourav Sahoo, SDET
- Shon Noronha, SDET
- Anuj Gaur, SDET
- Ayan Ray, Senior SDET
- Varun Singhai, Senior SDET
- Shravya Acharya, SDET
- Pooja Benni, Senior QA
- Sowmya Acharya, SDET
- Support for additional programming languages (Python, JavaScript, C#)
- Selewright MCP
- Support for additional browser automation frameworks
Found a bug or need help? Please open an issue on GitHub.