简体   繁体   English

谁能给出一个关于用testng和eclipse在Selenium Web驱动程序中实现脚本的最佳方法的想法?

[英]Can any one give an idea about best way of implementing script in selenium web driver with testng and eclipse?

I have started writing selenium web driver script using with TestNg and Eclipse . 我已经开始使用TestNg和Eclipse编写Selenium Web驱动程序脚本。 Can any one suggest basic idea and better way of scripting ? 有人可以提出基本思路和更好的脚本编写方式吗?

Currently i am working a big project which have so many modules. 目前,我正在一个有很多模块的大型项目。 I have to automate some test case in all modules. 我必须在所有模块中自动化一些测试用例。 So how will i start with ?? 那么我将如何开始呢?

1, I have to create separate class on writing script for each module ?? 1,我必须为每个模块的编写脚本创建单独的类?

2, Since login script is common , how can i reuse its script on each module ?? 2,由于登录脚本是常见的,我如何在每个模块上重用其脚本?

Can any one share idea about creating classes and writing script and running it ?? 谁能分享有关创建类和编写脚本并运行它的想法?

Let me try to address your Questions one by one: 让我尝试一一解答您的问题:

  1. I have to create separate class on writing script for each module : A lot depends on how you design your framework. I have to create separate class on writing script for each module :在很大程度上取决于您如何设计框架。 Now your framework can be one of the following types : 现在,您的框架可以是以下类型之一

a. 一种。 Module Based Testing Framework 基于模块的测试框架

b. Library Architecture Testing Framework 图书馆架构测试框架

c. C。 Data Driven Testing Framework 数据驱动测试框架

d. d。 Keyword Driven Testing Framework 关键字驱动测试框架

e. Hybrid Testing Framework 混合测试框架

f. F。 Behavior Driven Development Framework 行为驱动开发框架

  1. How to select a framework? 如何选择框架? A lot will depend on the functionalities your framework would perform. 在很大程度上取决于您的框架要执行的功能。 For example, 例如,

a. 一种。 If your framework needs to test one by one component/module, Module Based Testing Framework should be your approach. 如果您的框架需要一对一测试组件/模块,则Module Based Testing Framework应该是您的方法。 PageFactory using POM is one of the best practice in-terms of performance & least maintenance. 使用POM的PageFactory是性能和最少维护方面的最佳实践之一。

b. If your framework needs to read real-time data from excel sheets, Data Driven Testing Framework should be your approach. 如果您的框架需要从excel表格中读取实时数据,则应该使用Data Driven Testing Framework

c. C。 If you are reusing a number of methods repeatedly for Assertions, Library Architecture Testing Framework should be your approach. 如果您重复使用许多方法来断言,则应该使用Library Architecture Testing Framework

d. d。 If you want to leverage the benefits of all kinds of associated frameworks then Hybrid Testing Framework should be your approach. 如果您想利用各种关联框架的优势,那么Hybrid Testing Framework您的方法。

Now depending on the design of the framework, you have to write scripts/class for each module/library. 现在,根据框架的设计,您必须为每个模块/库编写脚本/类。

  1. Since login script is common , how can i reuse its script on each module ?? : The answer to this question is situation dependent .If you follow Data Driven Testing Framework to read the different credentials from an excel file recursively, it would be a nice idea to create a separate library for that. :此问题的答案取决于情况。如果您遵循Data Driven Testing Framework以递归方式从excel文件中读取不同的凭据,那么为此创建一个单独的库将是一个不错的主意。

  2. Can any one share idea about creating classes and writing script and running it ?? : There is nothing exceptional in writing class or scripts. :编写类或脚本没有什么例外。 Choose a language of your choice among Java / Python / C# / Ruby and create your first script. 在Java / Python / C#/ Ruby中选择一种语言,然后创建您的第一个脚本。 There is a lot of documentation available within stackoverflow.com, github.com & other external sites. 在stackoverflow.com,github.com和其他外部站点中有很多文档可用。

  3. Moving forward you may like to integrate TestNG to your framework which provides a lot of flexibility to work with viz Annotations and some superb Reporting Class. 展望未来,您可能希望将TestNG集成到您的框架中,这为使用viz Annotations和一些出色的Reporting类提供了很大的灵活性。

  4. Finally you can integrate the Maven framework to help you to gather all your required dependencies in quick time to execute your framework seamlessly. 最后,您可以集成Maven框架,以帮助您快速收集所有必需的依赖关系,以无缝地执行框架。

