3

Previously, I had worked in selenium with java automation. I had learnt page object design pattern , core java , selenium webdriver concepts. then do automate the each page has each class file and automate each page, then keep the data in property file.

Now I want to do with selenium with Python automation. I learned python basics and selenium python concepts. I am new in this python automation. I don't how to get start. I learnt some basics. How to start get to do? I meant like easy methods, what should every python testers should following any framework, page object design pattern.

This is my registration page:

import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select


class PythonRegister(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome(executable_path="/home/naveen/chromedriver")
        self.driver.maximize_window()

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("http://demoqa.com")
        driver.find_element_by_link_text("Registration").click()
        # time.sleep(10)
        elem=driver.find_element_by_id("name_3_firstname")
        elem.send_keys("Antony")
        elem=driver.find_element_by_id("name_3_lastname")
        elem.send_keys("Naveen")
        elem=driver.find_element_by_css_selector("input[type='radio'][value='married']").click()
        # time.sleep(5)
        elem=driver.find_element_by_xpath("//*[@id='pie_register']/li[3]/div/div[1]/input[1]").click()
        time.sleep(5)
        select = Select(driver.find_element_by_id('dropdown_7'))

        # select by visible text
        select.select_by_visible_text('India')

        # month od date



        select = Select(driver.find_element_by_id('mm_date_8'))
        select.select_by_visible_text('9')
        # day of date
        select = Select(driver.find_element_by_id('dd_date_8'))
        select.select_by_visible_text('3')
        #year of date
        select = Select(driver.find_element_by_id('yy_date_8'))
        select.select_by_visible_text('1993')


        time.sleep(10)
        elem=driver.find_element_by_id("phone_9")
        elem.send_keys("9400693133")
        elem=driver.find_element_by_id("email_1")
        elem.send_keys("naveencjnv@gmail.com")
        elem=driver.find_element_by_id("profile_pic_10")
        elem.send_keys("/home/naveen/Documents/pp (1).jpg")

        elem=driver.find_element_by_id("password_2")
        elem.send_keys("antony111")
        elem=driver.find_element_by_id("confirm_password_password_2")
        elem.send_keys("antony111")
        time.sleep(10)
        elem=driver.find_element_by_xpath("//*[@id='pie_register']/li[14]/div/input").click()


    def tearDown(self):
         self.driver.close()


if __name__ == "__main__":
    unittest.main()

What should I need to improve? What should I need to learn?

4

The good news is that, even though you are switching languages, you are going to work with the same Selenium API, which is reflected in many languages. Things are gonna go easy since the API itself is already familiar to you.

On the other hand, you are switching to Python, which is a very concise, "natural" and easy to grasp language. Good news here as well.

A good place to start is Python Selenium documentation - go through tutorial, make sure to cover:

Another good read would be StackOverflow and SQA sites - filter topics by Python + Selenium, sorted by votes and go through them one-by-one - this would give you a good idea of common problems and solutions.

As far as Page Objects go, there are different styles and ways to organize them in Python+Selenium projects. There are pros and cons for each of them - this can be a separate topic of its own.

0

You need to become a competent programmer, regardless of the language you use (and learning multiple languages helps, because you can see what hard parts are just quirks of a language and what parts is genuine complexity of the problem).

Good books to learn Python are "Dive into Python" and "Learn the Python hard way".

Another often underestimated part is: you need to learn how to design data structures to fit your problem space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy