繁体   English   中英

使用注释@Parameters 时,我收到 2 条错误消息“此位置不允许注释 @Parameter”。 不知道为什么?

[英]When use annotation @Parameters, I get 2 error messages "The annotation @Parameter is disallowed for this location" . Not sure why?

我一直在关注一些博客和 testng 站点以使其正常工作,使用参数背后的想法是从 testng.xml 文件传递​​浏览器值。 但是当我在运行脚本之前将 @Parameters annotaion 错误出现在 eclipse 中时。 当我尝试验证代码时出现错误 -

错误信息

此行有多个标记 - 注释类型的属性值未定义 参数 - 参数无法解析为类型 - 此位置不允许使用注释 @Parameter

认为这里有什么问题,可能是错误的导入或某些语法错误。 我也做过进口

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;

但不起作用。 曾尝试将 @Parameters 注释放在 @Test 下方,但即使这样也不起作用。

这是我的代码 -

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.Parameters;
import org.testng.annotations.*;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class first_class {
    private Selenium selenium;
    public String url = "http://google.com/";   

    @Parameter ({ "browser" })
    @Test   
    public void Test(String browser) throws MalformedURLException {
        DesiredCapabilities capability = new DesiredCapabilities();
        capability.setBrowserName(browser);

        WebDriver driver = null;
        try {
            driver = new RemoteWebDriver(new URL("http://localhost:".concat(
                    "4444").concat("/wd/hub")), capability);
            System.out.println();

        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        selenium = new WebDriverBackedSelenium(driver, "http://www.google.com/");
        System.out.println("In Test Methos");
        selenium.open("http://www.google.com/"); 
        System.out.println(selenium.getTitle() + "in in Test Method");
        selenium.close();
    }
    }

即使我在我的程序中发现了某种错误尝试在 @parameter 注释之前编写 @before 、 @after 或 @test 注释

使用@parameters 而不是@parameter

您使用了错误的注释,请阅读 TestNG Javadoc:

http://testng.org/javadocs/org/testng/annotations/Parameters.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM