WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions .github/workflows/ci-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,51 @@
build:
name: Build
uses: ./.github/workflows/bazel.yml
strategy:
fail-fast: false
matrix:
os: ['windows', 'macos']
with:
name: Build
cache-key: false
os: windows
name: Build (${{ matrix.os }})
cache-key: dotnet-${{ matrix.os }}-test
os: ${{ matrix.os }}
run: bazel build //dotnet:all

manager-tests:
name: Selenium Manager Tests
needs: build
uses: ./.github/workflows/bazel.yml
strategy:
fail-fast: false
matrix:
os: ['windows', 'macos', 'ubuntu']
with:
name: Manager Tests (${{ matrix.os }})
cache-key: dotnet-${{ matrix.os }}-test
os: ${{ matrix.os }}
run: >
bazel test
--keep_going
--flaky_test_attempts 3
--local_test_jobs 1
--pin_browsers=false
--test_env=SE_FORCE_BROWSER_DOWNLOAD=true
--test_env=SE_SKIP_DRIVER_IN_PATH=true
//dotnet/test/common:SeleniumManagerTest-chrome
//dotnet/test/common:SeleniumManagerTest-firefox
//dotnet/test/common:SeleniumManagerTest-edge

integration-tests:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
name: Browser Tests
uses: ./.github/workflows/bazel.yml
with:
name: Browser Tests
cache-key: false
cache-key: dotnet-windows-test
java-version: 17
os: windows
run: |
fsutil 8dot3name set 0
bazel test //dotnet/test/common:ElementFindingTest-firefox //dotnet/test/common:ElementFindingTest-chrome
run: >
bazel test
--keep_going
--local_test_jobs 1
//dotnet/test/common:ElementFindingTest-firefox
//dotnet/test/common:ElementFindingTest-chrome
8 changes: 1 addition & 7 deletions dotnet/test/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,9 @@ csharp_library(
],
)

# copy_file(
# name = "manager-macos",
# src = "//common/manager:selenium-manager-macos",
# out = "manager/macos/selenium-manager",
# )

dotnet_nunit_test_suite(
name = "AllTests",
size = "small",
size = "large",
srcs = glob([
"**/*Test.cs",
"**/*Tests.cs",
Expand Down
97 changes: 97 additions & 0 deletions dotnet/test/common/SeleniumManagerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// <copyright file="SeleniumManagerTest.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// </copyright>

using NUnit.Framework;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Environment;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Safari;
using System;
using System.IO;

namespace OpenQA.Selenium;

[TestFixture]
[Category("SeleniumManager")]
[IgnoreBrowser(Browser.IE, "IE does not use Selenium Manager")]
[IgnoreBrowser(Browser.Safari, "Safari does not need Selenium Manager")]
[IgnoreBrowser(Browser.Remote, "Remote does not use Selenium Manager directly")]
public class SeleniumManagerTest
{
private static readonly string CacheDirectory = System.Environment.GetEnvironmentVariable("SE_CACHE") ?? Path.Combine(".cache", "selenium");

private DriverOptions CreateOptionsForCurrentBrowser()
{
return EnvironmentManager.Instance.Browser switch
{
Browser.Chrome => new ChromeOptions(),
Browser.Firefox => new FirefoxOptions(),
Browser.Edge => new EdgeOptions(),
_ => throw new NotSupportedException($"Browser {EnvironmentManager.Instance.Browser} is not supported for Selenium Manager tests")
};
}

private DriverService CreateServiceForCurrentBrowser(string driverPath)
{
return EnvironmentManager.Instance.Browser switch
{
Browser.Chrome => ChromeDriverService.CreateDefaultService(driverPath),
Browser.Firefox => FirefoxDriverService.CreateDefaultService(driverPath),
Browser.Edge => EdgeDriverService.CreateDefaultService(driverPath),
_ => throw new NotSupportedException($"Browser {EnvironmentManager.Instance.Browser} is not supported for Selenium Manager tests")
};
}

[Test]
public void ShouldGetDriverAndBrowserPaths()
{
var options = CreateOptionsForCurrentBrowser();
var driverFinder = new DriverFinder(options);

string driverPath = driverFinder.GetDriverPath();
string browserPath = driverFinder.GetBrowserPath();

Assert.That(File.Exists(driverPath), Is.True, $"Driver path should exist: {driverPath}");
Assert.That(File.Exists(browserPath), Is.True, $"Browser path should exist: {browserPath}");
Assert.That(driverPath, Does.Contain(CacheDirectory), $"Driver path should contain cache directory: {driverPath}");
Assert.That(browserPath, Does.Contain(CacheDirectory), $"Browser path should contain cache directory: {browserPath}");
}

[Test]
public void ShouldStartDriverService()
{
var options = CreateOptionsForCurrentBrowser();
var driverFinder = new DriverFinder(options);

string driverPath = driverFinder.GetDriverPath();
var service = CreateServiceForCurrentBrowser(driverPath);

try
{
service.Start();
Assert.That(service.ServiceUrl, Is.Not.Null);
Assert.That(service.ServiceUrl.IsAbsoluteUri, Is.True);
}
finally
{
service.Dispose();
}
Comment on lines +106 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using statement

}
}
Loading