Hi Im a newbie to selenium, i was trying to use TestNG with IE webdriver, Now i cant instantiate the IE driver directly under the class (Not the main method). When i do that i get the below error: Multiple markers at this line - Syntax error on tokens, FormalParameter expected instead - Syntax error on token(s), misplaced construct(s) - Syntax error on token ""webdriver.ie.driver"", invalid
If i then put on a method with @BeforeSuite annotation, i need to pass the driver to every other test method in the class. Is there a way where i can by pass this passing the driver object.
Find below the sample code i am using:
package FirstTestNGPackage;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class FirstTestNGclass {
@BeforeSuite
public void SetDriverPaths()
{
File IEDriver = new File("C:\\Users\\REDACTED\\Desktop\\SeleniumJars\\IE Driver\\IEDriverServerX64_2.44.0.exe");
System.setProperty("webdriver.ie.driver", IEDriver.getAbsolutePath());
WebDriver Driver = new InternetExplorerDriver();
}
@Test
public void tester()
{
Driver.findElement(By.id("keywordInput")).sendKeys("REDACTED");
Driver.findElement(By.id("keywordInput")).sendKeys(Keys.ENTER);
Assert.assertEquals(Driver.findElement(By.xpath(".//*[@id='search_results']/h1/span/strong")).getText(), "REDACTED");
}
@BeforeTest
public void RMSLogin()
{
Driver.navigate().to("REDACTED");
}
@AfterTest
public void closeBrowser()
{
Driver.quit();
}
}
init you webdriver like this then you can use it in every method with
this.driver
.