Skip to content

Commit 49ac4f2

Browse files
authored
Merge branch 'trunk' into patch-3
2 parents 2cb8185 + 50f3836 commit 49ac4f2

File tree

251 files changed

+5859
-4509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+5859
-4509
lines changed

.github/workflows/dotnet-examples.yml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,28 @@ jobs:
3030
steps:
3131
- name: Checkout GitHub repo
3232
uses: actions/checkout@v3
33-
- name: Install Chrome for set binary test
34-
uses: browser-actions/setup-chrome@v1
35-
with:
36-
chrome-version: stable
37-
id: setup-chrome
38-
- name: Install Edge for set binary test
39-
uses: browser-actions/setup-edge@v1
40-
with:
41-
edge-version: stable
42-
id: setup-edge
43-
- name: Install Firefox for set binary test
44-
if: matrix.os != 'windows-latest'
45-
uses: browser-actions/setup-firefox@v1
46-
with:
47-
firefox-version: latest
48-
id: setup-firefox
49-
- name: Set ENV Windows
33+
- name: Remove driver directories Windows
5034
if: matrix.os == 'windows-latest'
5135
run: |
52-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> $env:GITHUB_ENV
53-
echo "EDGE_BIN=${{ steps.setup-edge.outputs.edge-path }}" >> $env:GITHUB_ENV
54-
- name: Set ENV Other
36+
rm "$env:ChromeWebDriver" -r -v
37+
rm "$env:EdgeWebDriver" -r -v
38+
rm "$env:GeckoWebDriver" -r -v
39+
- name: Remove driver directories Non-Windows
5540
if: matrix.os != 'windows-latest'
5641
run: |
57-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
58-
echo "EDGE_BIN=${{ steps.setup-edge.outputs.edge-path }}" >> "$GITHUB_ENV"
59-
echo "FF_BIN=${{ steps.setup-firefox.outputs.firefox-path }}" >> "$GITHUB_ENV"
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
6043
- name: Start Xvfb
6144
if: matrix.os == 'ubuntu-latest'
6245
run: Xvfb :99 &
6346
- name: Set up .Net
6447
uses: actions/setup-dotnet@v3
6548
with:
6649
dotnet-version: 6.0.x
50+
- name: Set up Java
51+
uses: actions/setup-java@v3
52+
with:
53+
distribution: 'temurin'
54+
java-version: 11
6755
- name: Run tests
6856
uses: nick-invision/retry@v2.8.3
6957
with:

.github/workflows/java-examples.yml

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,16 @@ jobs:
3030
steps:
3131
- name: Checkout GitHub repo
3232
uses: actions/checkout@v3
33-
- name: Install Chrome for set binary test
34-
uses: browser-actions/setup-chrome@v1
35-
with:
36-
chrome-version: stable
37-
id: setup-chrome
38-
- name: Install Edge for set binary test
39-
uses: browser-actions/setup-edge@v1
40-
with:
41-
edge-version: stable
42-
id: setup-edge
43-
- name: Install Firefox for set binary test
44-
if: matrix.os != 'windows-latest'
45-
uses: browser-actions/setup-firefox@v1
46-
with:
47-
firefox-version: latest
48-
id: setup-firefox
49-
- name: Set ENV Windows
33+
- name: Remove driver directories Windows
5034
if: matrix.os == 'windows-latest'
5135
run: |
52-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> $env:GITHUB_ENV
53-
echo "EDGE_BIN=C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" >> $env:GITHUB_ENV
54-
echo "FF_BIN=C:\Program Files (x86)\Mozilla Firefox\firefox-browser.exe" >> $env:GITHUB_ENV
55-
- name: Set ENV Mac
56-
if: matrix.os == 'macos-latest'
57-
run: |
58-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
59-
echo "EDGE_BIN=/Users/runner/hostedtoolcache/msedge/stable/x64/Contents/MacOS/Microsoft Edge" >> "$GITHUB_ENV"
60-
echo "FF_BIN=/Users/runner/hostedtoolcache/firefox/latest/x64/Contents/MacOS/firefox" >> "$GITHUB_ENV"
61-
- name: Set ENV Linux
62-
if: matrix.os == 'ubuntu-latest'
36+
rm "$env:ChromeWebDriver" -r -v
37+
rm "$env:EdgeWebDriver" -r -v
38+
rm "$env:GeckoWebDriver" -r -v
39+
- name: Remove driver directories Non-Windows
40+
if: matrix.os != 'windows-latest'
6341
run: |
64-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
65-
echo "EDGE_BIN=/opt/hostedtoolcache/msedge/stable/x64/msedge" >> "$GITHUB_ENV"
66-
echo "FF_BIN=/opt/hostedtoolcache/firefox/latest/x64/firefox" >> "$GITHUB_ENV"
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
6743
- name: Start Xvfb
6844
if: matrix.os == 'ubuntu-latest'
6945
run: Xvfb :99 &

