Parameterization in Selenium and TestNG

和自甴很熟 提交于 2021-02-10 11:29:53

问题


I am learning Selenium by my own. I am not sure about the right way to parameterize the test cases while using Selenium with TestNG Framework. Is it better to pass the parameters in TestNG.XML file OR keep a seperate spreadsheet. For example, I need to parameterize LOGIN functionality with 100 different users' login details. Where to keep the username/password details of 100 users?

If Parametrization through a spreadsheet works best, then what exactly is the purpose of having a testng.xml file?


回答1:


For parameterization Testng provide you two methods.

  1. By TestNG XML file.
  2. By Using @DataProvider

When to use TestNG XML file?

When you want to define simple parameters for decision making you can use XML file.

Example: Simply passing browser value like ff, chrome from .xml file ie to decide the browser to be used for test case execution.

When to use @DataProvider?

Specially in Data driven testing i.e when same test method needs to be run multiple times with different data-sets you can use DataProvider and it is also used to handle complex parameters or complex objects like reading from a property file or a database, etc.

  • In your case around 100 different users' login details needs to be passed so i would suggest put them in excel file and read them using APACHE POI / JXL reason why not to go for @DataProvider is logically its bad practice to pass 100 values in your DataProvider class which may also result in poor performance and increased the complexity of your test code.



回答2:


  1. It is preferred to keep your @Test methods without any parameters.But to answer, you can parametrize your tests as explained here Parametrized tests in TestNG
  2. If you are trying to pass 100 different login details, would advice you to keep it in separate spreadsheet.


来源:https://stackoverflow.com/questions/32602762/parameterization-in-selenium-and-testng

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!