Skip to content

Commit 4014a17

Browse files
authored
Merge branch 'trunk' into blog_4_35
2 parents 2739eab + c7fcb00 commit 4014a17

File tree

29 files changed

+320
-222
lines changed

29 files changed

+320
-222
lines changed

examples/dotnet/SeleniumDocs/BaseTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class BaseTest
1717
protected IWebDriver driver;
1818
protected Uri GridUrl;
1919
private Process _webserverProcess;
20-
private const string ServerJarName = "selenium-server-4.34.0.jar";
20+
private const string ServerJarName = "selenium-server-4.35.0.jar";
2121
private static readonly string BaseDirectory = AppContext.BaseDirectory;
2222
private const string RelativePathToGrid = "../../../../../";
2323
private readonly string _examplesDirectory = Path.GetFullPath(Path.Combine(BaseDirectory, RelativePathToGrid));
@@ -87,7 +87,7 @@ private static int GetFreeTcpPort()
8787

8888
private async Task EnsureGridIsRunningAsync()
8989
{
90-
DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(30));
90+
DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(240));
9191
bool isRunning = false;
9292
HttpClient client = new HttpClient();
9393

@@ -102,12 +102,12 @@ private async Task EnsureGridIsRunningAsync()
102102
}
103103
else
104104
{
105-
await Task.Delay(500);
105+
await Task.Delay(1000);
106106
}
107107
}
108108
catch (HttpRequestException)
109109
{
110-
await Task.Delay(500);
110+
await Task.Delay(1000);
111111
}
112112
}
113113

examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.VisualStudio.TestTools.UnitTesting;
66
using OpenQA.Selenium;
77
using OpenQA.Selenium.Chrome;
8+
using OpenQA.Selenium.Chromium;
89

910
namespace SeleniumDocs.Browsers
1011
{
@@ -44,8 +45,8 @@ public void Arguments()
4445
[TestMethod]
4546
public void SetBrowserLocation()
4647
{
47-
string userDataDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName());
48-
System.IO.Directory.CreateDirectory(userDataDir);
48+
string userDataDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
49+
Directory.CreateDirectory(userDataDir);
4950
var options = new ChromeOptions();
5051
options.AddArgument($"--user-data-dir={userDataDir}");
5152
options.AddArgument("--no-sandbox");
@@ -98,32 +99,12 @@ public void LogsToFile()
9899
}
99100

100101
[TestMethod]
101-
[Ignore("Not implemented")]
102-
public void LogsToConsole()
103-
{
104-
var stringWriter = new StringWriter();
105-
var originalOutput = Console.Out;
106-
Console.SetOut(stringWriter);
107-
108-
var service = ChromeDriverService.CreateDefaultService();
109-
110-
//service.LogToConsole = true;
111-
112-
driver = new ChromeDriver(service);
113-
114-
Assert.IsTrue(stringWriter.ToString().Contains("Starting ChromeDriver"));
115-
Console.SetOut(originalOutput);
116-
stringWriter.Dispose();
117-
}
118-
119-
[TestMethod]
120-
[Ignore("Not implemented")]
121102
public void LogsLevel()
122103
{
123104
var service = ChromeDriverService.CreateDefaultService();
124105
service.LogPath = GetLogLocation();
125106

126-
// service.LogLevel = ChromiumDriverLogLevel.Debug
107+
service.LogLevel = ChromiumDriverLogLevel.Debug;
127108

128109
driver = new ChromeDriver(service);
129110

@@ -133,22 +114,21 @@ public void LogsLevel()
133114
}
134115

135116
[TestMethod]
136-
[Ignore("Not implemented")]
137117
public void ConfigureDriverLogs()
138118
{
139119
var service = ChromeDriverService.CreateDefaultService();
140120
service.LogPath = GetLogLocation();
141121
service.EnableVerboseLogging = true;
142122

143123
service.EnableAppendLog = true;
144-
// service.readableTimeStamp = true;
124+
service.ReadableTimestamp = true;
145125

146126
driver = new ChromeDriver(service);
147127

148128
driver.Quit(); // Close the Service log file before reading
149129
var lines = File.ReadLines(GetLogLocation());
150-
var regex = new Regex(@"\[\d\d-\d\d-\d\d\d\d");
151-
Assert.IsNotNull(lines.FirstOrDefault(line => regex.Matches("").Count > 0));
130+
var regex = new Regex(@"\[\d\d-\d\d-\d\d\d\d \d\d:\d\d:\d\d\.\d+\]");
131+
Assert.IsNotNull(lines.FirstOrDefault(line => regex.Matches(line).Count > 0));
152132
}
153133

154134
[TestMethod]
@@ -169,7 +149,7 @@ public void DisableBuildCheck()
169149