.github/workflows/js-examples.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ jobs:
6464
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
6565
echo "EDGE_BIN=/opt/hostedtoolcache/msedge/stable/x64/msedge" >> "$GITHUB_ENV"
6666
echo "FF_BIN=/opt/hostedtoolcache/firefox/latest/x64/firefox" >> "$GITHUB_ENV"
67+
- name: Remove driver directories Windows
68+
if: matrix.os == 'windows-latest'
69+
run: |
70+
rm "$env:ChromeWebDriver" -r -v
71+
rm "$env:EdgeWebDriver" -r -v
72+
rm "$env:GeckoWebDriver" -r -v
73+
- name: Remove driver directories Non-Windows
74+
if: matrix.os != 'windows-latest'
75+
run: |
76+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
6777
- name: Start Xvfb
6878
if: matrix.os == 'ubuntu-latest'
6979
run: Xvfb :99 &

.github/workflows/kotlin-examples.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ jobs:
6464
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
6565
echo "EDGE_BIN=/opt/hostedtoolcache/msedge/stable/x64/msedge" >> "$GITHUB_ENV"
6666
echo "FF_BIN=/opt/hostedtoolcache/firefox/latest/x64/firefox" >> "$GITHUB_ENV"
67+
- name: Remove driver directories Windows
68+
if: matrix.os == 'windows-latest'
69+
run: |
70+
rm "$env:ChromeWebDriver" -r -v
71+
rm "$env:EdgeWebDriver" -r -v
72+
rm "$env:GeckoWebDriver" -r -v
73+
- name: Remove driver directories Non-Windows
74+
if: matrix.os != 'windows-latest'
75+
run: |
76+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
6777
- name: Start Xvfb
6878
if: matrix.os == 'ubuntu-latest'
6979
run: Xvfb :99 &

.github/workflows/python-examples.yml

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,16 @@ jobs:
3030
steps:
3131
- name: Checkout GitHub repo
3232
uses: actions/checkout@v3
33-
- name: Install Chrome for set binary test
34-
uses: browser-actions/setup-chrome@v1
35-
with:
36-
chrome-version: stable
37-
id: setup-chrome
38-
- name: Install Edge for set binary test
39-
uses: browser-actions/setup-edge@v1
40-
with:
41-
edge-version: stable
42-
id: setup-edge
43-
- name: Install Firefox for set binary test
44-
if: matrix.os != 'windows-latest'
45-
uses: browser-actions/setup-firefox@v1
46-
with:
47-
firefox-version: latest
48-
id: setup-firefox
49-
- name: Set ENV Windows
33+
- name: Remove driver directories Windows
5034
if: matrix.os == 'windows-latest'
5135
run: |
52-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> $env:GITHUB_ENV
53-
echo "EDGE_BIN=C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" >> $env:GITHUB_ENV
54-
echo "FF_BIN=C:\Program Files (x86)\Mozilla Firefox\firefox-browser.exe" >> $env:GITHUB_ENV
55-
- name: Set ENV Mac
56-
if: matrix.os == 'macos-latest'
57-
run: |
58-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
59-
echo "EDGE_BIN=/Users/runner/hostedtoolcache/msedge/stable/x64/Contents/MacOS/Microsoft Edge" >> "$GITHUB_ENV"
60-
echo "FF_BIN=/Users/runner/hostedtoolcache/firefox/latest/x64/Contents/MacOS/firefox" >> "$GITHUB_ENV"
61-
- name: Set ENV Linux
62-
if: matrix.os == 'ubuntu-latest'
36+
rm "$env:ChromeWebDriver" -r -v
37+
rm "$env:EdgeWebDriver" -r -v
38+
rm "$env:GeckoWebDriver" -r -v
39+
- name: Remove driver directories Non-Windows
40+
if: matrix.os != 'windows-latest'
6341
run: |
64-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
65-
echo "EDGE_BIN=/opt/hostedtoolcache/msedge/stable/x64/msedge" >> "$GITHUB_ENV"
66-
echo "FF_BIN=/opt/hostedtoolcache/firefox/latest/x64/firefox" >> "$GITHUB_ENV"
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
6743
- name: Start Xvfb
6844
if: matrix.os == 'ubuntu-latest'
6945
run: Xvfb :99 &
@@ -76,6 +52,11 @@ jobs:
7652
run: |
7753
python -m pip install --upgrade pip
7854
pip install -r requirements.txt
55+
- name: Set up Java
56+
uses: actions/setup-java@v3
57+
with:
58+
distribution: 'temurin'
59+
java-version: 11
7960
- name: Run tests
8061
uses: nick-invision/retry@v2.8.3
8162
with:

.github/workflows/ruby-examples.yml

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,16 @@ jobs:
3030
steps:
3131
- name: Checkout GitHub repo
3232
uses: actions/checkout@v3
33-
- name: Install Chrome for set binary test
34-
uses: browser-actions/setup-chrome@v1
35-
with:
36-
chrome-version: stable
37-
id: setup-chrome
38-
- name: Install Edge for set binary test
39-
uses: browser-actions/setup-edge@v1
40-
with:
41-
edge-version: stable
42-
id: setup-edge
43-
- name: Install Firefox for set binary test
44-
if: matrix.os != 'windows-latest'
45-
uses: browser-actions/setup-firefox@v1
46-
with:
47-
firefox-version: latest
48-
id: setup-firefox
49-
- name: Set ENV Windows
33+
- name: Remove driver directories Windows
5034
if: matrix.os == 'windows-latest'
5135
run: |
52-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> $env:GITHUB_ENV
53-
echo "EDGE_BIN=C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" >> $env:GITHUB_ENV
54-
echo "FF_BIN=C:\Program Files (x86)\Mozilla Firefox\firefox-browser.exe" >> $env:GITHUB_ENV
55-
- name: Set ENV Mac
56-
if: matrix.os == 'macos-latest'
57-
run: |
58-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
59-
echo "EDGE_BIN=/Users/runner/hostedtoolcache/msedge/stable/x64/Contents/MacOS/Microsoft Edge" >> "$GITHUB_ENV"
60-
echo "FF_BIN=/Users/runner/hostedtoolcache/firefox/latest/x64/Contents/MacOS/firefox" >> "$GITHUB_ENV"
61-
- name: Set ENV Linux
62-
if: matrix.os == 'ubuntu-latest'
36+
rm "$env:ChromeWebDriver" -r -v
37+
rm "$env:EdgeWebDriver" -r -v
38+
rm "$env:GeckoWebDriver" -r -v
39+
- name: Remove driver directories Non-Windows
40+
if: matrix.os != 'windows-latest'
6341
run: |
64-
echo "CHROME_BIN=${{ steps.setup-chrome.outputs.chrome-path }}" >> "$GITHUB_ENV"
65-
echo "EDGE_BIN=/opt/hostedtoolcache/msedge/stable/x64/msedge" >> "$GITHUB_ENV"
66-
echo "FF_BIN=/opt/hostedtoolcache/firefox/latest/x64/firefox" >> "$GITHUB_ENV"
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
6743
- name: Start Xvfb
6844
if: matrix.os == 'ubuntu-latest'
6945
run: Xvfb :99 &
@@ -75,6 +51,11 @@ jobs:
7551
- name: Install Gems
7652
working-directory: ./examples/ruby
7753
run: bundle install
54+
- name: Set up Java
55+
uses: actions/setup-java@v3
56+
with:
57+
distribution: 'temurin'
58+
java-version: 11
7859
- name: Run tests
7960
uses: nick-invision/retry@v2.8.3
8061
with:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2023 Software Freedom Conservancy (SFC)
190+
Copyright 2024 Software Freedom Conservancy (SFC)
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

