Hey everyone,
I’m trying to figure out how to run just one Selenium test through the command line in Play Framework. I know I can do it through the browser UI, but I’m looking for a CLI solution.
Right now, when I use play auto-test
, it runs all my Selenium and JUnit tests. But what if I only want to validate a specific Selenium test using a headless browser?
Is there a way to instruct Play to execute just that test from the command line? It would be a huge time-saver for quick checks without running the full suite.
Thanks in advance for any insights!
yo, ive run into this before. try using sbt’s test:testOnly command. like this:
sbt “test:testOnly *YourTestName”
just replace YourTestName with ur actual test class. for headless, make sure u set up ur webdriver right. works like a charm for me when i need to run just one test quick
Having worked extensively with Play Framework and Selenium, I can offer a solution that’s worked well for me. You can leverage TestNG to run specific tests. First, ensure you have TestNG dependencies in your build.sbt file. Then, create a TestNG XML file specifying the test you want to run. For example:
Now, you can run this specific test using the command:
sbt “test-only – -testng.configurator org.testng.TestNG -testngxml path/to/your/testng.xml”
This approach gives you fine-grained control over test execution from the CLI, saving considerable time during development and debugging cycles.
I’ve been in a similar situation and found a workaround that might help. Instead of running all tests via ‘play auto-test’, you can use SBT (which Play Framework relies on) to run a specific test. Try executing the command:
sbt ‘testOnly *YourSpecificTestName’
Replace ‘YourSpecificTestName’ with the actual name of your Selenium test. For headless testing, be sure to configure your WebDriver appropriately. For example, if you’re using ChromeDriver, you can set it up like this:
ChromeOptions options = new ChromeOptions();
options.addArguments(“–headless”, “–disable-gpu”, “–no-sandbox”);
WebDriver driver = new ChromeDriver(options);
This approach allows you to quickly verify a single test without running the whole suite, which can save a lot of time when making frequent changes.