简体   繁体   English

如果两者都需要在同一类的每个@Test中运行,则如何使用多个凭据验证登录功能[在Maven POM Selenium项目中]

[英]How to verify login functionality with multiple credentials if Both need to run in every @Test in a same Class[In Maven POM Selenium project]

我想在具有两个凭据的同一类中运行测试,并且两者都在同一TestRunner类中,所以我想在@Beforemethod类中声明,这样就无需在每个@Test编写相同的代码。

If I understood, You want to run same test twice, but with different credentials. 据我了解,您希望两次运行相同的测试,但是使用不同的凭据。

If this is the case use dataProvider: 如果是这种情况,请使用dataProvider:

@DataProvider(name="login")
    public Object[][] getData() {
        return new Object[][] {
            {"test2@test.com", "test",false},
            {"test@test.com", "abcabc",true}
        };
    }

and here is method how to call it. 这是如何调用它的方法。

@Test(dataProvider="login")
public void testLogin(String usernameEmail, String password,boolean flag) throws InterruptedException {

  if(flag){
      Assert.assertTrue(!errorMessage.isDisplayed());
  }else{
      Assert.assertTrue(errorMessage.isDisplayed());
  }
}

Hope I understood and it would help You, 希望我能理解,对您有帮助,

Updated answer with pseudo code of a sort, so You could create method without annotation just simple method inside test class or in different one, depending on Your logic, and provide parameter to that method within test methods here is example: 更新了带有某种伪代码的答案,因此您可以根据逻辑,在测试类内部或在不同类中创建不带注释的简单方法,并在测试方法中为该方法提供参数,例如:

Don't know how You data is set in @BeforeMethod, because there is no code example, but here is something: 不知道如何在@BeforeMethod中设置您的数据,因为没有代码示例,但是这里有一些内容:

@Test
public void testLogin_1(){
    login(email, password)
}

@Test
public void testLogin_2(){
    login(email2, password2)
}


private void login(String email, String password){
   inputEmail(email);
   inputPassword(password);
   clickSubmit();

   Assert.assertEquals();
   // do some asserts so if You want to assert some error cases.
}

Hope this helps, 希望这可以帮助,

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

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