Skip to content

Commit 0fdfdc7

Browse files
authored
use driver finder for all binary location (SeleniumHQ#1520)
[deploy site]
1 parent 5fc5d42 commit 0fdfdc7

Some content is hidden

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

61 files changed

+1189
-1226
lines changed

.github/workflows/dotnet-examples.yml

+2-29
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,14 @@ 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=${{ steps.setup-edge.outputs.edge-path }}" >> $env:GITHUB_ENV
54-
- name: Set ENV Other
55-
if: matrix.os != 'windows-latest'
56-
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"
6033
- name: Remove driver directories Windows
61-
if: matrix.os == 'windows'
34+
if: matrix.os == 'windows-latest'
6235
run: |
6336
rm "$env:ChromeWebDriver" -r -v
6437
rm "$env:EdgeWebDriver" -r -v
6538
rm "$env:GeckoWebDriver" -r -v
6639
- name: Remove driver directories Non-Windows
67-
if: matrix.os != 'windows'
40+
if: matrix.os != 'windows-latest'
6841
run: |
6942
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
7043
- name: Start Xvfb

.github/workflows/java-examples.yml

+2-36
Original file line numberDiff line numberDiff line change
@@ -30,48 +30,14 @@ 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"
6733
- name: Remove driver directories Windows
68-
if: matrix.os == 'windows'
34+
if: matrix.os == 'windows-latest'
6935
run: |
7036
rm "$env:ChromeWebDriver" -r -v
7137
rm "$env:EdgeWebDriver" -r -v
7238
rm "$env:GeckoWebDriver" -r -v
7339
- name: Remove driver directories Non-Windows
74-
if: matrix.os != 'windows'
40+
if: matrix.os != 'windows-latest'
7541
run: |
7642
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
7743
- name: Start Xvfb

.github/workflows/js-examples.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ jobs:
6565
echo "EDGE_BIN=/opt/hostedtoolcache/msedge/stable/x64/msedge" >> "$GITHUB_ENV"
6666
echo "FF_BIN=/opt/hostedtoolcache/firefox/latest/x64/firefox" >> "$GITHUB_ENV"
6767
- name: Remove driver directories Windows
68-
if: matrix.os == 'windows'
68+
if: matrix.os == 'windows-latest'
6969
run: |
7070
rm "$env:ChromeWebDriver" -r -v
7171
rm "$env:EdgeWebDriver" -r -v
7272
rm "$env:GeckoWebDriver" -r -v
7373
- name: Remove driver directories Non-Windows
74-
if: matrix.os != 'windows'
74+
if: matrix.os != 'windows-latest'
7575
run: |
7676
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
7777
- name: Start Xvfb

.github/workflows/kotlin-examples.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ jobs:
6565
echo "EDGE_BIN=/opt/hostedtoolcache/msedge/stable/x64/msedge" >> "$GITHUB_ENV"
6666
echo "FF_BIN=/opt/hostedtoolcache/firefox/latest/x64/firefox" >> "$GITHUB_ENV"
6767
- name: Remove driver directories Windows
68-
if: matrix.os == 'windows'
68+
if: matrix.os == 'windows-latest'
6969
run: |
7070
rm "$env:ChromeWebDriver" -r -v
7171
rm "$env:EdgeWebDriver" -r -v
7272
rm "$env:GeckoWebDriver" -r -v
7373
- name: Remove driver directories Non-Windows
74-
if: matrix.os != 'windows'
74+
if: matrix.os != 'windows-latest'
7575
run: |
7676
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
7777
- name: Start Xvfb

.github/workflows/python-examples.yml

+7-41
Original file line numberDiff line numberDiff line change
@@ -30,50 +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"
67-
- name: Remove driver directories Windows
68-
if: matrix.os == 'windows'
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'
75-
run: |
76-
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
42+
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
7743
- name: Start Xvfb
7844
if: matrix.os == 'ubuntu-latest'
7945
run: Xvfb :99 &

.github/workflows/ruby-examples.yml

+2-36
Original file line numberDiff line numberDiff line change
@@ -30,48 +30,14 @@ 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"
6733
- name: Remove driver directories Windows
68-
if: matrix.os == 'windows'
34+
if: matrix.os == 'windows-latest'
6935
run: |
7036
rm "$env:ChromeWebDriver" -r -v
7137
rm "$env:EdgeWebDriver" -r -v
7238
rm "$env:GeckoWebDriver" -r -v
7339
- name: Remove driver directories Non-Windows
74-
if: matrix.os != 'windows'
40+
if: matrix.os != 'windows-latest'
7541
run: |
7642
sudo rm -rf $CHROMEWEBDRIVER $EDGEWEBDRIVER $GECKOWEBDRIVER
7743
- name: Start Xvfb

examples/dotnet/SeleniumDocs/Browsers/ChromeTest.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ private string GetLogLocation()
171171
return _logLocation;
172172
}
173173

