How do I declare a driver as global?

Indigo

Here is how I declare firefox driver:

public static WebDriver driver = new FirefoxDriver();

I place the code above outside main and within my class (global)

Here is how I declare chrome driver:

System.setProperty("webdriver.chrome.driver", "/path/xxx/xxx/xx");
WebDriver driver  = new ChromeDriver();

I place the code above in main

Here is the issue:

I want to make the ChromeDriver as a global but I NEED to set the property before doing so. But I place the System.setProperty("xx","xx"); within the main body. Cuz it gives error when placed outside.

Here is a user trying to do the same thing as me. Trying to run different browsers using the same driver : How to run Selenium tests in multiple browsers for cross-browser testing using Java?

The answer is involves declaring the driver in the main body and not as a constant before.

My issue: All functions need driver declaration from before. Calling functions which use driver. If I declare driver in main, I need to continuously pass it as a parameter to all the functions. I do not wish to do that. Here is an example function

 public static void a(){

 driver.findElement(By.id("hi"));

}
SiKing

How about something like:

class SomeTest {

    static WebDriver driver;

    public static void main(String[] args) {

        System.setProperty("key", "value");
        driver = new ChromeDriver();
    }

    public static void a() {

        driver.findElement(By.id("hi"));

    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How do you declare a global constant in Python?

来自分类Dev

How do I run a global npm program when an ubuntu program has the same name?

来自分类Dev

In Slick 3.0 is there a way to declare Tables without using a Specific JDBC Driver

来自分类Dev

How do you declare a function in which you pass a multidimensional array by reference

来自分类常见问题

How do I resolve ClassNotFoundException?

来自分类Dev

How to declare and initialise an array in Swift

来自分类Dev

How do i sort my listview alphabetically?

来自分类Dev

How do I parse a RestSharp response into a class?

来自分类Dev

How do I override a default keybinding in LightTable?

来自分类Dev

How do I modularize polyfills in Angular?

来自分类Dev

How do I combine lenses and functors?

来自分类Dev

How do I parse JSON in Racket?

来自分类Dev

How do I link to a pdf in AngularJS?

来自分类Dev

How do I include jquery in javafx webview?

来自分类Dev

How do I retrieve the text of a cell comment

来自分类Dev

How do I write a custom module for AngularJS?

来自分类Dev

I do not understand how execlp() works in Linux

来自分类Dev

How do I iterate over a file?

来自分类Dev

How do I define the size of a CollectionView on rotate

来自分类Dev

How do I count selected checkboxes in Angular?

来自分类Dev

How do I combine three observables such that

来自分类Dev

Basic Ocaml: How do I compile this?

来自分类Dev

How do I free socket descriptors in RabbitMQ

来自分类Dev

How do I convert synchronous ajax to asynchronous?

来自分类Dev

puppet - How do I append to path variable?

来自分类Dev

How do I link boost to my program?

来自分类Dev

Passing File with intent, how do i retrieve it

来自分类Dev

How do I call an intent in Retrofit Callback?

来自分类Dev

How do I remove YUI delegated events?

Related 相关文章

热门标签

归档