i have started with selenium few weeks back. i have designed my test this way
- using @BeforeClass i am creating a object and calling a method of class which is opening the browser and performing a login operation.
- i have another method which has the selenium code for the test operation i want to perform, in my case boundary value analysis
- 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")
}
}