Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 12 additions & 10 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,8 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.7.10
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Chrome and ChromeDriver
uses: ./.github/actions/setup-chrome
- name: Setup Chrome
uses: browser-actions/setup-chrome@latest
- name: Start XVFB
run: Xvfb :99 &
- name: Start Fluxbox
Expand Down Expand Up @@ -179,8 +175,11 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Firefox and GeckoDriver
uses: ./.github/actions/setup-firefox
- name: Setup Firefox
uses: abhi1693/setup-browser@v0.3.4
with:
browser: firefox
version: latest
- name: Start XVFB
run: Xvfb :99 &
- name: Start Fluxbox
Expand Down Expand Up @@ -219,8 +218,11 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Setup Firefox and GeckoDriver
uses: ./.github/actions/setup-firefox
- name: Setup Firefox
uses: abhi1693/setup-browser@v0.3.4
with:
browser: firefox
version: latest
- name: Start Xvfb
run: Xvfb :99 &
- name: Start Fluxbox
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: ${{ matrix.ruby }}
- name: Cache Bazel artifacts
uses: actions/cache@v2
with:
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ JAVA_RELEASE_TARGETS = %w[
//java/src/org/openqa/selenium/ie:ie.publish
//java/src/org/openqa/selenium/json:json.publish
//java/src/org/openqa/selenium/lift:lift.publish
//java/src/org/openqa/selenium/manager:manager.publish
//java/src/org/openqa/selenium/remote/http/jdk:jdk.publish
//java/src/org/openqa/selenium/remote/http:http.publish
//java/src/org/openqa/selenium/remote:remote.publish
Expand Down
30 changes: 30 additions & 0 deletions common/manager/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
filegroup(
name = "manager",
srcs = glob([
"*",
"**/*",
]),
visibility = [
"//java/test/org/openqa/selenium/chrome:__pkg__",
"//java/test/org/openqa/selenium/edge:__pkg__",
"//java/test/org/openqa/selenium/firefox:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
],
)

exports_files(
[
"linux/selenium-manager",
"macos/selenium-manager",
"windows/selenium-manager.exe",
],
visibility = [
"//java/src/org/openqa/selenium/manager:__pkg__",
"//java/test/org/openqa/selenium/chrome:__pkg__",
"//java/test/org/openqa/selenium/edge:__pkg__",
"//java/test/org/openqa/selenium/firefox:__pkg__",
"//py:__pkg__",
"//rb:__pkg__",
Copy link
Member

@harsha509 harsha509 Oct 28, 2022

Choose a reason for hiding this comment

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

can we add this too for JS.
//javascript/node/selenium-webdriver:__pkg__

the implementation goes in here #11189

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, let's add in your PR

Copy link
Member

Choose a reason for hiding this comment

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

Updated the PR!

],
)
Binary file added common/manager/linux/selenium-manager
Binary file not shown.
Binary file added common/manager/macos/selenium-manager
Binary file not shown.
Binary file added common/manager/windows/selenium-manager.exe
Binary file not shown.
22 changes: 19 additions & 3 deletions dotnet/src/webdriver/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,23 @@ protected DriverService(string servicePath, int port, string driverServiceExecut
string executablePath = Path.Combine(servicePath, driverServiceExecutableName);
if (!File.Exists(executablePath))
{
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture, "The file {0} does not exist. The driver can be downloaded at {1}", executablePath, driverServiceDownloadUrl));
try
{
executablePath = SeleniumManager.DriverPath(driverServiceExecutableName);
}
catch (Exception e)
{
// No-op; entirely a fall-back feature
}

if (File.Exists(executablePath))
{
servicePath = Path.GetDirectoryName(executablePath);
}
else
{
throw new DriverServiceNotFoundException(string.Format(CultureInfo.InvariantCulture, "The file {0} does not exist. The driver can be downloaded at {1}", executablePath, driverServiceDownloadUrl));
}
}

this.driverServicePath = servicePath;
Expand All @@ -74,12 +90,12 @@ protected DriverService(string servicePath, int port, string driverServiceExecut
}

/// <summary>
/// Occurs when the driver process is starting.
/// Occurs when the driver process is starting.
/// </summary>
public event EventHandler<DriverProcessStartingEventArgs> DriverProcessStarting;

/// <summary>
/// Occurs when the driver process has completely started.
/// Occurs when the driver process has completely started.
/// </summary>
public event EventHandler<DriverProcessStartedEventArgs> DriverProcessStarted;

Expand Down
146 changes: 146 additions & 0 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// <copyright file="SeleniumManager.cs" company="WebDriver 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 System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using OpenQA.Selenium.Internal;

