I am using selenium webdriver , via Java & TestNG.
I've just tried the following code: (for starting chrome browser),
package testng1package;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.AssertJUnit;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.annotations.AfterTest;
public class TestNGFile {
//using firefox
//public WebDriver driver = new FirefoxDriver() ;
//using Chrome
System.setProperty("webdriver.chrome.driver", "C://Users//Roey//Desktop//chromedriver.exe");
public WebDriver driver = new ChromeDriver();
String baseurl = "http://newtours.demoaut.com/" ;
@BeforeTest
public void StartBrowser() {
}
@Test
public void Test1() {
driver.get(baseurl);
String expectedTitle = "Welcome: Mercury Tours" ;
String actualTitle = driver.getTitle();
AssertJUnit.assertEquals(actualTitle , expectedTitle) ;
driver.quit();
}
@AfterTest
public void terminateBrowser() {
driver.quit();
}
}
the test contain error on the system.setproperty, and says:
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on tokens, delete these tokens
If I am cutting and pasting this code line into the @test - it's ok, but I want to use it from the @BeforeTest or the beginning ( as it is it now).