How to run a Java Selenium test on an incognito Google Chrome profile

本小妞迷上赌 提交于 2021-02-17 06:43:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!