Skip to content

Commit 69669e2

Browse files
committed
Bumping to 4.35 and enabling tests
1 parent 77c3bf3 commit 69669e2

File tree

6 files changed

+52
-72
lines changed

6 files changed

+52
-72
lines changed

examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs

Lines changed: 49 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,41 +58,44 @@ 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);
6667
var lines = File.ReadLines(GetLogLocation());
6768
Assert.IsNotNull(lines.FirstOrDefault(line => line.Contains("geckodriver INFO Listening on")));
6869
}
6970

7071
[TestMethod]
71-
[Ignore("Not implemented")]
7272
public void LogsToConsole()
7373
{
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();
74+
TestLogHandler testLogHandler = new TestLogHandler();
75+
ResetGlobalLog();
76+
try
77+
{
78+
Log.SetLevel(LogEventLevel.Trace).Handlers.Add(testLogHandler);
79+
var service = FirefoxDriverService.CreateDefaultService();
80+
driver = new FirefoxDriver(service);
81+
Assert.IsTrue(testLogHandler.Events.Count >= 1);
82+
Assert.IsTrue(testLogHandler.Events.Any(e => e.Message.Contains("geckodriver INFO")));
83+
}
84+
catch (Exception e)
85+
{
86+
// If the test fails, we still want to reset the global log
87+
}
88+
finally
89+
{
90+
ResetGlobalLog();
91+
}
8592
}
8693

8794
[TestMethod]
88-
[Ignore("You can set it, just can't see it")]
8995
public void LogsLevel()
9096
{
9197
var service = FirefoxDriverService.CreateDefaultService();
92-
//service.LogFile = _logLocation
93-
98+
service.LogPath = GetLogLocation();
9499
service.LogLevel = FirefoxDriverLogLevel.Debug;
95100

96101
driver = new FirefoxDriver(service);
@@ -99,11 +104,10 @@ public void LogsLevel()
99104
}
100105

101106
[TestMethod]
102-
[Ignore("Not implemented")]
103107
public void StopsTruncatingLogs()
104108
{
105109
var service = FirefoxDriverService.CreateDefaultService();
106-
//service.TruncateLogs = false;
110+
service.LogTruncate = false;
107111

108112
service.LogLevel = FirefoxDriverLogLevel.Debug;
109113

@@ -113,18 +117,17 @@ public void StopsTruncatingLogs()
113117
}
114118

115119
[TestMethod]
116-
[Ignore("Not implemented")]
117120
public void SetProfileLocation()
118121
{
119122
var service = FirefoxDriverService.CreateDefaultService();
120-
// service.ProfileRoot = GetTempDirectory();
123+
service.ProfileRoot = GetTempDirectory();
121124

122125
driver = new FirefoxDriver(service);
123126

124127
string profile = (string)driver.Capabilities.GetCapability("moz:profile");
125128
string[] directories = profile.Split("/");
126129
var dirName = directories.Last();
127-
Assert.AreEqual(GetTempDirectory() + "/" + dirName, profile);
130+
Assert.AreEqual(GetTempDirectory() + dirName, profile);
128131
}
129132

130133
[TestMethod]
@@ -171,7 +174,7 @@ public void InstallUnsignedAddon()
171174

172175
private string GetLogLocation()
173176
{
174-
if (_logLocation != null && !File.Exists(_logLocation))
177+
if (String.IsNullOrEmpty(_logLocation) && !File.Exists(_logLocation))
175178
{
176179
_logLocation = Path.GetTempFileName();
177180
}
@@ -181,7 +184,7 @@ private string GetLogLocation()
181184

182185
private string GetTempDirectory()
183186
{
184-
if (_tempPath != null && !File.Exists(_tempPath))
187+
if (String.IsNullOrEmpty(_tempPath) && !File.Exists(_tempPath))
185188
{
186189
_tempPath = Path.GetTempPath();
187190
}
@@ -203,5 +206,26 @@ private static string GetFirefoxLocation()
203206
};
204207
return new DriverFinder(options).GetBrowserPath();
205208
}
209+
210+
private void ResetGlobalLog()
211+
{
212+
Log.SetLevel(LogEventLevel.Info);
213+
Log.Handlers.Clear().Handlers.Add(new TextWriterHandler(Console.Error));
214+
}
206215
}
216+
}
217+
218+
class TestLogHandler : ILogHandler
219+
{
220+
public ILogHandler Clone()
221+
{
222+
return this;
223+
}
224+
225+
public void Handle(LogEvent logEvent)
226+
{
227+
Events.Add(logEvent);
228+
}
229+
230+
public IList<LogEvent> Events { get; internal set; } = new List<LogEvent>();
207231
}

