"The attribute value is undefined for the annotation type Parameters" 跨浏览器测试脚本显示错误

"The attribute value is undefined for the annotation type Parameters" error is displayed for Cross-Browser Testing Script

我正在尝试使用 Selenium 进行跨浏览器测试。

CrossBrowser.java:

package automationFramewok;

import java.net.MalformedURLException;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.opera.OperaDriver;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.beust.jcommander.Parameters;

// I am getting the following error on the next line
//
//   "The attribute value is undefined for the annotation type Parameters"
//
@Parameters({"browser"})

public class CrossBrowser {

    @SuppressWarnings("deprecation")
    @BeforeTest

    public void setUp(String browser) throws MalformedURLException {

    if (browser.equalsIgnoreCase("Firefox")) {
       System.out.println("Running Firefox");
       System.setProperty("webdriver.gecko.driver","E:\\Selenium-required files\geckodriver\geckodriver.exe");
       FirefoxDriver driver = new FirefoxDriver();
    } else if (browser.equalsIgnoreCase("chrome")) {
       System.out.println("Running Chrome");
    System.setProperty("webdriver.chrome.driver", "E:\\\\Selenium-required files\\chromedriver\\chromedriver.exe");
       ChromeDriver driver = new ChromeDriver();
    } else if (browser.equalsIgnoreCase("opera")) {
       System.out.println("Running Opera");
    // driver = new OperaDriver();       --Use this if the location is set properly--
       DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("opera.binary", "C://Program Files (x86)//Opera//opera.exe");
       capabilities.setCapability("opera.log.level", "CONFIG");
       System.setProperty("webdriver.opera.driver", "E:\\\\Selenium-required files\\operadriver\\operadriver.exe");
       OperaDriver driver = new OperaDriver(capabilities);
    }
    }
}

我收到以下错误消息:

The attribute value is undefined for the annotation type Parameters

我该如何解决这个问题?

检查您的导入语句列表。我想你想要

import org.testng.annotations.Parameters;

而不是

import com.beust.jcommander.Parameters;

我遇到了同样的问题,问题出在导入语句上。我正在使用以下导入语句。

import org.junit.runners.Parameterized.Parameters;

替换为以下导入语句,问题得到解决。

import org.testng.annotations.Parameters;