I have a selenium framework with a BaseTest class. In the BaseTest class we instantiate a ChromeDriver instance which contains various arguments. These are part of the @BeforeMethod (using TestNG). My tests then extend the BaseTest class.
What I want to do for a specific test is to be able to add the --incognito argument to my ChromeDriver instance. How would I go about doing this?
BaseTest code:
public class BaseTest {
protected WebDriver driver;
@BeforeMethod
public void beforeMethod(Method method) {
System.out.println("Running " + this.getClass().getName() + "#" + method.getName());
d = new org.openqa.selenium.Dimension(1350, 660);
if (browser.equals("firefox")) {
System.out.println("Reached FF");
instantiateFirefoxDriver();
} else if (browser.equals("chrome")) {
System.out.println("Reached Chrome");
instantiateChromeDriver();
} else if (browser.equals("safari")) {
System.out.println("Reached Safari");
instantiateSafariDriver();
}
}
private void instantiateChromeDriver() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("disable-plugins");
chromeOptions.addArguments("disable-extensions");
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-dev-shm-usage");
this.driver = new ChromeDriver(chromeOptions);
driver.manage().window().setSize(d);
}
//Some more code......`
Example of a Test Class here:
public class FinanceScholarshipTest extends BaseTest {
private String financeUserUsername = TestUserConfig.STANDARD_USER_USERNAME;
private String financeUserPassword = TestUserConfig.STANDARD_USER_PASSWORD;
private String financeSecondUsername = TestUserConfig.CURRIC_USER_USERNAME;
private String financeSecondUserPassword = TestUserConfig.CURRIC_USER_PASSWORD;
private String studentNo = "1982076";
private CommonNavigation commonNavigation = new CommonNavigation();
private DataGenerationHelper randomData = new DataGenerationHelper();
private FinanceDBQueries dbQueries = new FinanceDBQueries();
@Test
public void shouldGenerateNewScholarshipForCurrentStudent() throws Exception {
// Given
HomePage homePage = commonNavigation.shouldAccessHomepageForSLSTestEnvironment(driver, financeUserUsername, financeUserPassword);
FinanceHomePage financeHomePage = homePage.clickFinanceLink();
// When
ApplicantStudentPage applicantStudentPage = financeHomePage.goToGenrateScholarshipApplicationStudentPage();
// Then
assertThat(applicantStudentPage.selectAcademicYear("1")).isEqualTo(applicantStudentPage.getSelectedAcademicYear());
// Given