我的代码工作,直到@BeforeMethod,它是开放的URL,但什么我@Test后输入无法正常工作。它不键入登录页面上的凭证,因此测试失败。
package com.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
// import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Great {
WebDriver driver;
@BeforeMethod
public void setup()
{
System.setProperty("webdriver.chrome.driver", "C:\\Program Files
(x86)\\Google\\Chrome\\Application\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseurl = "https://getfieldforce.com/dishqa";
driver.get(baseurl);
// Actions act = new Actions(driver);
}
@Test (priority=0)
public void login()
{
System.out.println("Login process starts");
driver.findElement(By.id("email")).sendKeys("[email protected]");
driver.findElement(By.id("password")).sendKeys("123456");
driver.findElement(By.id("cta")).click();
System.out.println("Login Sucessfully");
}
从该行删除的webdriver解决了该问题;驾驶员的webdriver =新ChromeDriver();
感谢您查看这个 :-)