简体   繁体   English

当无法通过“系统属性”或“路径”指定壁虎驱动程序位置时,是否有一种非远程的方式来指定它?

[英]Is there a non-remote way to specify geckodriver location when you cannot specify it by System property or Path?

In my application I cannot set geckodriver executable location using System.setProperty and I cannot set it in the path. 在我的应用程序中,无法使用System.setProperty设置geckodriver可执行文件的位置,也无法在路径中设置它。

Why? 为什么? Because my app is multi-tenant... and each tenant has their own directory where Firefox and Geckodriver is copied and ran. 因为我的应用程序是多租户...,并且每个租户都有自己的目录,所以Firefox和Geckodriver可以在其中复制和运行。 This is due to bugs in the Firefox + Geckodriver, where infinite javascript loops and several other situations cause Firefox to hang until manual kill. 这是由于Firefox + Geckodriver中的错误所致,在该错误中,无限的javascript循环和其他几种情况导致Firefox挂起,直到被手动杀死为止。 Sometimes quit fails to kill things completely as well. 有时,戒烟并不能完全杀死人们。 So we need to supply a custom geckodriver location within the JVM per-tenant . 因此,我们需要在JVM 每个租户中提供一个自定义的geckodriver位置。 Thus the problem. 这样的问题。

So I am instead using: 所以我改为使用:

driverService = new GeckoDriverService.Builder()
          .usingDriverExecutable(new File(geckoDriverBinaryPath))
          .build();
driverService.start();
RemoteWebDriver driver = new RemoteWebDriver(driverServiceUrl, capabilities);

But that is making me use a RemoteWebDriver when I am not remote. 但这使我在不处于远程状态时使用RemoteWebDriver。

Is there a better way to do this? 有一个更好的方法吗?

Rather than calling start() on the FirefoxDriverService object, why not simply use the FirefoxDriver constructor that takes the service? 除了在FirefoxDriverService对象上调用start() FirefoxDriverService ,为什么不简单地使用接受服务的FirefoxDriver构造函数呢?

driverService = new GeckoDriverService.Builder()
      .usingDriverExecutable(new File(geckoDriverBinaryPath))
      .build();
WebDriver driver = new FirefoxDriver(driverService);

As the questions stands it is still too broad. 就问题而言,它仍然太广泛了。 There are some unknowns: How are you running this? 有一些未知数:您如何运行此程序? JUnit?, Maven?, Jenkins? JUnit?,Maven?,Jenkins? And I am still not clear where this per-tenat geckoDriverBinaryPath comes from and how it is passed around. 而且,我仍然不清楚此每人的 geckoDriverBinaryPath来自何处以及如何传递。

What is wrong with just using: 仅仅使用有什么问题?

System.setProperty("webdriver.gecko.driver", geckoDriverBinaryPath);

You could set an environment variable in your OS. 您可以在操作系统中设置环境变量。 Something like export geckoDriverBinary=/some/path and then in your code read it back using: 诸如export geckoDriverBinary=/some/path ,然后在代码中使用以下命令将其读回:

String geckoDriverBinaryPath = System.getenv("geckoDriverBinary");
System.setProperty("webdriver.gecko.driver", geckoDriverBinaryPath);
...

If you are running it from command line, either straight up or using Maven, you could pass the variable in like -DgeckoDriverBinaryPath=/some/path and then in your code read it back using: 如果您是从命令行直接运行或使用Maven运行它,则可以像-DgeckoDriverBinaryPath=/some/path这样传递变量,然后在代码中使用以下命令将其读回:

String geckoDriverBinaryPath = System.getProperty("geckoDriverBinary");
System.setProperty("webdriver.gecko.driver", geckoDriverBinaryPath);
...

If the different tenants have the path fixed, you could write a utility function that would detect which tenant it is being run on, and set the property accordingly. 如果不同的租户固定了路径,则可以编写一个实用程序函数,该函数将检测正在运行该租户的租户,并相应地设置属性。

This answer is probably going to get closed as not-answer, but more of a discussion. 这个答案很可能会以没有答案的形式被关闭,只是更多的讨论。 :( :(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM