Best Python code snippet using autotest_python
test_hugo.py
Source:test_hugo.py
...17 if url[-1] != "/":18 return url + "/"19 else:20 return url21 def get_default_title(self):22 """get default title for site"""23 # pylint: disable=no-self-use24 return "Magnus's site"25 def get_button_by_link_name(self, linktext):26 """find a button based on in its link text"""27 return self.driver.find_element(By.LINK_TEXT, linktext)28 def wait_for_page_to_load(self,url,title):29 """wait 15 seconds to allow a page to fully load"""30 self.driver.get(url)31 WebDriverWait(self.driver, 15).until(32 lambda driver: title in self.driver.title33 )34 def load_index_page(self,url):35 """get the site main page"""36 self.wait_for_page_to_load(url,self.get_default_title())37 def test_index_page(self,url):38 """test the index page for a hugo site"""39 page_url = self.get_default_url(url)40 title = self.get_default_title()41 self.load_index_page(url)42 assert title == self.driver.title43 assert page_url == self.driver.current_url44 self.driver.save_screenshot("test_index_page_00.png")45 def test_lunchtime_post(self,url):46 """test the lunchtime post"""47 self.load_index_page(url)48 page_url = self.get_default_url(url)+"posts/lunchtime/"49 page_title = "Lunchtime | "+self.get_default_title()50 second_post = self.get_button_by_link_name("Lunchtime")51 second_post.click()52 self.wait_for_page_to_load(page_url,page_title)53 assert page_title == self.driver.title54 assert page_url == self.driver.current_url55 # social media links56 facebook_placeholder = self.driver.find_element(By.CSS_SELECTOR,'.facebook')57 assert facebook_placeholder is not None58 twitter_placeholder = self.driver.find_element(By.CSS_SELECTOR,".twitter")59 assert twitter_placeholder is not None60 linedin_placeholder = self.driver.find_element(By.CSS_SELECTOR,".linkedin")61 assert linedin_placeholder is not None62 self.driver.save_screenshot("test_lunchtime_page_00.png")63 def test_afternoon_post(self,url):64 """test the afternoon post"""65 self.load_index_page(url)66 page_url = self.get_default_url(url)+"posts/afternoon/"67 page_title = "RASCI | "+self.get_default_title()68 second_post = self.get_button_by_link_name("RASCI")69 second_post.click()70 self.wait_for_page_to_load(page_url,page_title)71 assert page_title == self.driver.title72 assert page_url == self.driver.current_url73 # social media links74 facebook_placeholder = self.driver.find_element(By.CSS_SELECTOR, '.facebook')75 assert facebook_placeholder is not None76 twitter_placeholder = self.driver.find_element(By.CSS_SELECTOR,".twitter")77 assert twitter_placeholder is not None78 linedin_placeholder = self.driver.find_element(By.CSS_SELECTOR,".linkedin")79 assert linedin_placeholder is not None80 self.driver.save_screenshot("test_afternoon_page_00.png")81 def test_another_page_post(self,url):82 """test the another_page post"""83 self.load_index_page(url)84 page_url = self.get_default_url(url)+"posts/another_page/"85 page_title = "Another_page | "+self.get_default_title()86 second_post = self.get_button_by_link_name("Another_page")87 second_post.click()88 self.wait_for_page_to_load(page_url,page_title)89 assert page_title == self.driver.title90 assert page_url == self.driver.current_url91 # social media links92 facebook_placeholder = self.driver.find_element(By.CSS_SELECTOR, '.facebook')93 assert facebook_placeholder is not None94 twitter_placeholder = self.driver.find_element(By.CSS_SELECTOR,".twitter")95 assert twitter_placeholder is not None96 linedin_placeholder = self.driver.find_element(By.CSS_SELECTOR,".linkedin")97 assert linedin_placeholder is not None98 self.driver.save_screenshot("test_another_page_page_00.png")99 def test_afternoon_post(self,url):100 """test the phoenix post"""101 self.load_index_page(url)102 page_url = self.get_default_url(url)+"posts/phoenix/"103 page_title = "Phoenix Project RASCI | "+self.get_default_title()104 second_post = self.get_button_by_link_name("Phoenix Project RASCI")105 second_post.click()106 self.wait_for_page_to_load(page_url,page_title)107 assert page_title == self.driver.title108 assert page_url == self.driver.current_url109 # social media links110 facebook_placeholder = self.driver.find_element(By.CSS_SELECTOR, '.facebook')111 assert facebook_placeholder is not None112 twitter_placeholder = self.driver.find_element(By.CSS_SELECTOR,".twitter")113 assert twitter_placeholder is not None114 linedin_placeholder = self.driver.find_element(By.CSS_SELECTOR,".linkedin")115 assert linedin_placeholder is not None116 self.driver.save_screenshot("test_phoenix_page_00.png")117 def test_my_first_post_post(self,url):118 """test the my-first-post post"""119 self.load_index_page(url)120 page_url = self.get_default_url(url)+"posts/my-first-post/"121 page_title = "My First Post | "+self.get_default_title()122 second_post = self.get_button_by_link_name("My First Post")123 second_post.click()124 self.wait_for_page_to_load(page_url,page_title)125 assert page_title == self.driver.title126 assert page_url == self.driver.current_url127 # social media links128 facebook_placeholder = self.driver.find_element(By.CSS_SELECTOR, '.facebook')129 assert facebook_placeholder is not None130 twitter_placeholder = self.driver.find_element(By.CSS_SELECTOR,".twitter")131 assert twitter_placeholder is not None132 linedin_placeholder = self.driver.find_element(By.CSS_SELECTOR,".linkedin")133 assert linedin_placeholder is not None134 self.driver.save_screenshot("test_my-first-post_page_00.png")135# pytest test_hugo.py -v --url http://localhost136# pytest test_hugo.py -v --url http:///ce02ice05.s3-website-eu-west-1.amazonaws.com/ --headless=yes137# pytest test_hugo.py -v --url http://stakubdevce02001huice05.z16.web.core.windows.net/ --headless=yes138 # def test_azure_post(self,url):139 # """test the azure post"""140 # self.load_index_page(url)141 # page_url = self.get_default_url(url)+"posts/azure/"142 # page_title = "Azure | "+self.get_default_title()143 # second_post = self.get_button_by_link_name("Azure")144 # second_post.click()145 # self.wait_for_page_to_load(page_url,page_title)146 # assert page_title == self.driver.title147 # assert page_url == self.driver.current_url148 # # social media links149 # facebook_placeholder = self.driver.find_element_by_css_selector('.facebook')150 # assert facebook_placeholder is not None151 # twitter_placeholder = self.driver.find_element_by_css_selector(".twitter")152 # assert twitter_placeholder is not None153 # linedin_placeholder = self.driver.find_element_by_css_selector(".linkedin")154 # assert linedin_placeholder is not None155 # # mermaid diagram156 # mermaid_placeholder = self.driver.find_element_by_class_name("mermaid")157 # assert mermaid_placeholder is not None158 # self.driver.save_screenshot("test_azure_page_00.png")159 # def test_aws_post(self,url):160 # """test the aws post"""161 # self.load_index_page(url)162 # page_url = self.get_default_url(url)+"posts/aws/"163 # page_title = "Aws | "+self.get_default_title()164 # second_post = self.get_button_by_link_name("Aws")165 # second_post.click()166 # self.wait_for_page_to_load(page_url,page_title)167 # assert page_title == self.driver.title168 # assert page_url == self.driver.current_url169 # # social media links170 # facebook_placeholder = self.driver.find_element_by_css_selector('.facebook')171 # assert facebook_placeholder is not None172 # twitter_placeholder = self.driver.find_element_by_css_selector(".twitter")173 # assert twitter_placeholder is not None174 # linedin_placeholder = self.driver.find_element_by_css_selector(".linkedin")175 # assert linedin_placeholder is not None176 # self.driver.save_screenshot("test_aws_page_00.png")177 # def test_gcp_post(self,url):178 # """test the gcp post"""179 # self.load_index_page(url)180 # page_url = self.get_default_url(url)+"posts/gcp/"181 # page_title = "Gcp | "+self.get_default_title()182 # second_post = self.get_button_by_link_name("Gcp")183 # second_post.click()184 # self.wait_for_page_to_load(page_url,page_title)185 # assert page_title == self.driver.title186 # assert page_url == self.driver.current_url187 # # social media links188 # facebook_placeholder = self.driver.find_element_by_css_selector('.facebook')189 # assert facebook_placeholder is not None190 # twitter_placeholder = self.driver.find_element_by_css_selector(".twitter")191 # assert twitter_placeholder is not None192 # linedin_placeholder = self.driver.find_element_by_css_selector(".linkedin")193 # assert linedin_placeholder is not None...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!