【问题标题】:Executing Specific tests in selenium (Maven project in eclipse IDE)在 selenium 中执行特定测试(eclipse IDE 中的 Maven 项目)
【发布时间】:2017-06-14 13:22:35
【问题描述】:

我正在使用 Selenium-Java 进行自动化。我在 Eclipse IDE 中创建了 maven 项目。我正在使用 @Test Annotation 运行测试用例。当我有许多要运行的测试用例时,我使用(priority=1,2 and so)enabled=false,这必须被禁用。有没有其他方法可以做,因为如果我说 100 个测试,其中 50 个需要运行,那么我需要禁用 50 个,这真的很忙。

【问题讨论】:

    标签: java maven selenium


    【解决方案1】:

    您可以使用 TestNG 组将测试组合在一起并运行它。

    您可以在 testNG.xml 文件中使用包含或排除方法并从那里运行测试。也可以使用Regex来定义排除方法。

    请参考 testNG 文档 -

    http://testng.org/doc/documentation-main.html

    2. 如果您没有使用 testNG,并且您想根据方法名称跳过测试用例,您可以执行以下操作 -

    @BeforeMethod
    public void nameBefore(Method method)
    {
        // You can define any condition on which you want to skip your tests.
        if(method.getName().matches("disabled")){
            throw new SkipException("Skipping test method");
        }       
    }
    

    3.如果你想禁用整个类中存在的所有测试方法,那么你可以使用 -

    @Test(enable=false)
    class MyClass{
      // Test methods
    } 
    

    【讨论】:

    • 正如我已经提到的,我正在使用 maven 项目,没有名为 testNG.xml 的文件。我可以有一些称为自定义测试类的东西,它将根据选择运行测试方法吗?更准确地说,只需给出测试方法名称?
    • 我已经更新了我的答案。这可能会解决您的问题
    猜你喜欢
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 2019-03-05
    • 2017-08-08
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多