Skip to content

Commit dad9990

Browse files
authored
Merge branch 'trunk' into issue/12491
2 parents 9756f59 + 7386549 commit dad9990

File tree

373 files changed

+15275
-9238
lines changed

Some content is hidden

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

373 files changed

+15275
-9238
lines changed

.github/workflows/dotnet-examples.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,28 @@ jobs:
3030
steps:
3131
- name: Checkout GitHub repo
3232
uses: actions/checkout@v3
33+
- name: Remove driver directories Windows
34+
if: matrix.os == 'windows-latest'
35+
run: |
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'
41+
run: |
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
3343
- name: Start Xvfb
3444
if: matrix.os == 'ubuntu-latest'
3545
run: Xvfb :99 &
3646
- name: Set up .Net
3747
uses: actions/setup-dotnet@v3
3848
with:
3949
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
4055
- name: Run tests
4156
uses: nick-invision/[email protected]
4257
with:

.github/workflows/java-examples.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ jobs:
3030
steps:
3131
- name: Checkout GitHub repo
3232
uses: actions/checkout@v3
33+
- name: Remove driver directories Windows
34+
if: matrix.os == 'windows-latest'
35+
run: |
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'
41+
run: |
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
3343
- name: Start Xvfb
3444
if: matrix.os == 'ubuntu-latest'
3545
run: Xvfb :99 &

.github/workflows/js-examples.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,50 @@ 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
50+
if: matrix.os == 'windows-latest'
51+
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'
63+
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"
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
3377
- name: Start Xvfb
3478
if: matrix.os == 'ubuntu-latest'
3579
run: Xvfb :99 &

.github/workflows/kotlin-examples.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,50 @@ 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
50+
if: matrix.os == 'windows-latest'
51+
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'
63+
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"
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
3377
- name: Start Xvfb
3478
if: matrix.os == 'ubuntu-latest'
3579
run: Xvfb :99 &

.github/workflows/python-examples.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ jobs:
3030
steps:
3131
- name: Checkout GitHub repo
3232
uses: actions/checkout@v3
33+
- name: Remove driver directories Windows
34+
if: matrix.os == 'windows-latest'
35+
run: |
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'
41+
run: |
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
3343
- name: Start Xvfb
3444
if: matrix.os == 'ubuntu-latest'
3545
run: Xvfb :99 &
@@ -42,6 +52,11 @@ jobs:
4252
run: |
4353
python -m pip install --upgrade pip
4454
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
4560
- name: Run tests
4661
uses: nick-invision/[email protected]
4762
with:

.github/workflows/ruby-examples.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ jobs:
3030
steps:
3131
- name: Checkout GitHub repo
3232
uses: actions/checkout@v3
33+
- name: Remove driver directories Windows
34+
if: matrix.os == 'windows-latest'
35+
run: |
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'
41+
run: |
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
3343
- name: Start Xvfb
3444
if: matrix.os == 'ubuntu-latest'
3545
run: Xvfb :99 &
@@ -41,6 +51,11 @@ jobs:
4151
- name: Install Gems
4252
working-directory: ./examples/ruby
4353
run: bundle install
54+
- name: Set up Java
55+
uses: actions/setup-java@v3
56+
with:
57+
distribution: 'temurin'
58+
java-version: 11
4459
- name: Run tests
4560
uses: nick-invision/[email protected]
4661
with:

examples/dotnet/HelloSelenium.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using OpenQA.Selenium.Chrome;
2+
3+
namespace SeleniumDocs.Hello;
4+
5+
public static class HelloSelenium
6+
{
7+
public static void Main()
8+
{
9+
var driver = new ChromeDriver();
10+
11+
driver.Navigate().GoToUrl("https://selenium.dev");
12+
13+
driver.Quit();
14+
}
15+
}
Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,119 @@
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;
11+
using OpenQA.Selenium.Chrome;
312

413
namespace SeleniumDocs
514
{
615
public class BaseTest
716
{
817
protected IWebDriver driver;
18+
protected Uri GridUrl;
19+
private Process _webserverProcess;
20+
private const string ServerJarName = "selenium-server-4.15.0.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));
924

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

0 commit comments

Comments
 (0)