examples/dotnet/SeleniumDocs/BaseChromeTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace SeleniumDocs
66
public class BaseChromeTest : BaseTest
77
{
88
[TestInitialize]
9-
public void CreateDriver()
9+
public void AutoStartDriver()
1010
{
11-
driver = new ChromeDriver();
11+
StartDriver();
1212
}
1313
}
1414
}
Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Net.Sockets;
7+
using System.Runtime.InteropServices;
8+
using System.Threading.Tasks;
19
using Microsoft.VisualStudio.TestTools.UnitTesting;
210
using OpenQA.Selenium;
311
using OpenQA.Selenium.Chrome;
@@ -7,25 +15,100 @@ namespace SeleniumDocs
715
public class BaseTest
816
{
917
protected IWebDriver driver;
18+
protected Uri GridUrl;
19+
private Process _webserverProcess;
20+
private const string ServerJarName = "selenium-server-4.16.1.jar";
21+
private static readonly string BaseDirectory = AppContext.BaseDirectory;
22+
private const string RelativePathToGrid = "../../../../../";
23+
private readonly string _examplesDirectory = Path.GetFullPath(Path.Combine(BaseDirectory, RelativePathToGrid));
1024

11-
public void StartDriver()
25+
[TestCleanup]
26+
public void Cleanup()
1227
{
13-
driver = new ChromeDriver();
28+
driver?.Quit();
29+
30+
if (_webserverProcess != null)
31+
{
32+
StopServer();
33+
}
1434
}
15-
16-
public void StartDriver(string browserVersion)
35+
36+
protected void StartDriver(string browserVersion = "stable")
1737
{
1838
ChromeOptions options = new ChromeOptions
1939
{
2040
BrowserVersion = browserVersion
2141
};
2242
driver = new ChromeDriver(options);
2343
}
24-
25-
[TestCleanup]
26-
public void QuitDriver()
44+
45+
protected async Task StartServer()
2746
{
28-
driver.Quit();
47+
if (_webserverProcess == null || _webserverProcess.HasExited)
48+
{
49+
_webserverProcess = new Process();
50+
_webserverProcess.StartInfo.FileName =
51+
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "java.exe" : "java";
52+
string port = GetFreeTcpPort().ToString();
53+
GridUrl = new Uri("http://localhost:" + port + "/wd/hub");
54+
_webserverProcess.StartInfo.Arguments = " -jar " + ServerJarName +
55+
" standalone --port " + port +
56+
" --selenium-manager true --enable-managed-downloads true";
57+
_webserverProcess.StartInfo.WorkingDirectory = _examplesDirectory;
58+
_webserverProcess.Start();
59+
await EnsureGridIsRunningAsync();
60+
}
61+
}
62+
63+
private void StopServer()
64+
{
65+
if (_webserverProcess != null && !_webserverProcess.HasExited)
66+
{
67+
_webserverProcess.Kill();
68+
_webserverProcess.Dispose();
69+
_webserverProcess = null;
70+
}
71+
}
72+
73+
private static int GetFreeTcpPort()
74+
{
75+
TcpListener l = new TcpListener(IPAddress.Loopback, 0);
76+
l.Start();
77+
int port = ((IPEndPoint)l.LocalEndpoint).Port;
78+
l.Stop();
79+
return port;
80+
}
81+
82+
private async Task EnsureGridIsRunningAsync()
83+
{
84+
DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(30));
85+
bool isRunning = false;
86+
HttpClient client = new HttpClient();
87+
88+
while (!isRunning && DateTime.Now < timeout)
89+
{
90+
try
91+
{
92+
HttpResponseMessage response = await client.GetAsync(GridUrl + "/status");
93+
if (response.IsSuccessStatusCode)
94+
{
95+
isRunning = true;
96+
}
97+
else
98+
{
99+
await Task.Delay(500);
100+
}
101+
}
102+
catch (HttpRequestException)
103+
{
104+
await Task.Delay(500);
105+
}
106+
}
107+
108+
if (!isRunning)
109+
{
110+
throw new TimeoutException("Could not confirm the remote selenium server is running within 30 seconds");
111+
}
29112
}
30113
}
31114
}

0 commit comments

Comments
 (0)