Skip to content

Commit

Permalink
Add possibility to hide "<BrowserName> is being controlled by automat…
Browse files Browse the repository at this point in the history
…ed software" infobar (#212)

* Add possibility to hide "Chrome is being controlled by automated software" infobar within Chrome

* Update settings

* Add ExcludedArguments into EdgeOptions and OperaOptions

* Add test with different excludedArguments

* Add logger localization messages

* Fix autotest

Co-authored-by: Mikhail Kalyn <[email protected]>
  • Loading branch information
MikhailKalyn and Mikhail Kalyn authored Feb 18, 2022
1 parent 3157da0 commit a1a255c
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public override DriverOptions DriverOptions
SetChromePrefs(options);
SetCapabilities(options, (name, value) => options.AddAdditionalOption(name, value));
SetChromeArguments(options);
SetChromeExcludedArguments(options);
SetPageLoadStrategy(options);
return options;
}
}

private void SetChromeExcludedArguments(ChromeOptions options)
{
options.AddExcludedArguments(BrowserExcludedArguments);
}

private void SetChromePrefs(ChromeOptions options)
{
foreach (var option in BrowserOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public abstract class DriverSettings : IDriverSettings
private IReadOnlyDictionary<string, object> options;
private IReadOnlyDictionary<string, object> capabilities;
private IReadOnlyList<string> startArguments;
private IReadOnlyList<string> excludedArguments;

/// <summary>
/// Instantiates class using JSON file with general settings.
Expand Down Expand Up @@ -90,19 +91,36 @@ protected IReadOnlyDictionary<string, object> BrowserOptions
}
}

protected IReadOnlyList<string> BrowserExcludedArguments
{
get
{
if (excludedArguments == null)
{
excludedArguments = SettingsFile.GetValueListOrEmpty<string>($"{DriverSettingsPath}.{nameof(excludedArguments)}");
if (excludedArguments.Any())
{
AqualityServices.LocalizedLogger.Debug("loc.browser.excludedArguments", args: string.Join(" ", excludedArguments));
}
}

return excludedArguments;
}
}

protected IReadOnlyList<string> BrowserStartArguments
{
get
{
if (startArguments == null)
{
startArguments = SettingsFile.GetValueListOrEmpty<string>($"{DriverSettingsPath}.{nameof(startArguments)}");

if (startArguments.Any())
{
AqualityServices.LocalizedLogger.Debug("loc.browser.arguments", args: string.Join(" ", startArguments));
}
}

return startArguments;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public override DriverOptions DriverOptions
SetEdgePrefs(options);
SetCapabilities(options, (name, value) => options.AddAdditionalOption(name, value));
SetEdgeArguments(options);
SetEdgeExcludedArguments(options);
SetPageLoadStrategy(options);
return options;
}
}

private void SetEdgeExcludedArguments(EdgeOptions options)
{
options.AddExcludedArguments(BrowserExcludedArguments);
}

private void SetEdgePrefs(EdgeOptions options)
{
foreach (var option in BrowserOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ public override DriverOptions DriverOptions
SetOperaPrefs(options);
SetCapabilities(options, (name, value) => options.AddAdditionalOption(name, value));
SetOperaArguments(options);
SetOperaExcludedArguments(options);
SetPageLoadStrategy(options);
return options;
}
}

private void SetOperaExcludedArguments(OperaOptions options)
{
options.AddExcludedArguments(BrowserExcludedArguments);
}

