1

I'm currently working at my job to perform GUI testing of our web page using Selenium 2 via Java in Eclipse. I've been trying to program my tests in such a way that I maximize the amount of code I can reuse and as a consequence I now have a lot of helper methods that function almost like a framework. This has lead to my test class becoming fairly bloated with only one method used as the actual test and the rest being the implementation of the test.

Currently I just run the testing right from Eclipse with all my methods being static.

From what I understand there are a couple different ways I could try to separate things out:

  • One way would be to put all the methods into a class I use as a framework and extend it when writing an actual test, but I don't know if having a framework in a framework (Selenium) makes sense.

  • Another way would possibly be making my helper methods into an object where I can have one of these objects for each test. I don't know if this is good practice though, or if it will cause problems down the road. It would also mean I'd have to type more to do the same amount of testing.

My main questions are:

  • What's the best way to split up my testing class into test classes and an implementation class?

  • Is what I'm doing outside the intended usage of Selenium?

scott_lotus
  • 3,171
  • 22
  • 51
  • 69
Seth A.
  • 25
  • 4

1 Answers1

1

The best practice is that create a page object model for each web UI.That will help you to access the web element easily.selenium provide that feature and you also have to do some R&D things.

 Home_Page.lnk_MyAccount(driver).click();

 LogIn_Page.txtbx_UserName(driver).sendKeys("testuser_1");

 LogIn_Page.txtbx_Password(driver).sendKeys("Test@123");

And put all selenium related actions into a one class.like Action.click(),Action.search(), or what ever your common set of actions.

Next thing is that reusable code implement via a function.let say login(usernName,Password) then handle the login code inside that.and you can reuse thease codes in your other places.always try to modularize your implementation.

gihan-maduranga
  • 4,381
  • 5
  • 41
  • 74