{"id":2505,"date":"2019-08-21T15:45:34","date_gmt":"2019-08-21T15:45:34","guid":{"rendered":"https:\/\/codoid.com\/page-object-pattern-in-python\/"},"modified":"2022-04-13T17:19:06","modified_gmt":"2022-04-13T17:19:06","slug":"page-object-pattern-in-python","status":"publish","type":"post","link":"https:\/\/codoid.com\/automation-testing\/page-object-pattern-in-python\/","title":{"rendered":"Page Object Pattern in Python"},"content":{"rendered":"<blockquote><p>Page objects are commonly used for testing, but should not make assertions themselves. Their responsibility is to provide access to the state of the underlying page. It&#8217;s up to test clients to carry out the assertion logic.<\/p><\/blockquote>\n<p>&#8211;<a href=\"https:\/\/martinfowler.com\/bliki\/PageObject.html\" target=\"_blank\" rel=\"noopener noreferrer\">Martin Fowler<\/a>\n<\/p>\n<p>In this blog article, you will learn how to implement Page Object Pattern using <b>PyPOM<\/b> package.<\/p>\n<p><strong>Installation<\/strong><\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npip install PyPOM\r\n  <\/pre>\n<\/p>\n<p>[\/code]\n<\/p><\/div>\n<p><strong>Sample Code<\/strong><\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nfrom pypom import Page\r\nfrom selenium import webdriver\r\nfrom selenium.webdriver.common.by import By\r\n\r\ndriver = webdriver.Chrome(executable_path='driverschromedriver.exe')\r\n\r\nclass Home(Page):\r\n    _contact_us_locator = (By.ID, 'menu-item-54')\r\n\r\n    @property\r\n    def fill_contact_us_form(self):\r\n        self.find_element(*self._contact_us_locator).click()\r\n\r\nbase_url = 'https:\/\/www.codoid.com'\r\n\r\nhome_page = Home(driver, base_url).open()\r\n\r\nhome_page.fill_contact_us_form\r\n\r\ndriver.quit()\r\n\r\n<\/pre>\n<\/div>\n<h3>In Conclusion:<\/h3>\n<p>We have other page object model packages in Python. We will review them in our subsequent articles. Please feel free to contact us if you face any issues with <a href=\"https:\/\/pypom.readthedocs.io\/en\/latest\/user_guide.html#root-elements\" target=\"_blank\" rel=\"noopener noreferrer\">PyPOM<\/a> implementation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Page objects are commonly used for testing, but should not make assertions themselves. Their responsibility is to provide access to the state of the underlying page. It&#8217;s up to test clients to carry out the assertion logic. &#8211;Martin Fowler In this blog article, you will learn how to implement Page Object Pattern using PyPOM package. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2506,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[182,179,20],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.3 (Yoast SEO v20.3) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Page Object Pattern in Python - Codoid<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Page Object Pattern in Python\" \/>\n<meta property=\"og:description\" content=\"Page objects are commonly used for testing, but should not make assertions themselves. Their responsibility is to provide access to the state of the underlying page. It&#8217;s up to test clients to carry out the assertion logic. &#8211;Martin Fowler In this blog article, you will learn how to implement Page Object Pattern using PyPOM package. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Codoid\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codoid.softwaretestingcompany\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-21T15:45:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-13T17:19:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codoid.com\/wp-content\/uploads\/2020\/08\/Page-Object-Pattern-in-Python-Banner-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codoid\" \/>\n<meta name=\"twitter:site\" content=\"@codoid\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Page Object Pattern in Python - Codoid","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Page Object Pattern in Python","og_description":"Page objects are commonly used for testing, but should not make assertions themselves. Their responsibility is to provide access to the state of the underlying page. It&#8217;s up to test clients to carry out the assertion logic. &#8211;Martin Fowler In this blog article, you will learn how to implement Page Object Pattern using PyPOM package. [&hellip;]","og_url":"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/","og_site_name":"Codoid","article_publisher":"https:\/\/www.facebook.com\/codoid.softwaretestingcompany","article_published_time":"2019-08-21T15:45:34+00:00","article_modified_time":"2022-04-13T17:19:06+00:00","og_image":[{"width":1200,"height":400,"url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/08\/Page-Object-Pattern-in-Python-Banner-1.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@codoid","twitter_site":"@codoid","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/#article","isPartOf":{"@id":"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/"},"author":{"name":"admin","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586"},"headline":"Page Object Pattern in Python","datePublished":"2019-08-21T15:45:34+00:00","dateModified":"2022-04-13T17:19:06+00:00","mainEntityOfPage":{"@id":"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/"},"wordCount":176,"commentCount":0,"publisher":{"@id":"https:\/\/codoid.com\/#organization"},"articleSection":["Automation Testing","Fixed","Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/","url":"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/","name":"Page Object Pattern in Python - Codoid","isPartOf":{"@id":"https:\/\/codoid.com\/#website"},"datePublished":"2019-08-21T15:45:34+00:00","dateModified":"2022-04-13T17:19:06+00:00","breadcrumb":{"@id":"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codoid.com\/learn\/automation-testing\/page-object-pattern-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codoid.com\/"},{"@type":"ListItem","position":2,"name":"Page Object Pattern in Python"}]},{"@type":"WebSite","@id":"https:\/\/codoid.com\/#website","url":"https:\/\/codoid.com\/","name":"Codoid","description":"","publisher":{"@id":"https:\/\/codoid.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codoid.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codoid.com\/#organization","name":"Codoid - Software Testing Company","url":"https:\/\/codoid.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/","url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","contentUrl":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","width":500,"height":500,"caption":"Codoid - Software Testing Company"},"image":{"@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codoid.softwaretestingcompany","https:\/\/twitter.com\/codoid","https:\/\/www.instagram.com\/codoid.softwaretestingcompany\/","https:\/\/www.linkedin.com\/company\/codoid-qacompany","https:\/\/www.pinterest.com\/codoid9282\/codoid-software-testing-company\/","https:\/\/www.youtube.com\/channel\/UCCmOTDQgcf4W8oo22mBMUYA"]},{"@type":"Person","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/codoid.com"]}]}},"_links":{"self":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2505"}],"collection":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/comments?post=2505"}],"version-history":[{"count":3,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2505\/revisions"}],"predecessor-version":[{"id":14284,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2505\/revisions\/14284"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media\/2506"}],"wp:attachment":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media?parent=2505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/categories?post=2505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/tags?post=2505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}