private void SetOperaPrefs(OperaOptions options)
{
foreach (var option in BrowserOptions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"loc.browser.arguments": "Атрымалі стартавыя аргументы браўзэра з settings файла: {0}",
"loc.browser.excludedArguments": "Выключэнне аргументаў браўзэра з settings файла: {0}",
"loc.browser.back": "Вяртаемся да папярэдняй старонкі",
"loc.browser.forward": "Пераходзім да наступнай старонкі",
"loc.browser.capabilities": "Атрымалі capabilities браўзэра з settings файла: {0}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"loc.browser.arguments": "Got browser start arguments from settings file: {0}",
"loc.browser.excludedArguments": "Exclude browser arguments from settings file: {0}",
"loc.browser.back": "Return to previous page",
"loc.browser.forward": "Proceed to the next page",
"loc.browser.capabilities": "Got browser capabilities from settings file: {0}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"loc.browser.arguments": "Получили стартовые аргументы браузера из settings файла: {0}",
"loc.browser.excludedArguments": "Исключение аргументов браузера из settings файла: {0}",
"loc.browser.back": "Возврат на предыдущую страницу",
"loc.browser.forward": "Перейти на следующую страницу",
"loc.browser.capabilities": "Получили capabilities браузера из settings файла: {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"excludedArguments": [ "enable-automation" ],
"startArguments": [],
"pageLoadStrategy": "Normal"
},
Expand Down Expand Up @@ -69,6 +70,7 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"excludedArguments": ["enable-automation"],
"startArguments": []
},
"safari": {
Expand All @@ -90,6 +92,7 @@
"disable-popup-blocking": "true",
"download.prompt_for_download": "false"
},
"excludedArguments": ["enable-automation"],
"startArguments": []
},
"yandex": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ public void Should_BePossibleTo_ScrollToTheCenter()
const int accuracy = 1;
var welcomeForm = new WelcomeForm();
welcomeForm.Open();
welcomeForm.GetExampleLink(AvailableExample.Dropdown).JsActions.ScrollToTheCenter();
welcomeForm.GetExampleLink(AvailableExample.Hovers).JsActions.ScrollToTheCenter();

var windowSize = AqualityServices.Browser.ExecuteScriptFromFile<object>("Resources.GetWindowSize.js").ToString();
var currentY = AqualityServices.Browser.ExecuteScriptFromFile<object>("Resources.GetElementYCoordinate.js",
welcomeForm.GetExampleLink(AvailableExample.Dropdown).GetElement()).ToString();
welcomeForm.GetExampleLink(AvailableExample.Hovers).GetElement()).ToString();
var coordinateRelatingWindowCenter = double.Parse(windowSize) / 2 - double.Parse(currentY);
Assert.LessOrEqual(Math.Abs(coordinateRelatingWindowCenter), accuracy, "Upper bound of element should be in the center of the page");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"startArguments": []
"excludedArguments": [ "enable-automation" ],
"startArguments": [],
"pageLoadStrategy": "Normal"
},
"firefox": {
"webDriverVersion": "0.24.0",
Expand Down Expand Up @@ -66,6 +68,7 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"excludedArguments": [ "enable-automation" ],
"startArguments": []
},
"safari": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"excludedArguments": [ "enable-automation" ],
"startArguments": [],
"pageLoadStrategy": "Normal"
},
Expand Down Expand Up @@ -70,6 +71,7 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"excludedArguments": ["enable-automation"],
"startArguments": []
},
"safari": {
Expand All @@ -90,6 +92,7 @@
"disable-popup-blocking": "true",
"download.prompt_for_download": "false"
},
"excludedArguments": ["enable-automation"],
"startArguments": []
},
"yandex": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public void Should_BeAbleGetBrowser_WithStartArguments(string startArguments)
Assert.DoesNotThrow(() => AqualityServices.Browser.WaitForPageToLoad());
}

[TestCase(null)]
[TestCase("enable-automation")]
[TestCase("a")]
public void Should_BeAbleGetBrowser_WithExcludedArguments(string excludedArguments)
{
var currentBrowser = AqualityServices.Get<IBrowserProfile>().BrowserName;
Environment.SetEnvironmentVariable($"driverSettings.{currentBrowser.ToString().ToLowerInvariant()}.excludedArguments", excludedArguments);
Assert.DoesNotThrow(() => AqualityServices.Browser.WaitForPageToLoad());
}

[Ignore("Not all browsers are supported in Azure CICD pipeline")]
[TestCase(BrowserName.IExplorer)]
[TestCase(BrowserName.Firefox)]
Expand Down

0 comments on commit a1a255c

Please sign in to comment.