The visual studio IDE can be used to do the python+selenium script writing. The best thing is, If you use unittest module, Test case is displayed on the test explorer. Which allows to run a test case using test explorer.
- First you need to create python project
Go to Files—>New—>Project
Select Python from Left panel and you can give suitable name for project and select Location
Let’s see how to create a test class using a unit test framework and organizing test cases. In this test case first moves to google search page, then verify “I’m Feeling Lucky” button available on the page. If button available, click on the button. After that verify the page title of the new page that navigate after click on “I’m Feeling Lucky” button.
Above script can be explained as follows.
- In the first part of the script, Import unit test module that provide a framework for organizing test cases. (The unit test module is in standard libraries. So no need to install anything new.) And also import selenium web driver module and other referencing classes.
- Next define the test class that inherit from unittest.TestCase
- After that, Inside this class create test cases to test functions we need to test.when we create methods there is naming convention that we need to follow.we need to start method name with word “test”
- Create the instance of IE web driver
- The driver.get method will navigate to a page given by the URL.this time navigate to 'https://www.google.lk” page
- Then define web driver wait time which tells how much time need to wait until element loaded completely.
- Then find the element using element name and wait until element become clickable.In this case wait 1 min until element become clickable.
- After that verify element available in the page before click on it.After that click on the “I’m Feeling Lucky” button.
- After click on the button, Verify navigated page using page title.
- This line close the browser windows.
- Test script can be run by right click inside the test case method and select “Run Tests” or using test explorer.
0 Comments