I had tried using System.setProperty
in main method with no issues, but when I switched to TestNG
as part of my Selenium learning, I realized we cannot write System.setProperty
at Class level. It should be either at method level or be in a static
block. I just want to understand what is the feature of Java that is compelling us to do this.
public class NewTest {
public String baseUrl = "http://newtours.demoaut.com/";
static {
System.setProperty("webdriver.chrome.driver","D:\\paths\\chromedriver.exe");
}
WebDriver driver = new ChromeDriver();
@Test
public void f1() {
...}
}
Writing this outside of static block shows compilation error like "Multiple markers at this line, Syntax error"