174-
private string GetChromeLocation()
174+
private static string GetChromeLocation()
175175
{
176-
return Environment.GetEnvironmentVariable("CHROME_BIN");
176+
var options = new ChromeOptions
177+
{
178+
BrowserVersion = "stable"
179+
};
180+
DriverFinder.FullPath(options);
181+
return options.BinaryLocation;
177182
}
178183
}
179184
}

examples/dotnet/SeleniumDocs/Browsers/EdgeTest.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ private string GetLogLocation()
171171
return _logLocation;
172172
}
173173

174-
private string GetEdgeLocation()
174+
private static string GetEdgeLocation()
175175
{
176-
return Environment.GetEnvironmentVariable("EDGE_BIN");
176+
var options = new EdgeOptions
177+
{
178+
BrowserVersion = "stable"
179+
};
180+
DriverFinder.FullPath(options);
181+
return options.BinaryLocation;
177182
}
178183
}
179184
}

examples/dotnet/SeleniumDocs/Browsers/FirefoxTest.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,14 @@ private void SetWaitingDriver()
195195
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
196196
}
197197

198-
private string GetFirefoxLocation()
198+
private static string GetFirefoxLocation()
199199
{
200-
return Environment.GetEnvironmentVariable("FF_BIN");
200+
var options = new FirefoxOptions()
201+
{
202+
BrowserVersion = "stable"
203+
};
204+
DriverFinder.FullPath(options);
205+
return options.BinaryLocation;
201206
}
202207
}
203208
}

examples/dotnet/SeleniumDocs/Drivers/ServiceTest.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ public void BasicService()
2121
[TestMethod]
2222
public void DriverLocation()
2323
{
24-
var service = ChromeDriverService.CreateDefaultService(GetDriverLocation());
24+
var options = GetLatestChromeOptions();
25+
var service = ChromeDriverService.CreateDefaultService(GetDriverLocation(options));
2526

26-
driver = new ChromeDriver(service);
27+
driver = new ChromeDriver(service, options);
2728
}
2829

2930
[TestMethod]
@@ -35,9 +36,17 @@ public void DriverPort()
3536
driver = new ChromeDriver(service);
3637
}
3738

38-
private string GetDriverLocation()
39+
private static string GetDriverLocation(ChromeOptions options)
40+
{
41+
return DriverFinder.FullPath(options);
42+
}
43+
44+
private static ChromeOptions GetLatestChromeOptions()
3945
{
40-
return DriverFinder.FullPath(new ChromeOptions());
46+
return new ChromeOptions
47+
{
48+
BrowserVersion = "stable"
49+
};
4150
}
4251
}
4352
}

examples/dotnet/SeleniumDocs/Waits/WaitsTest.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public void Explicit()
5151
{
5252
driver.Url = "https://www.selenium.dev/selenium/web/dynamic.html";
5353
IWebElement revealed = driver.FindElement(By.Id("revealed"));
54-
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(2));
55-
5654
driver.FindElement(By.Id("reveal")).Click();
55+
56+
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(2));
5757
wait.Until(d => revealed.Displayed);
5858

5959
revealed.SendKeys("Displayed");
@@ -65,13 +65,14 @@ public void ExplicitOptions()
6565
{
6666
driver.Url = "https://www.selenium.dev/selenium/web/dynamic.html";
6767
IWebElement revealed = driver.FindElement(By.Id("revealed"));
68+
driver.FindElement(By.Id("reveal")).Click();
69+
6870
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(2))
6971
{
7072
PollingInterval = TimeSpan.FromMilliseconds(300),
7173
};
7274
wait.IgnoreExceptionTypes(typeof(ElementNotInteractableException));
7375

74-
driver.FindElement(By.Id("reveal")).Click();
7576
wait.Until(d => {
7677
revealed.SendKeys("Displayed");
7778
return true;
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package dev.selenium;
22

33
import org.junit.jupiter.api.BeforeEach;
4-
import org.openqa.selenium.chrome.ChromeDriver;
54

65
public class BaseChromeTest extends BaseTest {
76

8-
@BeforeEach
9-
public void setup() {
10-
System.setProperty("webdriver.chrome.logfile", "chromedriver.log");
11-
System.setProperty("webdriver.chrome.verboseLogging", "true");
12-
driver = new ChromeDriver();
13-
}
14-
7+
@BeforeEach
8+
public void setup() {
9+
startChromeDriver();
10+
}
1511
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package dev.selenium;
22

33
import org.junit.jupiter.api.BeforeEach;
4-
import org.openqa.selenium.firefox.FirefoxDriver;
54

65
public class BaseFirefoxTest extends BaseTest {
76

8-
@BeforeEach
9-
public void setup() {
10-
driver = new FirefoxDriver();
11-
}
12-
7+
@BeforeEach
8+
public void setup() {
9+
startFirefoxDriver();
10+
}
1311
}

0 commit comments

Comments
 (0)