Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Init method in Env.cs for better initialization #906

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions test/integration/helpers/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@ public class Env

private static void Init()
{
if (_initialized) return;

_env = new Dictionary<string, JsonElement>
{
{ "DEV", JsonDocument.Parse("true").RootElement },
{ "isRemoteAppiumServer", JsonDocument.Parse("false").RootElement },
{ "remoteAppiumServerUri", JsonDocument.Parse("\"http://localhost:4723\"").RootElement }
};

if (_initialized) return;

try
{
_initialized = true;
var path = AppDomain.CurrentDomain.BaseDirectory;
var sr = new StreamReader(path + "env.json");
var jsonString = sr.ReadToEnd();
string path = AppDomain.CurrentDomain.BaseDirectory;
if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
path += Path.DirectorySeparatorChar;
}
StreamReader sr = new(path + "env.json");
string jsonString = sr.ReadToEnd();
_env = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(jsonString, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
_initialized = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it expected is remains false if an exception happens?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we don't want to set it to true if we fail.

}
catch (JsonException jsonEx)
{
Expand Down