Click here to Skip to main content
15,891,597 members
Articles / All Topics

Speed up Selenium Tests through RAM Facts and Myths

Rate me:
Please Sign up or sign in to vote.
4.82/5 (12 votes)
11 Aug 2015Ms-PL8 min read 18.5K   9  
I have been always curious if I could speed up my UI tests if the browser’s files (cache, profiles) are stored in RAM. When I was starting to test my idea, I was planning to put some majestic headline like […]The post Speed up Selenium Tests through RAM Facts and Myths appeared first on
This is an old version of the currently published technical blog.

I have been always curious if I could speed up my UI tests if the browser’s files (cache, profiles) are stored in RAM. When I was starting to test my idea, I was planning to put some majestic headline like “Speed up Your WebDriver Tests 120% Through RAM”. However, after a full day of hard research work, I found out that I was going to lie to you if I put a headline like this. For my benchmarks, I used all the major browsers- Chrome, Firefox, Internet Explorer and the new Edge. The tests were conducted against Hard Drive, SSD Drive, and RAM Drive. Find below all facts that break down the myth that you could make your browser fly if you put its files on an RAM drive.

<a href="http://i2.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/speed-up-selenium-tests-ram-facts-myths.jpg" ="" title="" rel="prettyPhoto[main]"> Speed Up Selenium Tests Through RAM Facts And Myths

 

So Far in the "WebDriver" Series

1. Getting Started with WebDriver C# in 10 Minutes
2. Most Underrated WebDriver Locator – XPath
3. WebDriver Selenium Tor Integration C# Code
4. Test URL Redirects with WebDriver and HttpWebRequest
5. Microsoft Edge WebDriver- What Everybody Ought to Know About
6. Speed up Selenium Tests through RAM Facts and Myths

Prerequisites for the Research

1. Download and install an RAM Drive Software (for my tests I used a trial version of GiliSoft RAMDisk)

2. Create a virtual RAM Drive (at least 1 GB)

<a href="http://i2.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/how-create-ramdisk.png" ="" title="" rel="prettyPhoto[main]"> How to Create RAM Disk

 

Keep in mind that the program will take a real RAM of your machine so be sure that you have enough before proceeding with the experiments.

Benchmark Selenium Tests Execution Time- Browser’s Files Stored on Hard Drive

All quality performance tests should contain a baseline against the rest of the results are going to be compared. The baseline for this research will be the selenium tests execution time against browsers that store their files on the Hard Drive.

The following code is going to be used to measure the selenium tests speed against different browser configurations.

<script src="https://gist.github.com/angelovstanton/8d764b4d68f6822dd3a8.js"></script><noscript>View the code on Gist.</noscript>

The test itself is straightforward- it only navigates to several URLs. In order WebDriver to wait for a full page load, the code uses the WaitUntilLoaded method. There the page’s document state is waited to be fully loaded though the WebDriver’s IJavaScriptExecuter.

Another fascinating piece of code that is used is the Profile method. First the garbage collector is called to clean up. After that, a stopwatch starts measuring the selenium tests execution time. The specified test is executed a predefined number of times (10). Finally, the results are stored in a file.

Firefox Driver Using Hard Drive

The initial version of the code is using FirefoxDriver. By the way by using the hard drive, I meant that the Firefox is storing all necessary files on the hard disk like cache files and user profiles.

The default folder for Windows is %APPDATA%\Mozilla\Firefox\Profiles\

Selenium Tests Execution Time- 56.112 seconds

Chrome Driver Using Hard Drive

Default Chrome user specific files location- C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default

To use the ChromeDriver, the TestInitialize should be changed a little bit. Also, you need to specify the location of the ChromeDriver.exe in the constructor.

<script src="https://gist.github.com/angelovstanton/689bd074575ab8296e50.js"></script><noscript>View the code on Gist.</noscript>

Selenium Tests Execution Time- 29.174 seconds

Internet Explorer Driver Using Hard Drive

Default Internet Explorer cache locations:

Windows Vista and 7- %userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files

Windows 8- %userprofile%\AppData\Local\Microsoft\Windows\INetCache

