{"id":652,"date":"2016-12-12T17:04:33","date_gmt":"2016-12-12T17:04:33","guid":{"rendered":"http:\/\/scrolltest.com\/?p=652"},"modified":"2016-12-12T17:33:30","modified_gmt":"2016-12-12T17:33:30","slug":"step-step-selenium-python-part-1","status":"publish","type":"post","link":"https:\/\/scrolltest.com\/step-step-selenium-python-part-1\/","title":{"rendered":"Step by Step Selenium With Python &#8211; Part 1"},"content":{"rendered":"<p>In this series, We going to learn about the create a Test Suite in the Python. Let&#8217;s not waste much of the time lets start as quickly as possible.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-657 alignleft\" src=\"http:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/oie_m1Z1dm3mSVps-300x96.jpg\" alt=\"\" width=\"316\" height=\"101\" srcset=\"https:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/oie_m1Z1dm3mSVps-300x96.jpg 300w, https:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/oie_m1Z1dm3mSVps.jpg 660w\" sizes=\"auto, (max-width: 316px) 100vw, 316px\" \/><\/p>\n<p style=\"text-align: left;\"><strong><br \/>\nThings you know before.<\/strong><br \/>\n1. Selenium &#8211; Testing Framework<br \/>\n2. Python &#8211; Basic Python Syntax. &#8211; Please install it before proceeding.<br \/>\n3. Brain \ud83d\ude1b<\/p>\n<p><strong>About Selenium :<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft\" src=\"http:\/\/www.seleniumhq.org\/images\/big-logo.png\" alt=\"Running selenium server\" width=\"200\" height=\"181\" \/><\/p>\n<p>If you have no clue what is selenium is,Read about Selenium in my other tutorials or you can have a look here for the more <a href=\"http:\/\/www.seleniumhq.org\" target=\"_blank\" rel=\"noopener\">http:\/\/www.seleniumhq.org<\/a>, Just for the quick reference, Selenium is Automation framework written in the java that allows you to automate the web application with the different languages\u00a0support e.g Python,Javascript, Java, Ruby.You can write\u00a0functional\/acceptance tests using Selenium WebDriver.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Installing Python bindings for Selenium<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft\" src=\"https:\/\/bioblog3d.files.wordpress.com\/2013\/12\/seleniumpy.jpg\" alt=\"Running selenium server\" width=\"138\" height=\"138\" \/>Go to Command prompt or Terminal in the Mac and Type.<br \/>\nMake sure pip is installed on your system.(If not you can install it using this<a href=\"http:\/\/stackoverflow.com\/questions\/17271319\/how-to-install-pip-on-mac-os-x\" target=\"_blank\" rel=\"noopener\"> link here<\/a>)<\/p>\n<pre class=\"\">pip install selenium<\/pre>\n<p>It will install the python binding for the selenium \u00a0to your system.<\/p>\n<p><strong>Step 1 : Running Selenium Server and Install Python Selenium bindings<\/strong><\/p>\n<p>Let&#8217;s run the Selenium Server that listens to our command\/Test cases written python and execute them in the browser. Make sure java is installed on your system and its available in the path. If not follow this <a href=\"https:\/\/java.com\/en\/download\/help\/mac_install.xml\" target=\"_blank\" rel=\"noopener\">tutorial<\/a>. And set up to <a href=\"https:\/\/www.mkyong.com\/java\/how-to-set-java_home-environment-variable-on-mac-os-x\/\" target=\"_blank\" rel=\"noopener\">path here<br \/>\n<\/a>Download &#8211;\u00a0<a href=\"https:\/\/goo.gl\/Lyo36k\" target=\"_blank\" rel=\"noopener\">Selenium server here<\/a><a href=\"https:\/\/www.mkyong.com\/java\/how-to-set-java_home-environment-variable-on-mac-os-x\/\" target=\"_blank\" rel=\"noopener\">.<br \/>\n<\/a><\/p>\n<pre class=\"\">Run the Selenium Server with this command.<\/pre>\n<pre class=\"\">java -jar selenium-server-standalone-3.x.x.jar\r\n<\/pre>\n<p>You will see something like this on the command line.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-653 size-medium\" src=\"http:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-12-at-10.15.02-PM-300x149.png\" alt=\"Running selenium server\" width=\"300\" height=\"149\" srcset=\"https:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-12-at-10.15.02-PM-300x149.png 300w, https:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-12-at-10.15.02-PM.png 697w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Selenium Server is up and Running.<\/p>\n<p><strong>Step 2 :\u00a0Creating a Basic Test in the Selenium with Python and Run it.<\/strong><\/p>\n<p>Create a File in the Pycharm ( <a href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\" rel=\"noopener\">Python Editor<\/a>) e.g I have made a Folder structure for the upcoming \u00a0tutorials also. So This part is Part 1 and I have one file HelloWorld.py that will have the code for the First Test case in python.<\/p>\n<p>In the File, we are going<\/p>\n<p>1. Import the selenium web driver.<br \/>\n2. Create a driver object from FirefoxDriver Class and Open the Borwser.<br \/>\n3. Use get method to go to the URL.<br \/>\n4. Assert the title and Close the Brower.<\/p>\n<p>Run the Test by<\/p>\n<pre class=\"\">from selenium import webdriver\r\n\r\ndriver = webdriver.Firefox()\r\ndriver.get(\"http:\/\/www.python.org\")\r\nassert \"Python\" in driver.title\r\ndriver.close()<\/pre>\n<p>File run using python:<\/p>\n<pre class=\"\">python HelloWorld.py<\/pre>\n<figure id=\"attachment_654\" aria-describedby=\"caption-attachment-654\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-654 size-large\" src=\"http:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-12-at-10.23.06-PM-1024x604.png\" alt=\"Python test running using Pycharm\" width=\"1024\" height=\"604\" srcset=\"https:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-12-at-10.23.06-PM-1024x604.png 1024w, https:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-12-at-10.23.06-PM-300x177.png 300w, https:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-12-at-10.23.06-PM-768x453.png 768w, https:\/\/scrolltest.com\/wp-content\/uploads\/2016\/12\/Screen-Shot-2016-12-12-at-10.23.06-PM.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-654\" class=\"wp-caption-text\">Python test running using Pycharm<\/figcaption><\/figure>\n<p>So we have successfully run our first Test, Let&#8217;s move to the other Tutorial in the Next Part2.<br \/>\nHope to see you guys in the next part.<\/p>\n<p>[mc4wp_form id=&#8221;638&#8243;]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this series, We going to learn about the create a Test Suite in the Python. Let&#8217;s not waste much of the time lets start as quickly as possible. Things you know before. 1. Selenium &#8211; Testing Framework 2. Python &#8211; Basic Python Syntax. &#8211; Please install it before proceeding. 3. Brain \ud83d\ude1b About Selenium&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[5,6],"tags":[25,23,14,16,24],"class_list":["post-652","post","type-post","status-publish","format-standard","hentry","category-python","category-selenium","tag-pip","tag-programming","tag-python","tag-selenium","tag-selenium-with-python"],"taxonomy_info":{"category":[{"value":5,"label":"Python"},{"value":6,"label":"Selenium"}],"post_tag":[{"value":25,"label":"pip"},{"value":23,"label":"programming"},{"value":14,"label":"python"},{"value":16,"label":"selenium"},{"value":24,"label":"selenium with python"}]},"featured_image_src_large":false,"author_info":{"display_name":"Promode","author_link":"https:\/\/scrolltest.com\/author\/admin\/"},"comment_info":3,"category_info":[{"term_id":5,"name":"Python","slug":"python","term_group":0,"term_taxonomy_id":5,"taxonomy":"category","description":"","parent":0,"count":29,"filter":"raw","cat_ID":5,"category_count":29,"category_description":"","cat_name":"Python","category_nicename":"python","category_parent":0},{"term_id":6,"name":"Selenium","slug":"selenium","term_group":0,"term_taxonomy_id":6,"taxonomy":"category","description":"","parent":0,"count":38,"filter":"raw","cat_ID":6,"category_count":38,"category_description":"","cat_name":"Selenium","category_nicename":"selenium","category_parent":0}],"tag_info":[{"term_id":25,"name":"pip","slug":"pip","term_group":0,"term_taxonomy_id":25,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":23,"name":"programming","slug":"programming","term_group":0,"term_taxonomy_id":23,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":14,"name":"python","slug":"python","term_group":0,"term_taxonomy_id":14,"taxonomy":"post_tag","description":"","parent":0,"count":20,"filter":"raw"},{"term_id":16,"name":"selenium","slug":"selenium","term_group":0,"term_taxonomy_id":16,"taxonomy":"post_tag","description":"","parent":0,"count":23,"filter":"raw"},{"term_id":24,"name":"selenium with python","slug":"selenium-with-python","term_group":0,"term_taxonomy_id":24,"taxonomy":"post_tag","description":"","parent":0,"count":6,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/comments?post=652"}],"version-history":[{"count":0,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/652\/revisions"}],"wp:attachment":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/media?parent=652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/categories?post=652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/tags?post=652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}