Skip to content
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

# 198 Support Passing Command Line Arguments To Driver #201

Merged
merged 12 commits into from
Oct 22, 2024

Conversation

oomelianchuk
Copy link
Contributor

Added driver arguments support for Chrome, Firefox, IE and Safari (Opera and PhantomJs won't be supported by Selenium in the next version, so the is no point to develop a feature for those browsers). As the most popular and, what's more important, cross-platform browsers are Chrome and Firefox, the solution was tested for these browsers, both manually and via unit tests.

PS: It would be good to know, that the solution also works for ie and safari, so feel free to try the feature out on your platform, especially if you have access to safari and ie browsers. Thanks!

}
catch (IOException e)
{
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

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

This might cause much confusion. If there's an IO error (for example due to rights issues or something), this method will return null, the calling method however will be just checking for null and ignore all given args. So someone would need to check the - hopefully somewhere logged - system log, which might be inside a docker or something else to check what happened and why the given args are not used.

We should just throw the exception and die hard and early so it's obvious that something went wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed during refactoring

{
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder();
argsBuilder.addAll(super.createArgs());
argsBuilder.add(String.format("--port=%d", port));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we set a random port here. What happens if the user is setting "---port" via args? Shouldn't this be checked before we add a random port?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adjusted

}
catch (IOException e)
{
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same argument as before.

We should just throw the exception and die hard and early so it's obvious that something went wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed during refactoring

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed during refactoring

String firefoxLogFile = logPathArgs.get(0).replaceAll("--log-path=", "").trim();
if (firefoxLogFile != null)
{
if ("/dev/stdout".equals(firefoxLogFile))
Copy link
Contributor

Choose a reason for hiding this comment

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

are there equivalents for windows OS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after refactoring delegated to Selenium (the "/dev/stdout" and "/dev/stderr", etc. are cross-platform in Selenium, these are only indicators for where to send logs output, in the end it's done via System.out or System.err)

{
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder();
// argsBuilder.addAll(super.createArgs());
argsBuilder.add(String.format("--port=%d", port));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as before, we should probably handle the case that the user wanted to manually override the port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adjusted

@@ -242,15 +242,28 @@ public interface NeodymiumConfiguration extends Mutable
@Key("neodymium.webDriver.chrome.pathToDriverServer")
public String getChromeDriverPath();

@Key("neodymium.webDriver.edge.pathToDriverServer")
public String getEdgeDriverPath();
Copy link
Contributor

Choose a reason for hiding this comment

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

why was the edge path removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for pointing this out! It should not be removed, furthermore, it missed implementation as IE and Edge now require different setups. Setup for Edge implemented. The setup for IE stays the same but it's now in investigation if we still need to support IE

Map<String, String> properties1 = new HashMap<>();
properties1.put("neodymium.webDriver.chrome.driverArguments", "--silent ; --log-path=" + randomLogFileName);
properties1.put("neodymium.webDriver.firefox.driverArguments", "--log ; fatal ; --log-path=" + randomLogFileName);
File tempConfigFile1 = new File("./config/dev-neodymium.properties");
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a handling to not get the dev-neodymium.properties removed. See (NeodymiumContextTest.java as example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@Browser("FF_headless")
public class DriverArgumentsTest extends NeodymiumTest
{
private static String randomLogFileName = "target/" + UUID.randomUUID().toString() + ".log";
Copy link
Contributor

Choose a reason for hiding this comment

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

Sine ports were handled specifically please add a unit test to check what happens if the user adds a port manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

public static void createSettings()
{
Map<String, String> properties1 = new HashMap<>();
properties1.put("neodymium.webDriver.chrome.driverArguments", "--silent ; --log-path=" + randomLogFileName);
Copy link
Contributor

Choose a reason for hiding this comment

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

The Issue has a list with possible arguments, but the issue is quite old, please check if everything is still valid for current browsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like the list for geckodriver arguments is now a bit bigger :) It should not be a problem though, as we are, mostly, not parsing the args, but simply passing them to the driver. The user should know better what args can be passed. The best way to check, what args are supported by the current driver version is to do " --help"

@RunWith(NeodymiumRunner.class)
@Browser("Chrome_headless")
@Browser("FF_headless")
public class DriverArgumentsTest extends NeodymiumTest
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a test for an empty config string as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implicity covered with other tests, adding tests for invalid values will test browser behavior but not our code

@wurzelkuchen wurzelkuchen linked an issue May 17, 2024 that may be closed by this pull request
@oomelianchuk oomelianchuk requested review from wurzelkuchen and removed request for occupant23 September 11, 2024 13:36
@wurzelkuchen wurzelkuchen merged commit b2a55a0 into develop Oct 22, 2024
@wurzelkuchen wurzelkuchen deleted the support-driver-arguments branch October 22, 2024 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Passing Command Line Arguments To Driver
2 participants