如何在Jenkins中禁用无头模式运行WiniumDriver自动化测试
Hey there, let's work through getting your WiniumDriver tests running without headless mode in Jenkins. I’ve tackled similar desktop automation hiccups before, so here’s a straightforward breakdown:
1. Adjust Your Test Code Configuration
First, check if your test code explicitly enables headless mode. Winium uses driver options to control this setting—you’ll want to either remove the headless flag or set it to false:
Example (C#):
var winiumOptions = new WiniumDesktopOptions(); // Either remove this line entirely, or set it to false winiumOptions.Headless = false; // Initialize driver with updated options var driver = new WiniumDriver(@"C:\path\to\winiumdriver.exe", winiumOptions);
Example (Java):
WiniumDesktopOptions options = new WiniumDesktopOptions(); // Disable headless mode explicitly options.setHeadless(false); WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999"), options);
2. Update Jenkins Build Parameters/Commands
If headless mode is being triggered via Jenkins build settings:
- Check build parameters: If you’ve set a parameter like
HEADLESS_MODEtotruein your Jenkins job, edit the job and change its value tofalse. - Modify execution commands: If your build step runs a command that launches WiniumDriver with the
--headlessflag (e.g.,winiumdriver.exe --headless), remove that flag entirely so the command becomes justwiniumdriver.exe.
3. Ensure Jenkins Has Access to a Desktop Session
A common gotcha: Jenkins running as a Windows service might not have access to an active desktop session, even with headless mode disabled. To fix this:
- Open Windows Services, find the Jenkins service, go to the Log On tab.
- Check the box that says "Allow service to interact with desktop".
- Restart the Jenkins service.
- Alternatively, run Jenkins directly from a user session (not as a service) by executing
java -jar jenkins.warin a command prompt while logged into the machine. This ensures the driver can launch visible windows.
4. Validate the Fix
After making these changes, trigger a new Jenkins build. Check the build logs for any errors, and verify that the WiniumDriver launches the target application in a visible window (you might need remote desktop access to the Jenkins machine to confirm this).
内容的提问来源于stack exchange,提问作者CelsoRicardo

