Skip to content

Commit

Permalink
Add method to Browser to get logs [+semver: feature] (#185)
Browse files Browse the repository at this point in the history
* Add method to Browser to get logs

* Fix XML comments

* Fix sonar issues
  • Loading branch information
paveliam authored May 21, 2020
1 parent 3532701 commit cc03ffb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
15 changes: 15 additions & 0 deletions Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System;
using Aquality.Selenium.Core.Waitings;
using System.Collections.ObjectModel;

namespace Aquality.Selenium.Browsers
{
Expand All @@ -18,6 +19,7 @@ public class Browser : IApplication
{
private TimeSpan implicitWaitTimeout;
private TimeSpan pageLoadTimeout;

private readonly IBrowserProfile browserProfile;
private readonly IConditionalWait conditionalWait;

Expand Down Expand Up @@ -241,6 +243,19 @@ public byte[] GetScreenshot()
return Driver.GetScreenshot().AsByteArray;
}

/// <summary>
/// Gets logs from WebDriver.
/// </summary>
/// <param name="logKind">Type of logs <see cref="LogType"/></param>
/// <returns>ReadOnlyCollection of log entries.</returns>
/// <remark>
/// Does not work on current version of Selenium WebDriver. Issue: https://github.com/SeleniumHQ/selenium/issues/7323
/// </remark>
public ReadOnlyCollection<LogEntry> GetLogs(string logKind)
{
return Driver.Manage().Logs.GetLog(logKind);
}

/// <summary>
/// Scrolls window by coordinates.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public void SwitchToLastTab(bool closeCurrent = false)
CloseAndSwitch(TabHandles.Last(), closeCurrent);
}

public void SwitchToTab(string handle, bool closeCurrent = false)
public void SwitchToTab(string tabHandle, bool closeCurrent = false)
{
Logger.Info("loc.browser.switch.to.tab.handle", handle);
CloseAndSwitch(handle, closeCurrent);
Logger.Info("loc.browser.switch.to.tab.handle", tabHandle);
CloseAndSwitch(tabHandle, closeCurrent);
}

public void SwitchToTab(int index, bool closeCurrent = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IBrowserTabNavigation
/// <summary>
/// Switches to tab.
/// </summary>
/// <param name="name">Tab handle.</param>
/// <param name="tabHandle">Tab handle.</param>
/// <param name="closeCurrent">Close current tab if true and leave it otherwise.</param>
void SwitchToTab(string tabHandle, bool closeCurrent = false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private Browser CreateBrowser()
break;
case BrowserName.Firefox:
SetUpDriver(new FirefoxConfig(), driverSettings);
FirefoxDriverService geckoService = FirefoxDriverService.CreateDefaultService();
var geckoService = FirefoxDriverService.CreateDefaultService();
geckoService.Host = "::1";
driver = GetDriver<FirefoxDriver>(geckoService, (FirefoxOptions)driverSettings.DriverOptions, commandTimeout);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
"chrome": {
"webDriverVersion": "Latest",
"capabilities": {
"enableVNC": true
"enableVNC": true,
"loggingPrefs": {
"driver": "INFO",
"server": "OFF",
"browser": "FINE"
}
},
"options": {
"intl.accept_languages": "en",
Expand Down

0 comments on commit cc03ffb

Please sign in to comment.