测试人社区

selenium-Fresh browser per test


title: “Fresh browser per test”
weight: 9

Start each test from a clean known state.
Ideally, spin up a new virtual machine for each test.
If spinning up a new virtual machine is not practical,
at least start a new WebDriver for each test.
For Firefox, start a WebDriver with your known profile.

FirefoxProfile profile = new FirefoxProfile(new File("pathToFirefoxProfile"));
WebDriver driver = new FirefoxDriver(profile);

官方链接为:https://www.selenium.dev/documentation/en/guidelines_and_recommendations/fresh_browser_per_test