namespace OpenQA.Selenium
{
/// <summary>
/// Wrapper for the Selenium Manager binary.
/// </summary>
public static class SeleniumManager
{
private static string binary;
private static readonly List<string> KnownDrivers = new List<string>() {
"geckodriver.exe",
"chromedriver.exe"
};

/// <summary>
/// Determines the location of the correct driver.
/// </summary>
/// <param name="driverName">Which driver the service needs.</param>
/// <returns>
/// The location of the driver.
/// </returns>
public static string DriverPath(string driverName)
{
if (!KnownDrivers.Contains(driverName))
{
throw new WebDriverException("Unable to locate driver with name: " + driverName);
}
var binaryFile = Binary;
if (binaryFile == null) return null;

var arguments = "--driver " + driverName.Replace(".exe", "");
var output = RunCommand(binaryFile, arguments);
return output.Replace("INFO\t", "").TrimEnd();
}

/// <summary>
/// Gets the location of the correct Selenium Manager binary.
/// </summary>
private static string Binary
{
get
{
if (string.IsNullOrEmpty(binary))
{
string folder = "windows";
string extension = ".exe";

if (!Environment.OSVersion.Platform.ToString().StartsWith("Win"))
{
throw new WebDriverException("Selenium Manager only supports Windows in .NET at this time");
}

try
{
string name = "selenium-manager-" + folder;
using (Stream fileStream = ResourceUtilities.GetResourceStream(name, name))
{
using (BinaryReader binReader = new BinaryReader(fileStream, Encoding.ASCII))
{
byte[] fileBytes = binReader.ReadBytes((int)fileStream.Length);
string directoryName = string.Format(CultureInfo.InvariantCulture, "webdriver.{0}",
Guid.NewGuid().ToString("N"));
var path = Path.Combine(Path.GetTempPath(), directoryName + "/" + folder);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that writing to %temp% directory is good. Given that each time it creates new folder, disk space is used irrationally. Executing 100 tests produces 100 files which will be unpredictably cleaned up by OS. Supposably it's better to copy binary file to user's app space like Environment.CurrentDirectory, and make copying process thread-safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

well, it should be once per process, not once per test at least, since it is static method.
I think the next step is putting it in $Home/.cache/manager/ (similar to how we're storing the drivers themselves)
but then we'd need logic to make sure we have the latest version.

Directory.CreateDirectory(path);
var filePath = Path.Combine(path, "selenium-manager" + extension);

using (BinaryWriter binWriter = new BinaryWriter(File.Open(filePath, FileMode.Create)))
{
binWriter.Flush();
Copy link
Member

Choose a reason for hiding this comment

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

Redundant invocation, Flush is automatically used when disposing.

Copy link
Member Author

Choose a reason for hiding this comment

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

but the flush is before the writing not after (with the disposal). tbh I'm not sure why you need it, I was going off of what I saw someone else doing...

binWriter.Write(fileBytes);
}
binary = filePath;
}
}
}
catch (Exception ex)
{
throw new WebDriverException("Unable to obtain Selenium Manager", ex);
}
}

return binary;
}
}

/// <summary>
/// Executes a process with the given arguments.
/// </summary>
/// <param name="fileName">The path to the Selenium Manager.</param>
/// <param name="arguments">The switches to be used by Selenium Manager.</param>
/// <returns>
/// the standard output of the execution.
/// </returns>
private static string RunCommand(string fileName, string arguments)
{
Process process = new Process();
process.StartInfo.FileName = fileName;
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;

try
{
process.Start();
}
catch (Exception ex)
{
throw new WebDriverException("Error starting process: " + process, ex);
}

String output = process.StandardOutput.ReadToEnd();

if (!output.StartsWith("INFO")) {
throw new WebDriverException("Invalid response from process: " + process);
Copy link
Member

Choose a reason for hiding this comment

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

Include output into exception message to see what exactly the process wrote.

Copy link
Member Author

Choose a reason for hiding this comment

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

right now output is always an empty string if there's a problem. If/when we start outputting more things (like errors), we can update.

}

return output;
}
}
}
8 changes: 8 additions & 0 deletions dotnet/src/webdriver/WebDriver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
<Visible>False</Visible>
<LogicalName>webdriver_prefs.json</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(ProjectDir)..\..\..\common\manager\windows\selenium-manager.exe">
Copy link
Member

Choose a reason for hiding this comment

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

As I understand it includes exe file embedded into dll. Given that how many target frameworks you support, total size of nuget package will increase significantly:

image

There is easier way. Include exe file anewhere in nuget package, and then copy this file to anywhere while user compiles his project (using msbuild tagets).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah; the real question is whether we can do that with Bazel...

Copy link
Member

@nvborisenko nvborisenko Oct 27, 2022

Choose a reason for hiding this comment

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

I think yes. Bazel uses nuspec definition file to create nuget package. Here we can include any files like image is already included <file src="../icon.png" target="images\" />. The same we can use to include *.exe and *.targets files.

If we can resolve it, then it will resolve my other concern completely.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, I built the nupkg and it went from 5MB to 15MB, so not storing it for each framework, thankfully.

<Visible>False</Visible>
<LogicalName>selenium-manager-windows</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(ProjectDir)..\..\..\bazel-bin\javascript\webdriver\atoms\get-attribute.js">
<Visible>False</Visible>
<LogicalName>get-attribute.js</LogicalName>
Expand All @@ -140,6 +144,10 @@
<Visible>False</Visible>
<LogicalName>webdriver_prefs.json</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(ProjectDir)../../../common/manager/windows/selenium-manager.exe">
<Visible>False</Visible>
<LogicalName>selenium-manager-windows</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(ProjectDir)../../../bazel-bin/javascript/webdriver/atoms/get-attribute.js">
<Visible>False</Visible>
<LogicalName>get-attribute.js</LogicalName>
Expand Down
41 changes: 41 additions & 0 deletions java/src/org/openqa/selenium/manager/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//common:defs.bzl", "copy_file")
load("//java:defs.bzl", "java_export")
load("//java:version.bzl", "SE_VERSION")

java_export(
name = "manager",
srcs = glob(["*.java"]),
maven_coordinates = "org.seleniumhq.selenium:selenium-manager:%s" % SE_VERSION,
pom_template = "//java/src/org/openqa/selenium:template-pom",
resources = [
":manager-linux",
":manager-macos",
":manager-windows",
],
visibility = [
"//visibility:public",
],
deps = [
"//java/src/org/openqa/selenium:core",
artifact("com.google.guava:guava"),
],
)

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

copy_file(
name = "manager-windows",
src = "//common/manager:windows/selenium-manager.exe",
out = "windows/selenium-manager.exe",
)

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