Let's talk testing with
SeleniumCreated by Anisha Narang | Red Hat Inc.
PyCon India 2013, Bangalore
Why Testing?
Test Automation
... is use of testing tool to:
To control the execution of tests
To compare the actual outcomes to expecte...
Selenium
Selenium automates web browsers
Can be controlled by many programming languages and
testing frameworks
Programmin...
Test Automation with
Selenium
Regression testing
Validate the application flow
Test suites
Report generation
How to start?
1. Install Selenium
pip install -U selenium
2. Record and Play with Selenium IDE
Selenium script looks like?
#!/usr/bin/env python
from selenium import webdriver
import unittest
Class Test:
def setUp(sel...
Building an
1. Understand the functionality
2. Make a manual test run
3. Decide which test cases to automate
4. Inspect th...
To automateWhat?
Some sample code snippets
Search
def test_search:
with open(“file.json”) as data_file:
data_text = json.load(data_file)
fo...
Checkbox selection
def test_checkbox:
checkbox = driver.find_element_by_id(“id_1”)
if checkbox:
self.assertTrue(checkbox.i...
Pagination
def test_pagination:
element=driver.find_element_by_class_name('pagination')
regexp= r"[A-Za-z0-9]+"
page_numbe...
Maintaining test scripts
Structure your test project
Decide the format for input test data
Keep the code DRY
Decide which ...
Test reports
How important is reporting?
Can we generate HTML reports?
How to generate reports for automated tests?
Genera...
Demo time
Best practices
Decide which test cases to automate
Create good quality test data
Design stable logic for test scripts
Crea...
END| anisha.narang27@gmail.com@anisha_narang
Let's talk testing with Selenium
Let's talk testing with Selenium
Upcoming SlideShare
Loading in...5
×

Let's talk testing with Selenium

467
-1

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
467
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Let's talk testing with Selenium

  1. 1. Let's talk testing with SeleniumCreated by Anisha Narang | Red Hat Inc. PyCon India 2013, Bangalore
  2. 2. Why Testing?
  3. 3. Test Automation ... is use of testing tool to: To control the execution of tests To compare the actual outcomes to expected outcomes To report the test status(PASS/FAIL)
  4. 4. Selenium Selenium automates web browsers Can be controlled by many programming languages and testing frameworks Programming language : python Testing framework : unittest
  5. 5. Test Automation with Selenium Regression testing Validate the application flow Test suites Report generation
  6. 6. How to start? 1. Install Selenium pip install -U selenium 2. Record and Play with Selenium IDE
  7. 7. Selenium script looks like? #!/usr/bin/env python from selenium import webdriver import unittest Class Test: def setUp(self): self.driver = webdriver.Firefox() self.driver.get("www.example.com") def test_case(self): #write your test case here def tearDown(self): self.driver.quit() if __name__ == "__main__": unittest.main()
  8. 8. Building an 1. Understand the functionality 2. Make a manual test run 3. Decide which test cases to automate 4. Inspect the UI elements accordingly 5. Set the expectations 6. Design a suitable logic for the test code 7. Start writing your test script
  9. 9. To automateWhat?
  10. 10. Some sample code snippets Search def test_search: with open(“file.json”) as data_file: data_text = json.load(data_file) for each in data_text: search_text = each["name"] driver.find_element_by_id("_id1").clear() driver.find_element_by_id("_id1").send_keys(search_text) driver.find_element_by_name("search_id").click() element = driver.find_elements_by_class_name('results_id') element_text = {z.text.lower() for z in element} self.assertIn(search_text.lower(), element_text, “Search result does n
  11. 11. Checkbox selection def test_checkbox: checkbox = driver.find_element_by_id(“id_1”) if checkbox: self.assertTrue(checkbox.is_selected(),"Incorrect filter selection” self.assertTrue(checkbox.is_enabled(),"Checkbox is disabled")
  12. 12. Pagination def test_pagination: element=driver.find_element_by_class_name('pagination') regexp= r"[A-Za-z0-9]+" page_numbers = re.findall(regexp,element.text) prev_element = driver.find_element_by_class_name('disabled') prev_element = prev_element.text self.assertEqual(prev_element, page_numbers[0], "The element 'Prev' is NOT page_1 = driver.find_element_by_class_name('active') page_1 = page_1.text self.assertEqual(page_1, page_numbers[1], "The element '1' is NOT active on next_element = driver.find_element_by_link_text("Next") #similarly verify the last and next element
  13. 13. Maintaining test scripts Structure your test project Decide the format for input test data Keep the code DRY Decide which test cases to cover in one test script depending on the flow of the application Use logging module to keep track of the events taking place during the test run
  14. 14. Test reports How important is reporting? Can we generate HTML reports? How to generate reports for automated tests? Generate reports using HTMLTestRunner.py
  15. 15. Demo time
  16. 16. Best practices Decide which test cases to automate Create good quality test data Design stable logic for test scripts Create automated tests that are resistant to changes in the UI Generate test reports
  17. 17. END| anisha.narang27@gmail.com@anisha_narang

×