The code compiles fine, but the test
selenium-rc\server-coreless\src\test\java\org\openqa\selenium\...
...server\browserlaunchers\BrowserLauncherFactoryUnitTest.java
fails during testing GoogleChromLauncher
GoogleChromeLauncher.java tries to obtain location of Chrome executable
from Windows Registry using WindowsUtils.getLocalAppDataPath():
protected String[] usualWindowsLauncherLocations() {
return new String[]{
WindowsUtils.getLocalAppDataPath() + "\\Google\\Chrome\\Application"
};
}
The method WindowsUtils.getLocalAppDataPath() uses REG.EXE executable to get
the value of the following Registry Key:
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Local AppData"
The Value is expected to look something like this:
%USERPROFILE%\Local Settings\Application Data
However, due to specifics (or bugs) of REG.EXE on Windows 2003 Server platform
the REG.EXE fails to return keys if they contain unresolved environment variables.
The Listing 1 shows the output or REG.EXE when executed from command line. The
REG.EXE fails, because all values contain unresolved %USERPROFILE% like this:
AppData = %USERPROFILE%\Application Data
Desktop = %USERPROFILE%\Desktop
Local AppData = %USERPROFILE%\Local Settings\Application Data
Personal = %USERPROFILE%\My Documents
– Listing 1 ------------------------------------------------------------------
C:\>reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Local AppData"
ERROR: More data is available.
-------------------------------------------------------------------------------
The Listing 2 shows that when Key values don't have unresolved %VARIABLE% referenses
the REG.EXE behaves as expected producing valid output:
AppData = C:\Documents and Settings\mlyubkin\Application Data
Desktop = C:\Documents and Settings\mlyubkin\Desktop
Local AppData = C:\Documents and Settings\mlyubkin\Local Settings\Application Data
Personal = C:\Documents and Settings\mlyubkin\My Documents
— Listing 2 (OK) ------------------------------------------------------------
C:\>reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Local AppData"
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
Local AppData REG_SZ C:\Documents and Settings\mlyubkin\Local Settings\Application Data
-------------------------------------------------------------------------------
This behavior of REG.EXE was verified on three different Windows 2003 Server machines
and appears to be specific to Windows 2003 Server platform only.
There was no problem with REG.EXE on Windows XP and Windows Vista.
===============================================================================
Suggested FIX:
===============================================================================
I would recommend reading different Registry Key to obtain "Local AppData":
Old Key:
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Local AppData"
New Key:
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Local AppData"
You can see that the "New Key" has all the values the "Old Key" has but there's no
%VARIABLE% substitutions - all Values are already resolved. This allows to simpify
the getLocalAppDataPath() method and rewrite it as follows:
-------------------------------------------------------------------------------
server-coreless/org/openqa/selenium/server/browserlaunchers/WindowsUtils.java
---Old Method -----------------------------------------------------------------
/** Returns the path to Local AppData. For different users, this will be
- different.
- @return the path to Local AppData
*/
public static String getLocalAppDataPath() Unknown macro: { loadEnvironment(); final String keyLocalAppData = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Local AppData"; String localAppDataPath = readStringRegistryValue(keyLocalAppData); String userProfile = getEnvVarIgnoreCase("USERPROFILE"); if (userProfile != null) {
return localAppDataPath.replace("%USERPROFILE%", userProfile);
} return localAppDataPath; }
---New Method -----------------------------------------------------------------
public static String getLocalAppDataPath() {
loadEnvironment();
final String keyLocalAppData =
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Local AppData";
String localAppDataPath = readStringRegistryValue(keyLocalAppData);
return localAppDataPath;
}
-------------------------------------------------------------------------------
With the fix applied the BrowserLauncherFactoryUnitTest passed on all three platforms:
Windows XP, Windows Vista, and Windows 2003 Server.