Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

QA Fes 2016. Александр Хотемской. Обзор ProtractorJS как фреймворка для браузерной автоматизации


Published on

Я хотел бы пролить свет на такой замечательный фреймворк как ProtractorJS, разработанный в недрах Google для автоматизации тестирования AngularJS 1.x/2.x, но он подходит и для не-Angular приложений. Я расскажу основные преимущества, особенности. Примеры кода и подходов на TypeScript 2.0, на котором сейчас написан ProtractorJS.

Published in: Education
  • Be the first to comment

QA Fes 2016. Александр Хотемской. Обзор ProtractorJS как фреймворка для браузерной автоматизации

  1. 1. Selenium WebDriverJS based framework for automated testing of Angular 1.x/2.x applications OLEKSANDR KHOTEMSKYI
  2. 2.  Julie Ralph(Google) is one of the main contributors, made first commits in January 2013  Created as an answer to question: ”How to make end to end tests for AngularJS applications easier?”  Now ProtractorJS reached version 4.x, with over 1300 commits, 5700 GitHub stars, 200 contributors
  3. 3.  JS is one of the most popular languages today, and TypeScript is as primary in Angular 2.0 JAVA C# JavaScript PHP PythonC++ Ruby
  4. 4.  Easier than Java  Thousands of libraries already exist for JS/NodeJS. Friendly community, tons of open source code. Package manager already included in NodeJS  Much easier common code like JSON parsing, sending HTTP requests, and others  Duck-typing, monkey-patching  Tools are smaller, and project start is faster  Newest versions of TypeScript or ECMAScript 6 makes code much easier to write and understand  Same language for front-end, back-end and tests means that same code execution environment
  5. 5.  Developed by Microsoft team  Superset of JavaScript (includes JavaScript)  Compiles to JavaScript (ECMAScript 3, 5 or 6)  Optional types! This allows to have autocomplete in IDE  Easier refactoring of code  Has features that not yet in JavaScript specification (@Annotations, async/await)  Compilation errors, instead of runtime errors in JavaScript
  6. 6. ProtractorJS Java Selenium WebDriver High-level framework Low-level automation library (not framework) Uses script languages: TypeScript or JavaScript or both same time Uses Java JasimineJS (test runner and assertions), SauceLabs/BrowserStack integration, basic reporting, interactive debugger, command line parameters, configuration files  Node Package Manager shows ~628 results for ‘protractor’ Maven shows ~422 results for ‘selenium webdriver’ Asynchronous, uses own control-flow, and Promises objects Synchronous, traditional approach Ability to run tests in parallel Parallel running should be done with additional libraries/frameworks PageObjects are just objects with attributes and functions PageObjects require @FindBy annotations and PageObjectFactory usage. Plugins. Extra element locators. Mobile browsers support (with Appium). Mobile browsers support.
  7. 7. Test Runner (JasmineJS, Cucumber …) ProtractorJS Selenium JavaScript official bindings NodeJS environment Test Runner extensions Selenium Standalone Server (JAVA) Other JS modules HTTP JSON ChromeDriver GeckoDriver EdgeDriver SafariDriver Other drivers
  8. 8. • Runs on NodeJS 4.x, 5.x, 6.x • Can be used with different Test Runners (JasmineJS, CucumberJS, Mocha, others) • Can connect to browser using WebDriver server or directly (Chrome and Firefox only) • Supports all browsers that WebDriver does: Chrome, Firefox, Edge, Safari, Opera, PhantomJS and mobile • Angular 1.x and Angular 2.x ready!
  9. 9. One of the key features of ProtractorJS that it is uses same JSON WebDriver Wire protocol as other language bindings. This code will be executed as 3 separate JSON WebDriver Wire Protocol commands: Synchronizing with AngularJS application Locating element on the page Sending ‘click’ action for element
  10. 10. • Protractor uses ‘Wrapper’ pattern to add own features to standard WebDriver, WebElement, Locators objects Browser(WebDriver instance) + Inherited from WebDriver • getProcessedConfig • forkNewDriverInstance • restart • useAllAngular2AppRoots • waitForAngular • findElement • findElements • isElementPresent • addMockModule • clearMockModules • removeMockModule • getRegisteredMockModules • get • refresh • navigate • setLocation • getLocationAbsUrl • debugger • enterRepl • pause • wrapDriver actions touchActions executeScript executeAsyncScri pt call wait sleep getPageSource close getCurrentUrl getTitle takeScreenshot switchTo
  11. 11. ElementFinder + Inherited from WebElement• then • clone • locator • getWebElement • all • element • $$ • $ • isPresent • isElementPresent • evaluate • allowAnimations • equals • getDriver • getId • getRawId • serialize • findElement • click • sendKeys • getTagName • getCssValue • getAttribute • getText • getSize • getLocation • isEnabled • isSelected • submit • clear • isDisplayed • takeScreenshot
  12. 12. Protractor Locators + Inherited from WebDriver Locators• addLocator • binding • exactBinding • model • buttonText • partialButtonText • repeater • exactRepeater • cssContainingText • options • deepCss • className • css • id • linkText • js • name • partialLinkText • tagName • xpath
  13. 13.  JavaScript is single threaded (mostly)  To have possibility to do multiple tasks at once – JavaScript run them all in single thread, and quickly switch between them  Async tasks are running in isolation. To make execution step by step – callbacks are used  Callbacks are just functions, that will be called when async function is finished. It is like – “call this when you are done”. You can pass any arguments to them
  14. 14.  Pattern to avoid callback hell, extension of callbacks  Almost every function from API returns special object – Promise  Promise is a object, that will be resolved to a value (any), or rejected if value can’t be returned
  15. 15.  Do not try to write in synchronous manner! You should think differently when writing async code  When you asserting results – promises automatically resolved. Do not worry to resolve promise before assertion  To wait something on the page – use browser.wait() or browser.sleep()  ES7 features are on their way! async/await will make our life much easier  Be brave and good luck
  16. 16. Example of simple test case JAVA + Pure Selenium JAVA + JUNIT TypeScript + ProtractorJS + JasmineJS
  17. 17. Example of simple pageObject pattern usage JAVA + Selenium PageObjectFactory (@FindBy) TypeScript + ProtractorJS
  18. 18. And useful links:  Protractor site:  Promises, WebDriver Control Flow documentation:  Gitter chat:  StackOverflow(top questions):  GitHub:  TypeScript documentation:  ES6 features:  Protractor TypeScript example: OLEKSANDR KHOTEMSKYI 2016