Forward slashes in RunConfiguration.getProjectDir cause issues

Hello,

Forward slashes are used in RunConfiguration.getProjectDir() project path - it had been working in the past, but it doesn’t in latest ChromeDriver version. Now, every download fails when using this method as a part of custom download path.

POC:

RunConfiguration.getProjectDir() + "\\Data Files" <--- not working
RunConfiguration.getProjectDir() + "//Data Files" <--- not working


RunConfiguration.getProjectDir().replace("/", "\\") + "\\Data Files" <--- working

There may be easy fix - add overloaded getProjectDir(boolean isBackslash) method which would accept boolean parameter - to use or not to use backslash.

@Marek_Melocik you may want to add OS detection too in the workaround.
On linux and mac most probably will require forward slashes.

I thought this is handled automaticaly (or at least it was in the past)
Nice catch!

I would avoid using / and \ as file path separator at all.

Using Java8 Path API, you can write code without / and \ at all. See the following example.

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

String projectDir = RunConfiguration.getProjectDir()
Path projectPath = Paths.get(projectDir)
Path dataFilesPath = projectPath.resolve('Data Files')   // you do not need / and \ here
File dataFilesDir = dataFilesPath.toFile()
// use dataFilesDir as you want

This code is OS-independent. This would work on Windows, Mac and Linux without any change.

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.