Hope this answers all of your questions. 希望这能回答您所有的问题。

You can google 'page factory' model as a methodology for your tests. 您可以使用Google“页面工厂”模型作为测试方法。 Alternatively nothing prohibits to setup one of your own; 另外,没有什么禁止设置自己的设置。 of course depending on the nature of the business/project you are working on. 当然,这取决于您正在从事的业务/项目的性质。

Personally, I like having a TestBase class which holds major functionality (like findElement, or gotoPage, or typeChars) and then from there create a class per test case always extending the main TestBase (so you can inherit call its methods). 就个人而言,我喜欢拥有一个拥有主要功能(如findElement或gotoPage或typeChars)的TestBase类,然后从那里为每个测试用例创建一个始终扩展主要TestBase的类(以便您可以继承调用其方法)。

So to answer your questions: 因此,回答您的问题:

1) It is really up to you, but you can write a class per test case where each @Test annotation will be a test step (so you can play with dependencies and priorities) 1)确实由您决定,但是您可以为每个测试用例编写一个类,其中每个@Test批注将成为测试步骤(因此您可以使用依赖项和优先级)

2) You can write up a loginViaEmail method/function in your TestBase and call it from every test on your @BeforeClass (so it loads up your config before you start each test). 2)您可以在TestBase中编写一个loginViaEmail方法/函数,并从@BeforeClass的每个测试中调用它(这样它会在启动每个测试之前加载您的配置)。 Something like this: 像这样:

public void loginViaEmail(String email, String pass){

driver.navigate("https://yourhomepage.com");
findElement.by.xpath(loginButton).click();
// input credentials
// click login
}

Then you can go at your changePass test/class: 然后,您可以进行changePass测试/课程:

public class ChangePass extends TestBase {


    @BeforeClass
    public void intialSetup(){
    loginViaEmail("youremail@test.com", "someHardToGuessPass");
    }

    @Test public void findChangePassLink(){

    //rest of your test code
    }
}

Hope this helps, best of luck! 希望这会有所帮助,祝您好运!

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

相关问题 有什么办法可以给testNG测试命名 - Is there any way to give name to testNG test 当我在一个类中进行多个测试时,避免Java Selenium TestNG中超时的最佳方法? - Best way to avoid timeout in Java Selenium TestNG when I have multiple tests in one class? 在Selenium Web驱动程序中使用TestNG时调用方法两次 - Method invoking twice when using TestNG in Selenium Web Driver 初始化Web驱动程序的最佳方法 - Best Way to Initialize Web Driver NG和JUnit框架之间的区别? 使用Selenium Web驱动程序最适合测试哪一个 - Difference between NG and JUnit framework?? which one is best for testing by using Selenium Web-driver 使用Selenium和Java重置TestNG中浏览器状态的最佳方法 - Best Way to Reset Browser State in TestNG with Selenium and Java 有没有更好的方法从使用selenium web驱动程序的查找中选择选项 - Is there any better way to select option from lookup using selenium web driver 带有 TestNG 脚本的 Selenium 不起作用? - Selenium with TestNG Script is not working? 在使用Selenium Web驱动程序执行脚本之前,如何等待屏幕调整大小? - How can I wait for screen to be resized before executing script using Selenium web driver? 使用Selenium Web Driver无法在IE中打开任何网页 - not able to open any web page in IE by using Selenium Web Driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM