Reputation: 1877
public class A{
WebDriver driver;
JavascriptExecutor js = (JavascriptExecutor) driver;
@Test
js.executeScript("alert('hello world');");
}
doesn't work; whereas
public class A{
WebDriver driver;
@Test
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("alert('hello world');");
}
works fine.I can't understand why?
Upvotes: 0
Views: 240
Reputation: 5809
Assuming that is the code you have then the first example wouldn't work because you would be assigning null to the JavascriptExecutor, because you have not instantiated the driver at the point you instantiated the executor. In the second example I assume you did in some setup method.
This might just be because your code to illustrate your example is wrong though...
Upvotes: 1