0

We build model for each page with selenium page objects pattern. But for implementing one business feature, it will involve couple of pages. For example, creating one user, it involves AgreementPage and CreateUserPage like below

agreementPage = AgreementPage()
creatUserPage = agreementPae.accept()
createUserPage.typeEmail("your email address")
createUserPage.submit()

In our tests, many test cases require to create one user for preconditions. To reuse these code, we made one new Service tier. We move code into UserService.CreateUser(). Then our test scripts become

def test_create_user():
    userService.CreateUser("email address")

    #do assertion

def test_edit_user():
    authenticationService.login("user name", "password")
    userService.CreateUser("email addrss")

    #do editing created user

def test_delete_user():
    authenticationService.login("user name", "password")
    userService.CreateUser("email addrss")

    #do deleting created user

Because most features involve two pages or more, so page objects go into service tier. And in test scripts tier, it seems that we are testing services.But we do think service name is not friendly and not like talking with domain language.

I assume this is very common approach to do automation test, right? How do you naming service tier or how do you deal with resuing page objects?

Cypine
  • 310
  • 3
  • 13
  • After reading Gojko Adzic's posts: http://gojko.net/2010/04/13/how-to-implement-ui-testing-without-shooting-yourself-in-the-foot-2/ and http://gojko.net/2009/10/06/putting-selenium-in-the-right-place/, I agree that Activity is better naming than services. It also proves that this is one general code hierarchy for automation testing: 1. test scripts 2. activities 3. page objects --- Test scripts do testing for funcionalities and also illustrate requirements. Activites descript system behaviors. Page objects encapsulate operations on pages. – Cypine Oct 20 '13 at 13:14

1 Answers1

0

We are also using page object model as the frame work and it's awesome. One way of resuing the page is creating a method in the page which returns decorated page every time. Call the method before calling/using any other object in your page. This should solve the problem. Let me give you simple example of login page.

 public class LoginPage{
 public LoginPage getLoginPage(){
 PageObject.initElements(yourDriverObject, LoginPage.class);
}


public void doLogin(){
 //Code to login 

}

Test class

public class testLogin{

 new LoginPage.getLoginPage().doLogin();

}
Vinay
  • 648
  • 4
  • 12
  • I undersand action chain, but it doesn't help to my problem. I don't want to see a lot of duplications of "LoginPage.getLoginPage().doLogin()" where we need login funcionality.In fact, there are duplicated code block with page object, more than one code line. – Cypine Jul 22 '13 at 02:49
  • I underdstand. But since we have methods do the work instead of writing the logic in the test case, I guess duplication to an extend can be reduced. Can somebody also help???? – Vinay Jul 22 '13 at 04:16