29
Хороший тест - простой тест Андрей Солнцев

Good test = simple test (with selenide)

Embed Size (px)

Citation preview

Page 1: Good test = simple test (with selenide)

Хороший тест -

простой тест

Андрей Солнцев

Page 2: Good test = simple test (with selenide)

Selenide:

Нафига?

Page 3: Good test = simple test (with selenide)

Don’t put logic in tests

@Test public void shouldNavigateToPhotosPage() { String baseUrl = "http://plus.google.com/"; Navigator nav = new Navigator(baseUrl); nav.goToPhotosPage();

assertEquals(baseUrl + "/u/0/photos", nav.getCurrentUrl());}

http://googletesting.blogspot.com/2014/07/testing-on-toilet-dont-put-logic-in.html

Page 4: Good test = simple test (with selenide)

Don’t put logic in tests

@Test public void shouldNavigateToPhotosPage() { Navigator nav = new Navigator("http://plus.google.com/"); nav.goToPhotosPage();

assertEquals("http://plus.google.com//u/0/photos", nav.getCurrentUrl());}

Упс!

Page 5: Good test = simple test (with selenide)

Код

Общий алгоритм Частные случаи

Тест

C = SQRT(A*A + B*B)

assert hyph(3,4) == 5assert hyph(5,12) == 13assert hyph(1,1) == 1.41assert hyph(0,0) == 0assert hyph(-1,3) -> error

Page 6: Good test = simple test (with selenide)

ТестыКодсложный простые

копипастнельзя

копипастможно

Page 7: Good test = simple test (with selenide)

Тесты - максимально простые!

● условия● переменные● вычисления● циклы

привносят в тесты ошибки!

А тем более:● Page Object● Factory● Builder● “карточки”● и т.д.

Page 8: Good test = simple test (with selenide)

Усложнения в тесты

Стоит вносить осознанно● только по необходимости● понимая риски

Page 9: Good test = simple test (with selenide)

Итак,

чем же хорош Selenide?

Page 10: Good test = simple test (with selenide)

Selenide

● позволяет начать очень просто● и усложнять при необходимости

● при написании● при отладке

экономит массу времени

- синтаксис + API- умное ожидание

(20%)(80%)

Page 11: Good test = simple test (with selenide)

Пример: Google search

Page 12: Good test = simple test (with selenide)

Google search - Page Object

Page 13: Good test = simple test (with selenide)

Selenide

новинки

Page 14: Good test = simple test (with selenide)

1. Автоматические скриншоты

Page 15: Good test = simple test (with selenide)

На Jenkins - публичный URL:

build.gradle

Page 16: Good test = simple test (with selenide)

2. Методы $.hover(), $.dragAndDrop()

Page 17: Good test = simple test (with selenide)

3. Поиск родителей

● $.parent()● $.closest(“table”)● $.closest(“.modal”)

Page 18: Good test = simple test (with selenide)

4. $.uploadFile(File file)

Page 19: Good test = simple test (with selenide)

4. $.uploadFile(File … files)

Page 20: Good test = simple test (with selenide)

5. sizzle selectors

Page 21: Good test = simple test (with selenide)

6. zoom in/out

Page 22: Good test = simple test (with selenide)

7. Selenide profilerReport for userCanReplyToIncomingMessages(ui.BankMessagesSpec)

+----------------------+---------------------------------------------+--------+----------+

|Element |Subject |Status |ms. |

+----------------------+---------------------------------------------+--------+----------+

|open |http://localhost:2070/ |PASSED |4669 |

|open |http://localhost:2070/fakeLogin?username=bob |PASSED |1324 |

|By.linkText: Quicky |click() |PASSED |793 |

|#btn-message-reply |click() |PASSED |1002 |

|By.name: message.text |should be(focused) |PASSED |57 |

|By.name: message.text |should have(text 'long thread') |PASSED |47 |

|By.name: message.text |set value(Hello world!) |PASSED |69 |

|#send-button |click() |PASSED |1051 |

|.alert-success |should be(visible) |PASSED |71 |

+--------------------+-----------------------------------------------+--------+----------+

Page 23: Good test = simple test (with selenide)

8. fast set value

mvn -Dselenide.fastSetValue=true

@Before public void setUp() { Configuration.fastSetValue = true;}

или

Page 24: Good test = simple test (with selenide)

8. fast set value

И тогда $.setValue() использует JavaScript

● $.setValue(“john”) - быстро● $.sendKeys(“john”) - для autocompletion

который гораздо быстрее!

Ты сам можешь выбирать:

Page 25: Good test = simple test (with selenide)

Благодарности

● Alexandr GavrilenkoImproved mechanism of closing webdrivers

● Sergey Shimkiv Added method getWebDriverLogs()

Page 26: Good test = simple test (with selenide)

Благодарности

● Vladimir Denisov @proton72Added support for BrowserMob proxy

● kumarunster Possibility to log important Selenide Actions

Page 27: Good test = simple test (with selenide)

Статистика скачиваний

Page 28: Good test = simple test (with selenide)

Уникальных IP

Page 29: Good test = simple test (with selenide)

Андрей Солнцев@asolntsev

ru.selenide.org

Спасибо!