测试注释代码不起作用,只是BeforeMethod起作用

时间:2019-02-04 12:31:13

标签: selenium-webdriver testng

我的代码在@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("123@p.com");
     driver.findElement(By.id("password")).sendKeys("123456");
     driver.findElement(By.id("cta")).click();
     System.out.println("Login Sucessfully");
    }

1 个答案:

答案 0 :(得分:0)

从此行删除webdriver可解决此问题; WebDriver驱动程序=新的C​​hromeDriver();

感谢您对此的关注:-)