To use the InternetExplorerDriver, the TestInitialize should be changed. Also, you need to specify the location of the InternetExplorerDriver.exe in the constructor.

<script src="https://gist.github.com/angelovstanton/763f3a7a094c8baf3ca3.js"></script><noscript>View the code on Gist.</noscript>

Additionally, the test should be modified to be able to pass. Through the usage of InternetExplorerOptions, the InternetExplorerDriver is capable of waiting the pages to be fully loaded. This means that we don’t need the WaitUntilLoaded method anymore.

<script src="https://gist.github.com/angelovstanton/c69e049c8617a95c1d06.js"></script><noscript>View the code on Gist.</noscript>

Selenium Tests Execution Time- 36.324 seconds

Edge Driver Using Hard Drive

To use the InternetExplorerDriver, the TestInitialize should be changed. Furthermore, you can find out how to fully setup the Edge Driver in my article- Microsoft Edge WebDriver- What Everybody Ought to Know About.

<script src="https://gist.github.com/angelovstanton/a9d16f08a6d11572fc92.js"></script><noscript>View the code on Gist.</noscript>

Selenium Tests Execution Time- 14.197 seconds

Benchmark Selenium Tests Execution Time- Browser’s Files Stored on RAM Drive

The same code base is used for these series of tests. However, there is initial setup for every browser in order to move its files to the RAM Drive.

<a href="http://i2.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/ram-drive-speed-up-tests.jpg" ="" title="" rel="prettyPhoto[main]"> RAM Drive Speed up Tests

 

Firefox Driver Using RAM Drive (Cache)

The first test that I performed was with Firefox, which cache files were moved to the RAM Drive.

Steps to Move Firefox Cache to RAM Drive

1. Type about:config into the location bar and press enter.

2. Accept the warning message that appears, you will be taken to a list of preferences.

<a href="http://i1.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/about-config-firefox.png" ="" title="" rel="prettyPhoto[main]"> about:config Firefox

 

3. Right-click somewhere in the list and select “New > String”

<a href="http://i2.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/create-new-string-about-config-firefox.png" ="" title="" rel="prettyPhoto[main]"> Create New String Firefox about:config

 

4. For the name of the preference type browser.cache.disk.parent_directory

5. For its value type the path to where you want to store the cache (path to the RAM Drive)

6. Next locate the preference browser.cache.disk.enable, it must be set to true, if it is not, double-click on it to change its value

<a href="http://i2.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/browser.cache_.disk_.parent_directory.png" ="" title="" rel="prettyPhoto[main]"> browser.cache.disk.parent_directory

 

Selenium Tests Execution Time- 54.713 seconds

Steps to Move Firefox Profiles to RAM Drive

The next phase of the speed up process is to move the Firefox profiles files to the RAM Drive.

1. If Firefox is open, close Firefox.

2. Press Windows +R on the keyboard. A Run dialog will open.

3. In the Run dialog box, type in firefox.exe -P

Note: You can use -P or -ProfileManager (either one should work).

<a href="http://i0.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/firefox-profile-manager-run.png" ="" title="" rel="prettyPhoto[main]"> Firefox Run Profile Manager

 

4. Click OK.

5. Create a new profile and sets its location to the RAM Drive

<a href="http://i1.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/firefox-ram-profile.png" ="" title="" rel="prettyPhoto[main]"> Firefox RAM Profile

 

Selenium Tests Execution Time- 56.856 seconds

Move Firefox Installation, Cache and Profiles to RAM Drive

1. Uninstall Firefox

2. Download it again

3. Choose installation location RAM Drive

<a href="http://i0.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/best-result-from-all-measurements.jpg" ="" title="" rel="prettyPhoto[main]"> Best Result All Measurements

 

With this setup, there was a real improvement of almost 7%. It was the best that I achieved through the usage of the RAM Drive from all tested browsers.

Selenium Tests Execution Time- 48.970 seconds

Chrome Driver Using RAM Drive (Cache)

To set up Chrome to load its cache from the RAM Drive, follow the next steps.

