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

ChromeDriverFactoory#newChromeDriver(ProfileDirectoryName) works but slow #8

Closed kazurayam closed 2 years ago

kazurayam commented 2 years ago
ChromeDriverFactory cdFactory = ChromeDriverFactory.newChromeDriverFactory()
ChromeDriver driver = cdFactory.newChromeDriver(new ProfileDirectoryName('Default'))

It takes 30 seconds to launch Chrome browser while specified with ProfileDirectoryName. When no argument specified, Chrome opens in 5 seconds.

kazurayam commented 2 years ago

added ChromeDriverFactoryTest#test_speed()

kazurayam commented 2 years ago

In ChromeDriverFactoryImpl, we are copying a lot of files. This would take 20 seconds or so.

private ChromeDriver launchChrome(ChromeUserProfile userProfile,
                                      Path originalProfileDirectory,
                                      Path userDataDir,
                                      ProfileDirectoryName profileDirectoryName,
                                      UserDataAccess instruction) {
        if (instruction == UserDataAccess.TO_GO) {
            // create a temporary directory with name "User Data", into which
            // copy the Profile directory contents from the Chrome's internal "User Data",
            // this is done in order to workaround "User Data is used" contention problem.
            userDataDir = Files.createTempDirectory("User Data")
            Path destinationDirectory = userDataDir.resolve(profileDirectoryName.getName())
            FileUtils.copyDirectory(
                    originalProfileDirectory.toFile(),
                    destinationDirectory.toFile())
            logger_.info("copied ${originalProfileDirectory} into ${destinationDirectory} ")
        } else {
            logger_.debug("will use ${originalProfileDirectory} ")
        }

I should minimise the amount of copies.

kazurayam commented 2 years ago

I have got the following message

[Test worker] INFO com.kazurayam.webdriverfactory.chrome.ChromeDriverFactoryImpl - copied 26913 files from /Users/kazuakiurayama/Library/Application Support/Google/Chrome/Default into /var/folders/7m/lm7d6nx51kj0kbtnsskz6r3m0000gn/T/__user-data-dir__8354836740741382681/Default 

It copied 26913 files!

The Default profile directory contains this many files!

kazurayam commented 2 years ago

Another case

[Test worker] INFO com.kazurayam.webdriverfactory.chrome.ChromeDriverFactoryImpl - copied 674 files from /Users/kazuakiurayama/Library/Application Support/Google/Chrome/Profile 1 into /var/folders/7m/lm7d6nx51kj0kbtnsskz6r3m0000gn/T/__user-data-dir__1264775796246643911/Profile 1 

The profile directory Profile 1 contained just 647 files. Chrome browser launched quickly.

kazurayam commented 2 years ago

So, it really depends which User Profile you specify to launch Chrome with.

I have a user profile "Kazuaki", which is mapped to the profile directory "Default". This directory contains 26000+ files. When I specify this user profile, it takes 30 seconds to copy 26000 files.

When I specify other profile ("Picasso" for example), it contains small number of files to copy and Chrome will launch quickly

kazurayam commented 2 years ago

I changed ChromeDriverFactoryTest so that it does not use the profile directory "Default". Instead it use "Profile 1". By this channge, the test runs far quickly, and is satisfactory.

Only one test method test_ChromeDriver_metadata still use "Default" profile directory.