Skip to content

Commit cc03ffb

Browse files
authored
Add method to Browser to get logs [+semver: feature] (#185)
* Add method to Browser to get logs * Fix XML comments * Fix sonar issues
1 parent 3532701 commit cc03ffb

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Reflection;
99
using System;
1010
using Aquality.Selenium.Core.Waitings;
11+
using System.Collections.ObjectModel;
1112

1213
namespace Aquality.Selenium.Browsers
1314
{
@@ -18,6 +19,7 @@ public class Browser : IApplication
1819
{
1920
private TimeSpan implicitWaitTimeout;
2021
private TimeSpan pageLoadTimeout;
22+
2123
private readonly IBrowserProfile browserProfile;
2224
private readonly IConditionalWait conditionalWait;
2325

@@ -241,6 +243,19 @@ public byte[] GetScreenshot()
241243
return Driver.GetScreenshot().AsByteArray;
242244
}
243245

246+
/// <summary>
247+
/// Gets logs from WebDriver.
248+
/// </summary>
249+
/// <param name="logKind">Type of logs <see cref="LogType"/></param>
250+
/// <returns>ReadOnlyCollection of log entries.</returns>
251+
/// <remark>
252+
/// Does not work on current version of Selenium WebDriver. Issue: https://github.com/SeleniumHQ/selenium/issues/7323
253+
/// </remark>
254+
public ReadOnlyCollection<LogEntry> GetLogs(string logKind)
255+
{
256+
return Driver.Manage().Logs.GetLog(logKind);
257+
}
258+
244259
/// <summary>
245260
/// Scrolls window by coordinates.
246261
/// </summary>

Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserTabNavigation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public void SwitchToLastTab(bool closeCurrent = false)
6262
CloseAndSwitch(TabHandles.Last(), closeCurrent);
6363
}
6464

65-
public void SwitchToTab(string handle, bool closeCurrent = false)
65+
public void SwitchToTab(string tabHandle, bool closeCurrent = false)
6666
{
67-
Logger.Info("loc.browser.switch.to.tab.handle", handle);
68-
CloseAndSwitch(handle, closeCurrent);
67+
Logger.Info("loc.browser.switch.to.tab.handle", tabHandle);
68+
CloseAndSwitch(tabHandle, closeCurrent);
6969
}
7070

7171
public void SwitchToTab(int index, bool closeCurrent = false)

Aquality.Selenium/src/Aquality.Selenium/Browsers/IBrowserTabNavigation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface IBrowserTabNavigation
2222
/// <summary>
2323
/// Switches to tab.
2424
/// </summary>
25-
/// <param name="name">Tab handle.</param>
25+
/// <param name="tabHandle">Tab handle.</param>
2626
/// <param name="closeCurrent">Close current tab if true and leave it otherwise.</param>
2727
void SwitchToTab(string tabHandle, bool closeCurrent = false);
2828

Aquality.Selenium/src/Aquality.Selenium/Browsers/LocalBrowserFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private Browser CreateBrowser()
4646
break;
4747
case BrowserName.Firefox:
4848
SetUpDriver(new FirefoxConfig(), driverSettings);
49-
FirefoxDriverService geckoService = FirefoxDriverService.CreateDefaultService();
49+
var geckoService = FirefoxDriverService.CreateDefaultService();
5050
geckoService.Host = "::1";
5151
driver = GetDriver<FirefoxDriver>(geckoService, (FirefoxOptions)driverSettings.DriverOptions, commandTimeout);
5252
break;

Aquality.Selenium/src/Aquality.Selenium/Resources/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
"chrome": {
99
"webDriverVersion": "Latest",
1010
"capabilities": {
11-
"enableVNC": true
11+
"enableVNC": true,
12+
"loggingPrefs": {
13+
"driver": "INFO",
14+
"server": "OFF",
15+
"browser": "FINE"
16+
}
1217
},
1318
"options": {
1419
"intl.accept_languages": "en",

0 commit comments

Comments
 (0)