examples/dotnet/SeleniumDocs/Browsers/InternetExplorerTest.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,38 +45,6 @@ public void BasicOptionsWin11()
4545
_driver = new InternetExplorerDriver(options);
4646
}
4747

48-
[TestMethod]
49-
[Ignore("Not implemented")]
50-
public void LogsToFile()
51-
{
52-
var service = InternetExplorerDriverService.CreateDefaultService();
53-
service.LogFile = GetLogLocation();
54-
55-
_driver = new InternetExplorerDriver(service);
56-
_driver.Quit(); // Close the Service log file before reading
57-
var lines = File.ReadLines(GetLogLocation());
58-
Console.WriteLine("Lines: {0}", lines);
59-
Assert.IsTrue(lines.Contains("Started InternetExplorerDriver server"));
60-
}
61-
62-
[TestMethod]
63-
[Ignore("Not implemented")]
64-
public void LogsToConsole()
65-
{
66-
var stringWriter = new StringWriter();
67-
var originalOutput = Console.Out;
68-
Console.SetOut(stringWriter);
69-
70-
var service = InternetExplorerDriverService.CreateDefaultService();
71-
72-
//service.LogToConsole = true;
73-
74-
_driver = new InternetExplorerDriver(service);
75-
Assert.IsTrue(stringWriter.ToString().Contains("geckodriver INFO Listening on"));
76-
Console.SetOut(originalOutput);
77-
stringWriter.Dispose();
78-
}
79-
8048
[TestMethod]
8149
public void LogsLevel()
8250
{

examples/dotnet/SeleniumDocs/Browsers/SafariTest.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,5 @@ public void BasicOptions()
2222
var options = new SafariOptions();
2323
driver = new SafariDriver(options);
2424
}
25-
26-
[TestMethod]
27-
[Ignore("Not implemented")]
28-
public void EnableLogs()
29-
{
30-
var service = SafariDriverService.CreateDefaultService();
31-
32-
//service.EnableLogging = true;
33-
34-
driver = new SafariDriver(service);
35-
}
3625
}
3726
}

examples/dotnet/SeleniumDocs/SeleniumDocs.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.7.1" />
1111
<PackageReference Include="MSTest.TestAdapter" Version="3.6.0" />
1212
<PackageReference Include="MSTest.TestFramework" Version="3.6.0" />
13-
<PackageReference Include="Selenium.Support" Version="4.33.0" />
14-
<PackageReference Include="Selenium.WebDriver" Version="4.33.0" />
13+
<PackageReference Include="Selenium.Support" Version="4.35.0" />
14+
<PackageReference Include="Selenium.WebDriver" Version="4.35.0" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

examples/dotnet/SeleniumDocs/Troubleshooting/LoggingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void TestCleanup()
4545
// reset log to default
4646
Log.SetLevel(LogEventLevel.Info)
4747
.Handlers.Clear()
48-
.Handlers.Add(new ConsoleLogHandler());
48+
.Handlers.Add(new TextWriterHandler(Console.Error));
4949
}
5050

5151
// logging is only for internal usage

examples/kotlin/src/test/kotlin/dev/selenium/virtualauthenticator/VirtualAuthenticatorTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class VirtualAuthenticatorTest {
108108
}
109109

110110
@Test
111-
@Disabled("A fix was implemented and will be available in Selenium 4.34.")
112111
fun testCreateAndAddNonResidentialKey() {
113112
val options = VirtualAuthenticatorOptions()
114113
.setProtocol(VirtualAuthenticatorOptions.Protocol.U2F)

0 commit comments

Comments
 (0)