170150
private string GetLogLocation()
171151
{
172-
if (_logLocation == null || !File.Exists(_logLocation))
152+
if (string.IsNullOrEmpty(_logLocation) && !File.Exists(_logLocation))
173153
{
174154
_logLocation = Path.GetTempFileName();
175155
}

examples/dotnet/SeleniumDocs/Browsers/EdgeTest.cs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text.RegularExpressions;
55
using Microsoft.VisualStudio.TestTools.UnitTesting;
66
using OpenQA.Selenium;
7+
using OpenQA.Selenium.Chromium;
78
using OpenQA.Selenium.Edge;
89

910
namespace SeleniumDocs.Browsers
@@ -92,32 +93,12 @@ public void LogsToFile()
9293
}
9394

9495
[TestMethod]
95-
[Ignore("Not implemented")]
96-
public void LogsToConsole()
97-
{
98-
var stringWriter = new StringWriter();
99-
var originalOutput = Console.Out;
100-
Console.SetOut(stringWriter);
101-
102-
var service = EdgeDriverService.CreateDefaultService();
103-
104-
//service.LogToConsole = true;
105-
106-
driver = new EdgeDriver(service);
107-
108-
Assert.IsTrue(stringWriter.ToString().Contains("Starting Microsoft Edge WebDriver"));
109-
Console.SetOut(originalOutput);
110-
stringWriter.Dispose();
111-
}
112-
113-
[TestMethod]
114-
[Ignore("Not implemented")]
11596
public void LogsLevel()
11697
{
11798
var service = EdgeDriverService.CreateDefaultService();
11899
service.LogPath = GetLogLocation();
119100

120-
// service.LogLevel = ChromiumDriverLogLevel.Debug
101+
service.LogLevel = ChromiumDriverLogLevel.Debug;
121102

122103
driver = new EdgeDriver(service);
123104

@@ -127,22 +108,21 @@ public void LogsLevel()
127108
}
128109

129110
[TestMethod]
130-
[Ignore("Not implemented")]
131111
public void ConfigureDriverLogs()
132112
{
133113
var service = EdgeDriverService.CreateDefaultService();
134114
service.LogPath = GetLogLocation();
135115
service.EnableVerboseLogging = true;
136116

137117
service.EnableAppendLog = true;
138-
// service.readableTimeStamp = true;
118+
service.ReadableTimestamp = true;
139119

140120
driver = new EdgeDriver(service);
141121

142122
driver.Quit(); // Close the Service log file before reading
143123
var lines = File.ReadLines(GetLogLocation());
144-
var regex = new Regex(@"\[\d\d-\d\d-\d\d\d\d");
145-
Assert.IsNotNull(lines.FirstOrDefault(line => regex.Matches("").Count > 0));
124+
var regex = new Regex(@"\[\d\d-\d\d-\d\d\d\d \d\d:\d\d:\d\d\.\d+\]");
125+
Assert.IsNotNull(lines.FirstOrDefault(line => regex.Matches(line).Count > 0));
146126
}
147127

148128
[TestMethod]
@@ -163,7 +143,7 @@ public void DisableBuildCheck()
163143

