Skip to content

Commit 98e4fd8

Browse files
#16 Support {basedir} in service/driverPath
1 parent aa40ef2 commit 98e4fd8

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ string sectionBoolValue = AppConfig.Current.Section.BoolProperty;
354354
"{{driverOptionsPropertyName}}": "value" // Any property of driver specific options (e.g.: ChromeOptions).
355355
},
356356
"service": { // Configures driver service.
357-
"driverPath": "string",
358-
"driverExecutableFileName": "string",
357+
"driverPath": "string", // Sets absolute or relative driver folder path.
358+
// Allows "{basedir}" value at the beginning that equals AppDomain.CurrentDomain.BaseDirectory.
359+
"driverExecutableFileName": "string", // Sets the name of the driver executable file.
359360
"{{driverServicePropertyName}}": "value" // Any property of driver specific service (e.g.: ChromeDriverService).
360361
},
361362
"commandTimeout": 60 // Sets the command timeout in seconds.

src/Atata.Configuration.Json.Tests/Configs/Chrome+NUnit.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"type": "Chrome",
44
"options": {
55
"arguments": [ "disable-extensions", "start-maximized" ]
6+
},
7+
"service": {
8+
"driverPath": "{basedir}",
9+
"driverExecutableFileName": "chromedriver.exe"
610
}
711
},
812
"baseUrl": "https://atata-framework.github.io/atata-sample-app/#!/",

src/Atata.Configuration.Json.Tests/GeneralSettingsTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public void GeneralSettings_NUnit()
3636
context.VerificationRetryInterval.Should().Be(TimeSpan.FromSeconds(1));
3737

3838
context.TestNameFactory().Should().Be(nameof(GeneralSettings_NUnit));
39+
40+
builder.Build();
3941
}
4042
}
4143
}

src/Atata.Configuration.Json/Mapping/DriverJsonMapper`3.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using OpenQA.Selenium;
45

@@ -9,6 +10,8 @@ public abstract class DriverJsonMapper<TBuilder, TService, TOptions> : IDriverJs
910
where TService : DriverService
1011
where TOptions : DriverOptions, new()
1112
{
13+
public const string BaseDirectoryVariable = "{basedir}";
14+
1215
public void Map(DriverJsonSection section, AtataContextBuilder builder)
1316
{
1417
TBuilder driverBuilder = CreateDriverBuilder(builder);
@@ -36,7 +39,7 @@ protected virtual void Map(DriverJsonSection section, TBuilder builder)
3639
builder.WithCommandTimeout(TimeSpan.FromSeconds(section.CommandTimeout.Value));
3740

3841
if (!string.IsNullOrWhiteSpace(section.Service?.DriverPath))
39-
builder.WithDriverPath(section.Service.DriverPath);
42+
builder.WithDriverPath(FormatDriverPath(section.Service.DriverPath));
4043

4144
if (!string.IsNullOrWhiteSpace(section.Service?.DriverExecutableFileName))
4245
builder.WithDriverExecutableFileName(section.Service.DriverExecutableFileName);
@@ -75,5 +78,12 @@ protected virtual void MapService(DriverServiceJsonSection section, TService ser
7578
if (properties?.Any() ?? false)
7679
AtataMapper.Map(properties, service);
7780
}
81+
82+
private static string FormatDriverPath(string driverPath)
83+
{
84+
return driverPath.Contains(BaseDirectoryVariable)
85+
? driverPath.Replace(BaseDirectoryVariable, AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))
86+
: driverPath;
87+
}
7888
}
7989
}

0 commit comments

Comments
 (0)