简体   繁体   中英

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 . 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 ??

2, Since login script is common , how can i reuse its script on each module ??

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. Now your framework can be one of the following types :

a. Module Based Testing Framework

b. Library Architecture Testing Framework

c. Data Driven Testing Framework

d. Keyword Driven Testing Framework

e. Hybrid Testing Framework

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. PageFactory using POM is one of the best practice in-terms of performance & least maintenance.

b. If your framework needs to read real-time data from excel sheets, Data Driven Testing Framework should be your approach.

c. If you are reusing a number of methods repeatedly for Assertions, Library Architecture Testing Framework should be your approach.

d. If you want to leverage the benefits of all kinds of associated frameworks then Hybrid Testing Framework should be your approach.

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.

  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. There is a lot of documentation available within stackoverflow.com, github.com & other external sites.

  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.

  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.

Hope this answers all of your questions.

You can google 'page factory' model as a methodology for your tests. 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).

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)

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). 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:

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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