Download - Как и зачем мы тестируем UI
vlialkin
Presented by Вячеслав Лялькин
• Что
• Зачем
• Автотесты
• WebDriver HOWTO
• Контекст использования
Agenda
Что тестировать?
• Web-приложение
• jQuery
• Backbone.js
• Underscore.js
• jqGrid/DataTables
• Bootstrap 2
• Freemarker
Что тестировать?
Зачем тестировать?
• Спокойствие заказчика
• Continuous Integration/Delivery
• Нет тестировщиков
Selenium
Автотесты
• Что это такое?
• Test Automation Engineer
• Проблемы автоматизированных тестов
Selenium
Selenium IDE
Selenium Remote Control
Selenium Grid
Selenium WebDriver
Selenium WebDriver
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.35.0</version>
<scope>test</scope>
</dependency>
WebDriver driver = new FirefoxDriver();
// FirefoxDriver, ChromeDriver, SafariDriver,
// InternetExplorerDriver, AndroidDriver, IPhoneDriver
Selenium WebDriver
• Google Chrome 12+
• Internet Explorer 6, 7, 8, 9
• Firefox 3.6+
• Safari 5+
• Opera 8+
• Android 2.3+ (устройства и эмуляторы)
• iOS 3.2+ (устройства и эмуляторы)
Как искать элементы?
• IDBy.id("items_table_id");
• Class NameBy.className("popover");
• Tag NameBy.tagName(rowId == 0 ? "th" : "td");
• NameBy.name("Viachaslau Lialkin");
Как искать элементы?
• Link text/partial link textBy.linkTest("orders-list");
• CSSBy.cssSelector("tr.checked");
• XpathBy.xpath("//span[contains(@class,'item')"
+ "and text()='Test product']");
• JavaScriptWebElement element =
(WebElement) ((JavascriptExecutor) driver)
.executeScript("return $('#orders tr.checked')[0]");
XPath
• Что это такое?
• Зачем?
• Как?
• Примеры xpath-выражений//span[@class='error']
//div[@class='modal-body']//*[text()='I am button']
//table[@id='items_id']/tbody/tr[1]/td[4]/a[text()='I am cell']
//div[@id='faceted_section']//span
[contains(@class,'accordion') and text()='I am span']
Какие возможности?
• Переключение между окнами
• Всплывающие диалоги
• Полноценная навигация
• Работа с cookies
• Замена User Agent (для FirefoxDriver)
• Drag And Drop
Действия с элементами
getText
getAttribute
getCssValue
getTagName
findElement
isDisplayed
isEnabled
isSelected
clear
click
sendKeys
submit
Класс org.openqa.selenium.WebElement
Что может пойти не так?
NoSuchElementException
NoAlertPresentException
ElementNotVisibleException
TimeoutException
Класс org.openqa.selenium.WebDriverException
Контекст использования
• Fast build
• Automated builds
• Automated deployment
• Self-testing builds
• Clone of the production environment
Continuous Integration
• Continuous Delivery
• Pipeline
• Smoke/Full tests
• Dark launch
• QA1, QA2, PROD1..PROD9
Continuous Delivery
CD pipeline