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.

Easy automation.py

273 views

Published on

This talk was given at "Easy Automation in Python" meetup (https://www.meetup.com/Test-Fanatic-MeetUp/events/236481850/).

The talk is about some easy approaches in building web ui automation in python.

As an "easy tool" the selene library is uses.

src code for the talk: https://github.com/yashaka/talks/tree/master/easy-automation-py

Published in: Technology
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Easy automation.py

  1. 1. @yashaka 01.2017 easy_automation.py
  2. 2. Plan Intro Live Coding Session Easy Automation Tools Retrospective Q&A
  3. 3. Why Automation?
  4. 4. Testing = Assessing Quality
  5. 5. Effective Testing => Assessing Quality 0 50 100 150 200
  6. 6. Automation = Automating manual routine work
  7. 7. Effective Testing *= Testing with automated routine work
  8. 8. Automation!
  9. 9. But, it’s hard, no?
  10. 10. no:p
  11. 11. Coding Session https://github.com/yashaka/talks/tree/master/easy-automation-py
  12. 12. Summary
  13. 13. Coverage Styles End to End style + more coverage in less time with less efforts during implementation + integration coverage Unit/One-feature-per-test style + in case of bugs, gives more complete report + easier to identify reason from the report => + less time and efforts in support
  14. 14. How many => => Only: + functional high priority use cases
  15. 15. Avoid => => No - style checks - low priority test cases (that user will not do on regular basis) - additional requirements, like “different kind of names for entities” <=
  16. 16. Implementing Automation • Project in progress, no Automation? 1. start with End To End style smoke integration tests 2. review and test plan 3. cover with “One feature”/“Unit” style independent tests
  17. 17. Implementing Automation • Project just started and Auto-POC is approved OR ready features are automated? 1. Test plan new features 2. Cover with “One feature”/“Unit” style independent tests 3. Add End to End integration smoke tests
  18. 18. Wasn’t it Easy? :)
  19. 19. Of course, “Automation is Easy” is a semi-truth but the devil is not so black as he is painted;)
  20. 20. How to start? • Choose language • Learn language (interactive tutorials, koans, exercism.io/checkio.org, learnxinyminutes.com, books, etc.) • Choose Easy Tools • Find a mentor (friend, dev on your project, chat, etc…) • Go :)
  21. 21. Choose language? • Have project? • choose language of project’s developers • Have no project but want to find work fast? • choose one of the most popular language • Have no project but want to code in your style, and it does not matter how long will you seek for the job? • choose language that fits you
  22. 22. Learn language? Google :p
  23. 23. interactive tutorials + koans + exercism.io + docs.seleniumhq.org + google.com = “You can do this in any language.”
  24. 24. Easy Tools? • Just a few examples… • Python: Selene • C#: NSelene • Java: Selenide • Ruby: Capybara
  25. 25. tasks = ss("#todo-list>li")
 
 ... def toggle(task_text):
 
 tasks.element_by(have.exact_text(task_text)).element(“.toggle”).click()
 
 
 def should_be(*task_texts):
 
 tasks.filtered_by(be.visible).should(have.exact_texts(*task_texts))
  26. 26. public class Tasks {
 
 public static ElementsCollection tasks = $$("#todo-list>li");
 
 ... 
 public static void toggle(String taskText) { 
 tasks.findBy(exactText(taskText)).find(".toggle").click();
 }
 
 public static void shouldBe(String ... taskTexts) { 
 tasks.filterBy(visible).shouldHave(exactTexts(taskTexts));
 }
 }
  27. 27. public static class Tasks
 {
 public static SCollection List = SS("#todo-list>li"); 
 
 ...
 
 public static void Toggle (string taskText)
 {
 List.FindBy(Have.ExactText(taskText)).Find(".toggle").Click();
 }
 
 public static void ShouldBe(params string [] names) {
 List.FilterBy(Be.Visible).Should(Have.Texts(names));
 }
 }
  28. 28. module Tasks
 extend Capybara ::DSL
 
 def self.tasks
 all "#todo-list>li"
 end 
 ...
 def self.toggle task_text 
 (tasks.findBy {|task| task.text == task_text}).find(".toggle").click
 end
 
 def self.should_be *task_texts 
 tasks.texts.should == task_texts
 end
 end
  29. 29. = ?Easy Tool
  30. 30. = ?Selene
  31. 31. = … web automation tool … Selene
  32. 32. = … web automation tool selenium wrapper Selene
  33. 33. = … web automation tool selenium wrapper Selene
  34. 34. = Effective web test automation tool Selene
  35. 35. = Effective web test automation tool being also selenium wrapper Selene
  36. 36. = Effective web test automation tool = ? Selene
  37. 37. = Effective web test automation tool = tool to automate web UI tests logic Selene
  38. 38. = Effective web test automation tool = tool to automate web UI tests logic not browser Selene
  39. 39. = Effective web test automation tool = tool to automate web UI tests logic not browser (it should be already automated;) Selene
  40. 40. = Effective web test automation tool = tool to automate web UI tests logic not browser Selene concise API … … … …
  41. 41. = Effective web test automation tool = tool to automate web UI tests logic not browser Selene concise API waiting search … … …
  42. 42. = Effective web test automation tool = tool to automate web UI tests logic not browser Selene concise API waiting search waiting asserts … …
  43. 43. = Effective web test automation tool = tool to automate web UI tests logic not browser concise API waiting search waiting asserts dynamic elements … Selene
  44. 44. = Effective web test automation tool = tool to automate web UI tests logic not browser Selene concise API waiting search waiting asserts dynamic elements informative errors
  45. 45. Selene = Effective web test automation tool = tool to automate web UI tests logic not browser concise API waiting search waiting asserts dynamic elements informative errors
  46. 46. “UI Tests Logic” Automation with Selene
  47. 47. class TestTodoMVC(object):
 def test_filter_active_tasks(self):
 
 # visit page 
 # add "a" # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic
  48. 48. 
 # visit page 
 # add "a" # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic
  49. 49. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 # add "a" # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic
  50. 50. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic
  51. 51. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Concise API
  52. 52. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Automatic Driver Management
  53. 53. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Concise API search element “short-cut”
  54. 54. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Concise API default conversion to “by css” locator
  55. 55. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Concise API with implicit clear()
  56. 56. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Concise API chainable methods
  57. 57. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Dynamic Elements search actually starts here
  58. 58. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() # add "b" # add "c"
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Waiting Search with implicit waiting for visibility
  59. 59. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() s("#new-todo").set("b").press_enter() s("#new-todo").set("c").press_enter()
 # tasks should be "a", "b", "c"
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic
  60. 60. UI Tests Logic Waiting Asserts aka “explicit waits” 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() s("#new-todo").set("b").press_enter() s("#new-todo").set("c").press_enter()
 ss("#todo-list li").should(have.exact_texts("a", "b", "c"))
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c"
  61. 61. UI Tests Logic handy conditions Waiting Asserts 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() s("#new-todo").set("b").press_enter() s("#new-todo").set("c").press_enter()
 ss("#todo-list li”).should(have.texts(“a", "b", "c"))
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c"
  62. 62. 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() s("#new-todo").set("b").press_enter() s("#new-todo").set("c").press_enter()
 ss("#todo-list li”).should(have.texts("a.", "b.", "c."))
 
 # toggle "b"
 
 # filter active
 # tasks should be "a", "c" UI Tests Logic Informative errors E TimeoutException: Message: E failed while waiting 4 seconds E to assert ExactTexts E for all_by('css selector', '#todo-list li') E E reason: ConditionMismatchException: condition did not match E expected: ('a.', 'b.', 'c.') E actual: ['a', 'b', 'c'] E screenshot: /Users/ayia/.selene/screenshots/1484695102265/screen_1484695102266.png
  63. 63. UI Tests Logic instead of bulky xpath locators inner element search Concise API & Waiting Search 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() s("#new-todo").set("b").press_enter() s("#new-todo").set("c").press_enter()
 ss("#todo-list li”).should(have.texts("a", "b", "c"))
 
 ss("#todo-list li”).element_by(have.text(“b")).element(".toggle").click()
 
 # filter active
 # tasks should be "a", "c" laconic inner collection search by text
  64. 64. UI Tests Logic custom locators 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() s("#new-todo").set("b").press_enter() s("#new-todo").set("c").press_enter()
 ss("#todo-list li”).should(have.texts(“a", "b", "c"))
 
 ss("#todo-list li”).element_by(have.text(“b")).element(".toggle").click()
 
 s(by.link_text("Active")).click()
 # tasks should be "a", "c"
  65. 65. UI Tests Logic Concise API & Waiting Asserts filtering collection 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() s("#new-todo").set("b").press_enter() s("#new-todo").set("c").press_enter()
 ss("#todo-list li”).should(have.texts(“a", "b", "c"))
 
 ss("#todo-list li").element_by(have.text("b")).element(".toggle").click()
 
 s(by.link_text("Active")).click()
 tasks.filtered_by(be.visible).should(have.texts(“a”, "c"))
  66. 66. UI Tests Logic 
 visit("https: //todomvc4tasj.herokuapp.com/") 
 s("#new-todo").set("a").press_enter() s("#new-todo").set("b").press_enter() s("#new-todo").set("c").press_enter()
 ss("#todo-list li").should_have(texts("a", "b", "c"))
 
 ss("#todo-list li").element_by(have.text("b")).element(".toggle").click()
 
 s(by.link_text("Active")).click()
 tasks.filtered_by(be.visible).should(have.texts("a", "c"))
  67. 67. Page steps for even more readable code?
  68. 68. #tasks.py def visit():
 tools.visit("https: //todomvc4tasj.herokuapp.com/")
 def add(*task_texts):
 for text in task_texts: s("#new-todo").set(text).press_enter()
 
 def filter_active():
 s(by.link_text("Active")).click()
 
 def filter_completed():
 s(by.link_text("Completed")).click()
  69. 69. #tasks.py tasks = ss("#todo-list>li")
 
 ... def toggle(task_text):
 tasks.element_by(have.text(task_text)).element(".toggle").click()
 
 
 def should_be(*task_texts):
 tasks.filtered_by(be.visible).should(have.texts(*task_texts))
  70. 70. tasks = ss("#todo-list>li")
 
 ... Dynamic Elements possible because search does not start here in fact, ss creates “lazy elements proxy” aka “elements lazy finder”;)
  71. 71. class TestTodoMVC(object):
 
 def test_filter_tasks(self):
 
 tasks.visit()
 
 tasks.add("a", "b", "c")
 tasks.should_be("a", "b", "c")
 
 tasks.toggle("b")
 
 tasks.filter_active ()
 tasks.should_be("a", "c")
 
 tasks.filter_completed ()
 tasks.should_be("b")
  72. 72. Customisation
  73. 73. config.browser_name = "chrome" ... or config.browser_name = Browser.CHROME ... will use “firefox” by default
  74. 74. config.app_host = "http: //mydomain.com" ... visit("/subpage")
  75. 75. s(“#new-todo”).should(be.enabled) Default Timeouts Behaviour will wait until 4 seconds
  76. 76. s(“#new-todo”).should(be.enabled, timeout=10) Custom or config.timeout = 10 ... s(“#new-todo”).should(be.enabled)
  77. 77. No Tool for your language?
  78. 78. No Tool for your language? • Have project? • ask project’s developers to write it for you • Have no project and lack of knowledge? • switch to language that has easy tools :) • Brave? • implement it by your own ;)
  79. 79. Remember… • Automation is NOT a separate Role • Automation IS A TOOL for Test Engineer to do his work effectively
  80. 80. Q&A
  81. 81. Thank you! @yashaka 01.2017 github.com/automician automician.com seleniumcourses.com yashaka @

×