Для управления тестами будем использовать TestNG.
1) Создайте новый пакет “src/test/java” –> New –> Package –> nи назовите его “com.selenium.test”
2) Создайте новый класс в пакете “com.selenium.test” –> TestNG –> Create TestNG Class.
3) Назовите класс “autoTestFacebook” и выберите опции “BeforeTest”, “AfterTest”.
4) Скопируйте следующий код:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
package com.selenium.test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterTest; import com.selenium.pageObject.LoginPage; import com.selenium.userAction.PostStatus; import com.selenium.userAction.SignIn; public class autoTestFacebook { /** * Create WebDriver as static variable */ private static WebDriver driver; /** * Setup some variable to run your script test */ @BeforeTest public void beforeTest() { driver = new FirefoxDriver(); } /** * your test script call action class here */ @Test public void f() { LoginPage.loadPage(driver); SignIn.Execute(driver, "gaumun", "63hamlong"); PostStatus.Execute(driver, "this is my status posted by my automation test"); } /** * after run your script test , use this code to close your browser */ @AfterTest public void afterTest() { driver.quit(); } } |
5) Запустите класс: Run As –> TestNG Test.
6) После завершения теста просмотрите созданный репорт в “test-output”:
Основа полноценного Selenium Framework создана. Дальше рассмотрим дополнительные надстройки.