-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Implementation of Selenium Manager #11120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c927d4b
08dcad6
ba18ecc
eecdaca
69a327e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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__", | ||
| ], | ||
| ) | ||
| 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| Directory.CreateDirectory(path); | ||
| var filePath = Path.Combine(path, "selenium-manager" + extension); | ||
|
|
||
| using (BinaryWriter binWriter = new BinaryWriter(File.Open(filePath, FileMode.Create))) | ||
| { | ||
| binWriter.Flush(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant invocation,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,10 @@ | |
| <Visible>False</Visible> | ||
| <LogicalName>webdriver_prefs.json</LogicalName> | ||
| </EmbeddedResource> | ||
| <EmbeddedResource Include="$(ProjectDir)..\..\..\common\manager\windows\selenium-manager.exe"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: 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).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah; the real question is whether we can do that with Bazel...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think yes. Bazel uses If we can resolve it, then it will resolve my other concern completely.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
@@ -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> | ||
|
|
||
| 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", | ||
| ) |

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the PR!