3

I have general questions about Managing selenium web project, the example is below, my question is how to manage those test cases?(its only 3 for the example, the real number of test cases is more than 1000)

Did create class for sub tests is good, like class for login and all the tests that related to log in is under this class?

Did there is an Conventions for writing test cases and manage them?

Thanks you all.

I create class with tests like:
        @Test   //Test1
        public  void logInFaildTest() {
            GridTest gridTest = new GridTest();
            WebDriver webDriver = gridTest.getWebDriver();
            String url = gridTest.getUrl();
            LoginPage logIn = new LoginPage(webDriver, url);
            String userName = "user";
            String pass="pass";
            logIn.login(userName, pass);
            WebElement errorMsg = webDriver.findElement(By.className("dijitToasterContent"));
            String actual = errorMsg.getAttribute("innerHTML");
            String expected="Incorrect user name or password. Please try again.";
            assertEquals(expected, actual);
            webDriver.close();
        }

        @Test
        public void loginSucsecc()
        {
            GridTest gridTest = new GridTest();
            String url = gridTest.getUrl();
            WebDriver webDriver = gridTest.getWebDriver();
            LoginPage logIn = new LoginPage(webDriver, url);
            String userName = "user";
            String pass="pass";
            logIn.login(userName, pass);
            String actual = webDriver.getCurrentUrl();
            String expected= url+"#lastmile/";
    //      webDriver.close();
            webDriver.quit();
            assertEquals(expected, actual);
        }

        @Test
        public void accountLock()
        {
            GridTest gridTest = new GridTest();
            String url = gridTest.getUrl();
            WebDriver webDriver = gridTest.getWebDriver();
            LoginPage logIn = new LoginPage(webDriver, url);
            String userName = "user";
            String pass="wrong";
            for(int i=0;i<11;i++){
                logIn.login(userName, pass);
                logIn.clearFileduNamePass();
            }
            WebElement msg = webDriver.findElement(By.id("dijit__TemplatedMixin_0"));       //block message
            String actual  = msg.getAttribute("innerHTML");
            int splitIndex= actual.indexOf(".<");
            actual = actual.substring(0, splitIndex);

            String expected= "Your account has been locked";
            webDriver.quit();
            assertEquals(expected, actual);
        }
    }

1 Answers1

2

Yes what you've done is good only.So that all Login related operations can go into one class so if there is any change we can easily manage that

Object Maintaenance

You can go with Page Object Model(POM) as it is widely used approach and easily manageable one.This is for managing your Objects more like maintaining an Object Repository

As you can observe, all we are doing is finding elements and filling values for those elements.

This is a small script. Script maintenance looks easy. But with time test suite will grow. As you add more and more lines to your code, things become tough.

The chief problem with script maintenance is that if 10 different scripts are using the same page element, with any change in that element, you need to change all 10 scripts. This is time consuming and error prone.

A better approach to script maintenance is to create a separate class file which would find web elements , fill them or verify them. This class can be reused in all the scripts using that element. In future if there is change in the web element , we need to make change in just 1 class file and not 10 different scripts.

This approach is called Page Object Model(POM). It helps make code more readable, maintainable, and reusable.

Test Data Maintenance

The next you've to consider is the test data used to run the test cases with different set of data Test-Driven Approach

Same as POM You can create a factory class which will give you set of data whenever required so that when you want to change/modify the data you can simply go to the factory and change it .

For ex you create a class named LoginData which have functions like getValidCredentials getRandomCredentials to get your data. If your application requires random emailid for each run then you can simply modify the getValidCredentials part alone It will help you a lot when your application runs mainly on forms or user datas

Reusable Components

The third thing is the Re-usability of what you've created.You can reuse the validLogin for other scenario's as well

Madhan
  • 5,750
  • 4
  • 28
  • 61
  • WooW, thank you, this is really good answer. I have another question about Page Object Model(POM), i have dynamic web site we use dojotoolkit, So I do not really have static pages, only the content of the page changed, did you recommends to use POM in this such site? – Software Qustions Jun 21 '15 at 08:30
  • Still you can go for it but you've to modularise your POM so that you can reuse it without much redundancy You can refer [dojo selenium](http://stackoverflow.com/questions/5884189/testing-a-dojo-web-application-with-selenium) for more – Madhan Jun 21 '15 at 08:54