Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium定义要在多个测试中共享的常量变量_Java_Variables_Selenium_Selenium Webdriver - Fatal编程技术网

Java Selenium定义要在多个测试中共享的常量变量

Java Selenium定义要在多个测试中共享的常量变量,java,variables,selenium,selenium-webdriver,Java,Variables,Selenium,Selenium Webdriver,我想在selenium中的多个测试中共享一个常量变量 例如String text=“测试上的共享文本”您可以将其定义为包含所有共享内容的类: public class TestConstants { public static final String SHARED_TEXT = "My shared text"; } 然后在测试中,您可以简单地将其引用为: TestConstants.SHARED_TEXT.equals(actualText); 或者,无论您如何需要它,您都可以这样定

我想在selenium中的多个测试中共享一个常量变量
例如
String text=“测试上的共享文本”

您可以将其定义为包含所有共享内容的类:

public class TestConstants {
  public static final String SHARED_TEXT = "My shared text";
}
然后在测试中,您可以简单地将其引用为:

TestConstants.SHARED_TEXT.equals(actualText);

或者,无论您如何需要它,您都可以这样定义常量类:

public class Constants {
// now here you can define your constant variables 
public static text = "the shared text over tests";
}
现在,您可以在包的任何类中使用常量变量,如下所示:

String constantText = Constants.text;