0

i have started with selenium few weeks back. i have designed my test this way

  1. using @BeforeClass i am creating a object and calling a method of class which is opening the browser and performing a login operation.
  2. i have another method which has the selenium code for the test operation i want to perform, in my case boundary value analysis
  3. now i have created a @Test method which calls this previous method and passes values to it required for the test

The problem i am facing is 1. the browser is launched and the loging operation takes pace, after this the browser tries to open the the home page again. 2. I wanted to know if this is correct way to write selenium tests scripts

also if i remove the step 1 and include login method in step 2 my test runs fine I am using selenium-rc and STS on groovy on grails

Code in one class

void candidatelogin() {
        selenium.open("/jeepnee/")
        selenium.click("link=Login")
        selenium.type("id=username", "csv_candidate4@trashmail.net")
        selenium.type("id=j_password", "kanishka1")
        selenium.click("id=submit")
        selenium.waitForPageToLoad("60000")
    }

the above part i am calling from the code bellow

class CandidateEditProfileInfoFunctionalTests extends GroovyTestCase{

public String addressone="nejshdgfbvxczaqwer1y2io3lkjh7dg*lakiqwerjshag"
    @BeforeClass
    static void setUp() {
        GeneralTests candidate= new GeneralTests()
        candidate.candidatelogin()
    }


void EditProfileInfoFail(String streeta, String streetb, String city, String state, String zip, String mobilecountry, String mobilearea, String mobilephone, String landlinecountry, String landlinearea, String landlinenumber) {
        selenium.waitForPageToLoad("60000")
        selenium.click("link=My Profile")
        selenium.waitForPageToLoad("80000")
        selenium.click("id=editProfile")
        selenium.waitForPageToLoad("80000")
        selenium.type("id=street1", streeta)
        selenium.type("id=street2", streetb)
        selenium.type("id=city", city)
        selenium.type("id=state", state)
        selenium.type("id=zip", zip)
        selenium.select("id=country", "label=Philippines")
        selenium.type("id=mobileCountryCode", mobilecountry)
        selenium.type("id=mobileAreaCode", mobilearea)
        selenium.type("id=mobilePhoneNumber", mobilephone)
        selenium.type("id=landlineCountryCode", landlinecountry)
        selenium.type("id=landlineAreaCode", landlinearea)
        selenium.type("id=landlinePhoneNumber", landlinenumber)
        selenium.click("id=submit")
        selenium.waitForPageToLoad("80000")
        assertTrue(selenium.isTextPresent("Please complete the required fields"))
        assertEquals("Candidate Creation - Step 2", selenium.getTitle())
    }
    @Test
    void homeCountryOnFailureShowsErrorMessage(){
        EditProfileInfoFail(addressone, "aaa", "bangalote", "karnataka", "1234", "11", "222", "12345", "11", "22", "5432")

    }
}
  • Your description seems to be the right way to do it. Note that you don't need to call the methods annotated `@BeforeClass` and `@Test` anywhere. If you don't, please post some code so we can see your actual implementation. – Petr Janeček Apr 30 '12 at 12:45
  • i have posted some code. please have a look if you can – Kanishka Choudhury Apr 30 '12 at 13:04

1 Answers1

1

Is any of your logic duplicated in your @BeforeClass method? That method is run one time to setup any dependencies all of your test methods will need. It sounds like the logic in this method is somewhat duplicated in Step 2. It seems that the code in step 2 to open the home page could be removed, as it has taken place inside of your @BeforeClass method. If your subsequent tests need to go back to the HomePage it would be better to change to the @Before annotation, which will then run that code prior to every test run.

Scott
  • 9,458
  • 7
  • 54
  • 81
  • thanks scot. my code dose not have duplicates in beforeclass method. also in my second step i am not performing any open operation, mostly click and type. i have observed that the step 1 runs more then once. as the error i am getting at the end of test is related to the method i am calling in BeforeClass – Kanishka Choudhury Apr 30 '12 at 12:51
  • Could you attempt to rename your method from setUp to any other method? It shouldn't be running twice, but it is the default method name for any method which is to be run prior to a test in jUnit. – Scott Apr 30 '12 at 13:17