164144
private string GetLogLocation()
165145
{
166-
if (_logLocation == null || !File.Exists(_logLocation))
146+
if (string.IsNullOrEmpty(_logLocation) && !File.Exists(_logLocation))
167147
{
168148
_logLocation = Path.GetTempFileName();
169149
}

examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using Microsoft.VisualStudio.TestTools.UnitTesting;
56
using OpenQA.Selenium;
67
using OpenQA.Selenium.Firefox;
8+
using OpenQA.Selenium.Internal.Logging;
79

810
namespace SeleniumDocs.Browsers
911
{
@@ -17,7 +19,7 @@ public class FirefoxTest
1719
[TestCleanup]
1820
public void Cleanup()
1921
{
20-
if (_logLocation != null && File.Exists(_logLocation))
22+
if (!String.IsNullOrEmpty(_logLocation) && File.Exists(_logLocation))
2123
{
2224
File.Delete(_logLocation);
2325
}
@@ -56,75 +58,75 @@ public void SetBinary()
5658
}
5759

5860
[TestMethod]
59-
[Ignore("Not implemented")]
6061
public void LogsToFile()
6162
{
6263
var service = FirefoxDriverService.CreateDefaultService();
63-
//service.LogFile = _logLocation
64+
service.LogPath = GetLogLocation();
6465

6566
driver = new FirefoxDriver(service);
67+
driver.Quit(); // Close the Service log file before reading
6668
var lines = File.ReadLines(GetLogLocation());
6769
Assert.IsNotNull(lines.FirstOrDefault(line => line.Contains("geckodriver INFO Listening on")));
6870
}
6971

7072
[TestMethod]
71-
[Ignore("Not implemented")]
7273
public void LogsToConsole()
7374
{
74-
var stringWriter = new StringWriter();
75-
var originalOutput = Console.Out;
76-
Console.SetOut(stringWriter);
77-
78-
var service = FirefoxDriverService.CreateDefaultService();
79-
//service.LogToConsole = true;
80-
81-
driver = new FirefoxDriver(service);
82-
Assert.IsTrue(stringWriter.ToString().Contains("geckodriver INFO Listening on"));
83-
Console.SetOut(originalOutput);
84-
stringWriter.Dispose();
75+
TestLogHandler testLogHandler = new TestLogHandler();
76+
ResetGlobalLog();
77+
try
78+
{
79+
Log.SetLevel(LogEventLevel.Trace).Handlers.Add(testLogHandler);
80+
var service = FirefoxDriverService.CreateDefaultService();
81+
driver = new FirefoxDriver(service);
82+
Assert.IsTrue(testLogHandler.Events.Count >= 1);
83+
Assert.IsTrue(testLogHandler.Events.Any(e => e.Message.Contains("geckodriver")));
84+
}
85+
finally
86+
{
87+
ResetGlobalLog();
88+
}
8589
}
8690

8791
[TestMethod]
88-
[Ignore("You can set it, just can't see it")]
8992
public void LogsLevel()
9093
{
9194
var service = FirefoxDriverService.CreateDefaultService();
92-
//service.LogFile = _logLocation
93-
95+
service.LogPath = GetLogLocation();
9496
service.LogLevel = FirefoxDriverLogLevel.Debug;
9597

9698
driver = new FirefoxDriver(service);
99+
driver.Quit(); // Close the Service log file before reading
97100
var lines = File.ReadLines(GetLogLocation());
98101
Assert.IsNotNull(lines.FirstOrDefault(line => line.Contains("Marionette\tDEBUG")));
99102
}
100103

101104
[TestMethod]
102-
[Ignore("Not implemented")]
103105
public void StopsTruncatingLogs()
104106
{
105107
var service = FirefoxDriverService.CreateDefaultService();
106-
//service.TruncateLogs = false;
108+
service.LogTruncate = false;
107109

108110
service.LogLevel = FirefoxDriverLogLevel.Debug;
109111

110112
driver = new FirefoxDriver(service);
113+
driver.Quit(); // Close the Service log file before reading
111114
var lines = File.ReadLines(GetLogLocation());
112115
Assert.IsNull(lines.FirstOrDefault(line => line.Contains(" ... ")));
113116
}
114117

115118
[TestMethod]
116-
[Ignore("Not implemented")]
117119
public void SetProfileLocation()
118120
{
119121
var service = FirefoxDriverService.CreateDefaultService();
120-
// service.ProfileRoot = GetTempDirectory();
122+
service.ProfileRoot = GetTempDirectory();
121123

122124
driver = new FirefoxDriver(service);
123125

124126
string profile = (string)driver.Capabilities.GetCapability("moz:profile");
125127
string[] directories = profile.Split("/");
126128
var dirName = directories.Last();
127-
Assert.AreEqual(GetTempDirectory() + "/" + dirName, profile);
129+
Assert.AreEqual(GetTempDirectory() + dirName, profile);
128130
}
129131

130132
[TestMethod]
@@ -171,7 +173,7 @@ public void InstallUnsignedAddon()
171173

172174
private string GetLogLocation()
173175
{
174-
if (_logLocation != null && !File.Exists(_logLocation))
176+
if (string.IsNullOrEmpty(_logLocation) && !File.Exists(_logLocation))
175177
{
176178
_logLocation = Path.GetTempFileName();
177179
}
@@ -181,7 +183,7 @@ private string GetLogLocation()
181183

182184
private string GetTempDirectory()
183185
{
184-
if (_tempPath != null && !File.Exists(_tempPath))
186+
if (string.IsNullOrEmpty(_tempPath) && !File.Exists(_tempPath))
185187
{
186188
_tempPath = Path.GetTempPath();
187189
}
@@ -203,5 +205,26 @@ private static string GetFirefoxLocation()
203205
};
204206
return new DriverFinder(options).GetBrowserPath();
205207
}
208+
209+
private void ResetGlobalLog()
210+
{
211+
Log.SetLevel(LogEventLevel.Info);
212+
Log.Handlers.Clear().Handlers.Add(new TextWriterHandler(Console.Error));
213+
}
214+
}
215+
}
216+
217+
class TestLogHandler : ILogHandler
218+
{
219+
public ILogHandler Clone()
220+
{
221+
return this;
206222
}
223+
224+
public void Handle(LogEvent logEvent)
225+
{
226+
Events.Add(logEvent);
227+
}
228+
229+
public IList<LogEvent> Events { get; internal set; } = new List<LogEvent>();
207230
}

0 commit comments

Comments
 (0)