问题
I hope that you're fine. I'm trying to run a certain test on a certain profile but using incognito mode here what I did, it opens the incognito WebDriver of the profile but it doesn't run the test:
import org.openqa.selenium.By;
import org.openqa.selenium.By.ByXPath;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
//import org.openqa.selenium.edge.EdgeDriver;
import org.testng.annotations.Test;
public class AutomationTest {
WebDriver driver;
@BeforeTest
// @BeforeTest
public void setUp() {
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/khadr/AppData/Local/Google/Chrome/User Data");
options.addArguments("profile-directory=Profile 1");
options.addArguments("--incognito");
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
// driver = new ChromeDriver();
driver.get("https://www.rapidtables.com/tools/click-counter.html");
driver.manage().window().maximize();
}
@Test
public void testRegister() throws InterruptedException {
do {
Thread.sleep(3000);
driver.findElement(By.id("addbtn")).click();
} while(true);
}
@AfterTest
public void tearDown() {
// driver.close();
}
}
来源:https://stackoverflow.com/questions/66092093/how-to-run-a-java-selenium-test-on-an-incognito-google-chrome-profile