Вторник, 17.06.2025, 06:45
Мой сайт
Приветствую Вас Гость | RSS
Меню сайта
Наш опрос
Оцените мой сайт
Всего ответов: 2
Статистика

Онлайн всего: 1
Гостей: 1
Пользователей: 0
Главная » 2017 » Сентябрь » 8 » Первый тест-кейс с использованием TestNG
12:41
Первый тест-кейс с использованием TestNG

http://autoqa.org/testng-framework/pervyj-test-kejs-s-ispolzovaniem-testng.html

Проделайте следующие шаги:

1) В контекстном меню созданного пакета выберите TestNG и выберите TestNG Class”.

Install-TestNG-8

 

2) Назовите класс “TestNG”. Выберите следующие аннотации – “@BeforeMethod“, “@AfterMethod” и нажмите Finish.

TestNG-FTC-2

 

3) Новосозданный класс должен выглядить следующим образом.

TestNG-FTC-3

Время написать первый тест-кейс с помощью TestNG.

 

5) Воспользуемся тест-кейсом и разделим его на три части.

@BeforeMethod : Запуск Firefox и переход по URL

@Test : Ввод имени пользователя и пароля, отображение информации в консоле и Log out

@AfterMethod : Закрытие браузера

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

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

package automationFramework;

 

import java.util.concurrent.TimeUnit;

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.AfterMethod;

 

public class TestNG {

public WebDriver driver;

@Test

public void main() {

// Find the element that's ID attribute is 'user_login' (Username)

// Enter Username on the element found by above desc.

driver.findElement(By.id("user_login")).sendKeys("subscriber");

// Find the element that's ID attribute is 'user_pass' (Password)

// Enter Password on the element found by the above desc.

driver.findElement(By.id("user_pass")).sendKeys("2016subscriberpasssword2016ok");

// Now submit the form. WebDriver will find the form for us from the element

driver.findElement(By.id("wp-submit")).click();

if (driver.findElement(By.id("profile-page")).isDisplayed())

{

// Print a Log In message to the screen

System.out.println("Login successfully.");

}

}

@BeforeMethod

public void beforeMethod() {

// Create a new instance of the Firefox driver

driver = new FirefoxDriver();

//Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

//Launch the Wordpress Admin site

driver.get("http://autoqa.pp.ua/wp-admin");

}

@AfterMethod

public void afterMethod() {

// Close the driver

driver.quit();

}

}



6) Запустите тест-кейс с помощью команды Run As -> TestNG Test.

 

TestNG-FTC-5

Результаты запуска Testng тест-кейса

 

7) После завершения выполнения тест-кейса перейдите в окно результата запуска TestNg Result.

TestNG-FTC-6

Он отображает “passed : 1″. Это означает, что тест-кейс выполнилcя успешно и Passed.

Еще есть три вкладки: “All Tests”, “Failed Tests” и “Summary”. Нажмите “All Tests”.

TestNG-FTC-7

Здесь присутствует информация о том, какой метод запускался и время выполнения.

 

8) TestNG также генерирует HTML отчет. Чтобы его просмотреть, перейдите в директорию проекта и в папку test-output.

 

9) Откройте “emailable-report.html” в браузере.

TestNG-FTC-9

 

10) TestNG также создает “index.html”, размещенный в папке test-output. Этот репорт позволяет перейти по ссылкам Groups и Reporter Output.

TestNG-FTC-10

TestNG-FTC-11

Просмотров: 273 | Добавил: admin | Рейтинг: 0.0/0
Всего комментариев: 0
avatar
Вход на сайт
Поиск
Календарь
«  Сентябрь 2017  »
Пн Вт Ср Чт Пт Сб Вс
    123
45678910
11121314151617
18192021222324
252627282930
Архив записей
Друзья сайта
Copyright MyCorp © 2025uCoz