kazurayam / chromedriverfactory

A Java library that enables you to launch Selenium ChromeDriver using an existing user Profile. That let you to carry cookies over multiple HTTP sessions via user Profile.
0 stars 0 forks source link

Add addributes (UserProfile,ProfileDirectoryName,UserDataDir) to a ChromeDriver instance #7

Closed kazurayam closed 2 years ago

kazurayam commented 2 years ago

I can create an instance of ChromeDriver using com.kazurayam.webdriverfactory.chrome.ChromeDriverFactory while specifying

I want to retrieve these attributes out of the ChromeDriver instance. It is useful for various reporting/diagnostics purposes.

I can dynamically add attributes to ChromeDriver instance using Groovy's Metaprogramming Technique.

kazurayam commented 2 years ago

Example

    @Test
    void test_ChromeDriver_metadata_stuffed() {
        ChromeDriverFactory cdFactory = ChromeDriverFactory.newChromeDriverFactory()
        driver = cdFactory.newChromeDriver(new ProfileDirectoryName('Default'))
        assertNotNull(driver)
        assertTrue(driver.userProfile.isPresent())
        assertTrue(driver.userDataAccess.isPresent())
        driver.userProfile.ifPresent({ ChromeUserProfile up ->
            println up
            assertEquals(new UserProfile("Kazuaki"), up.getUserProfile())
            assertEquals(new ProfileDirectoryName("Default"), up.getProfileDirectoryName())
            assertTrue(Files.exists(up.getUserDataDir()))
            // e.g, "/Users/kazurayam/Library/Application Support/Google/Chrome"
        })
    }