1.  Press Windows+R on the keyboard. A Run dialog will open.

2. Type regedit

3. Locate the Registry key – HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command

You should find a path to the Chrome executable there. All you need to do is to append the cache location and size to the path so that Chrome uses the right caching information when links are clicked, and Chrome is not open at that time.

4. Add –disk-cache-dir=”D:\Browsers-Caches\Chrome-Cache” after chrome.exe, so that it looks like the following:

“C:\Users\aangelov\AppData\Local\Google\Chrome\Application\chrome.exe” –disk-cache-dir=”D:\Browsers-Caches\Chrome-Cache”  — “%1″

<a href="http://i0.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/regedit-chrome-cache-location.png" ="" title="" rel="prettyPhoto[main]"> Regedit Cache Location Chrome

 

The next time when you start Chrome it will load from your RAM Disk.

The execution of the tests against Chrome was the fastest when the cache is stored on the RAM. However, the improvement was only 1%.

Selenium Tests Execution Time- 28.077 seconds

Internet Explorer Driver Using RAM Drive (Cache)

Internet Explorer offers the easiest and most convenient way to change the default cache folder location.

1. Click Tools – Internet Options – under ‘Browsing History’ section

2. Choose ‘Settings’

3. Click ‘Move folder’ and provide the new location, e.g. Z:\IECache

After providing the new temp folder and clicking OK to save the new settings, Internet Explorer forcefully closes the current user session and logs the user off.

<a href="http://i2.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/internet-explorer-change-cache-location.png" ="" title="" rel="prettyPhoto[main]"> Internet Explorer Change Cache Location

 

Instead of speeding up the tests, they were executed even slower compared to the execution when the cached resources were present on the hard drive.

Selenium Tests Execution Time- 36.511 seconds

Benchmark Selenium Tests Execution Time- Browser’s Files Stored on SSD Drive

The setup for the tests against SSD drive is identical to the one against RAM Drive. So I will just share the test execution results.

<a href="http://i2.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/ssd-drive-tests.jpg" ="" title="" rel="prettyPhoto[main]"> SSD Drive Tests

 

Firefox Driver Using SSD Drive (Cache, Profiles, Installation)

Selenium Tests Execution Time- 56.579 seconds

Chrome Driver Using SSD Drive

Selenium Tests Execution Time- 32.273 seconds

Internet Explorer Driver Using SSD Drive

Selenium Tests Execution Time- 33.287 seconds

Test Results Analysis

Below you can find a table with all execution times from the conducted experiments. The average execution time of all browsers is ~41 seconds, so the second column shows the improvement against it. The third column presents the advance of each test against the baseline for every browser that was the test execution on a hard drive.

<a href="http://i1.wp.com/automatetheplanet.com/wp-content/uploads/2015/08/test-execution-drives-table.png" ="" title="" rel="prettyPhoto[main]"> Test Execution Drives Table

 

I think from the above results we can conclude that it is a myth that you can speed up your browser if you move some of its files to an RAM Drive. The same is valid for the SSD drives. As you can see from the picture, there was a real improvement with Chrome and Firefox. However, it is so small that I think it is safe to say that it doesn’t worth the time and resources to deal with it.

Source Code

You can download the full source code from my Github repository.

If you enjoy my publications, feel free to SUBSCRIBEhttp://automatetheplanet.com/newsletter/ Also, hit these share buttons. Thank you!

 

The post Speed up Selenium Tests through RAM Facts and Myths appeared first on Automate The Planet.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
CEO Automate The Planet
Bulgaria Bulgaria
CTO and Co-founder of Automate The Planet Ltd, inventor of BELLATRIX Test Automation Framework, author of "Design Patterns for High-Quality Automated Tests: High-Quality Test Attributes and Best Practices" in C# and Java. Nowadays, he leads a team of passionate engineers helping companies succeed with their test automation. Additionally, he consults companies and leads automated testing trainings, writes books, and gives conference talks. You can find him on LinkedIn every day.

Comments and Discussions

Discussions on this specific version of this article. Add your comments on how to improve this article here. These comments will not be visible on the final published version of this article.