For any TestNG users out there. Building my first test. From the snippet below you can see I have annotated BeforeTest with the info to set up the Chrome browser. Then I annotate a Test which should launch the Chrome browser.
HOWEVER I am getting an error in line
UName = driver.findElement(By.name("login_user"));
It says it driver cannot be resolved.
Would appreciate help
public class FirstTestNGFile {
@BeforeTest
public void setup() {
System.setProperty("webdriver.chrome.driver", "C:\Selenium3\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// URL for ASK
String baseUrl = "https://BLAH BLAH / ";
// User and passwords
String goodUser = "wayne";
String goodPassword = "askTest17";
String badUser = "foo";
String badPassword = "badpass";
driver.get(baseUrl);
}
@Test
public void validuserpass() {
// ------------------------------------------------
// Able to login with valid username and password
// --------------------------------------------
// launch browser and direct it to the Base URL
// Enter a valid name for username
// Enter Text on Register Screen
WebElement UName;
UName = driver.findElement(By.name("login_user"));
UName.sendKeys(goodUser);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…