私は数週間前にセレンを使い始めました。私はこのようにテストを設計しました
- @BeforeClass を使用して、オブジェクトを作成し、ブラウザを開いてログイン操作を実行するクラスのメソッドを呼び出しています。
- 実行したいテスト操作用のセレンコードを持つ別のメソッドがあります。私の場合は境界値分析です
- これで、この前のメソッドを呼び出してテストに必要な値を渡す @Test メソッドを作成しました
私が直面している問題は、1.ブラウザが起動され、ログ操作がペースを上げて、その後ブラウザがホームページを再度開こうとすることです。2. これがセレン テスト スクリプトの正しい書き方かどうか知りたかった
また、ステップ 1 を削除してステップ 2 にログイン メソッドを含めると、テストは正常に実行されます。grails の groovy で selenium-rc と STS を使用しています。
1 つのクラスのコード
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")
}
上記の部分は、以下のコードから呼び出しています
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")
}
}