Best Python code snippet using pytractor_python
test_chrome.py
Source:test_chrome.py
1import pytest2import time3from logfile import *4logger = logging.getLogger()5logger.setLevel(logging.INFO)67def test_checkGoogle_Url(test_chromedriver):8 logger.info("Enter Google URL...")9 driver=test_chromedriver[0]10 driver.get('http://www.google.com')11 time.sleep(3)1213 driver.close()1415def test_checkGoogle_Url(test_chromedriver):16 logger.info("Open the Firefox browser..")17 logger.info('--------------------------------------------------------------------------------------')18 logger.info('test_checkGoogle_Url..............')1920 e_url='https://www.google.com/?gws_rd=ssl'21 logger.info("Enter Google URL...")22 logger.info('We are redirecting to the Google Webpage...')2324 driver = test_chromedriver[0]25 driver.get('http://www.google.com')26 a_url=driver.current_url27 logger.info('actual_url')28 logger.info(a_url)29 logger.info('expected_url')30 logger.info(e_url)31 if(a_url==e_url):32 logger.info("test_checkGoogle_URL: Passed...")33 else:34 logger.info("test_checkGoogle_URL: Failed...")35 time.sleep(3)36 driver.close()373839def test_current_Url(test_chromedriver):40 logger.info('--------------------------------------------------------------------------------------')41 logger.info('test_current_Url..............')42 ex_url='https://online.actitime.com/tcs1/administration/manage_licenses.do'43 logger.info("Enter Actitime URL...")44 logger.info('enter correct username, password and click on Login Button and check it is redirected to the homepage.')4546 driver = test_chromedriver[0]47 driver.get("https://online.actitime.com/tcs1/login.do")48 logger.info("Enter username=kkj28kumanj@gmail.com")49 driver.find_element_by_id('username').send_keys('kkj28kumanj@gmail.com')50 logger.info("Enter password=manager")51 driver.find_element_by_name('pwd').send_keys('manager')52 logger.info("click on the Login button.")53 driver.find_element_by_xpath("//a[@id='loginButton']//div[contains(text(),'Login')]").click()54 time.sleep(4)5556 text=driver.current_url57 logger.info('current_url')58 logger.info(text)59 logger.info('expected_url')60 logger.info(ex_url)61 if(text==ex_url):62 logger.info("test_current_Url: Passed..")63 else:64 logger.info("test_current_Url: Failed..")65 print(text)66 driver.close()676869def test_checkbox(test_chromedriver):70 logger.info('--------------------------------------------------------------------------------------')71 logger.info('test_checkbox..............')72 logger.info('Goto the Actitime webpage....')73 logger.info('click on the checkbox')7475 driver = test_chromedriver[0]76 driver.get("https://online.actitime.com/tcs1/login.do")77 chkbox = driver.find_element_by_id('keepLoggedInCheckBox')78 chkbox.click()7980 if (chkbox.is_selected()):8182 logger.info("test_checkbox: Passed..")83 print("Yes")84 else:85 logger.info("test_checkbox: Failed...")86 print("No")8788 driver.close()8990def test_alert_popup(test_chromedriver):91 logger.info('--------------------------------------------------------------------------------------')92 logger.info('test_alert_popup..............')93 logger.info('Enter the GSRTC webpage url....')94 logger.info('check whether alert popup displayed when we click on search button..')95 ex_data=" 'From' place is required."96 print(ex_data)9798 driver = test_chromedriver[0]99 driver.get('https://gsrtc.in/site/')100 logger.info('Click on the search button.')101 driver.find_element_by_xpath("//button[@id='cboxClose']").click()102 time.sleep(2)103 driver.find_element_by_xpath(104 "//div[@id='menu1']//button[@class='btn btn-primary btn-md'][contains(text(),'Search')]").click()105106 alert = driver.switch_to.alert107108 time.sleep(2)109 data = alert.text110111 print("Alert msg: ", data)112 alert.accept()113114 if(data==ex_data):115 logger.info("test_alert_popup: Passed..")116 else:117 logger.info("test_alert_popup: Failed..")118119 time.sleep(2)120121122def test_multielement(test_chromedriver):123 logger.info('--------------------------------------------------------------------------------------')124 logger.info('test_multielement..............')125 logger.info('enter the Google webpage url..')126 ex_list=['manual testing','manual','manual scavenging','manual testing interview questions','manual meaning','manual testing jobs','manually','manual testing pdf','manual testing tools'127]128129 driver = test_chromedriver[0]130 driver.get('http://www.google.com')131 logger.info('Enter the manual in google searchtextbox')132 driver.find_element_by_name('q').send_keys('manual')133 time.sleep(7)134 lists = driver.find_elements_by_xpath("//span[contains(.,'manual')]") # list of all links which contain manual in it.135136 size = len(lists)137 ac_list=list()138 for i in range(0, size):139 text = lists[i].text # retrieve text from list.140 print(text)141 ac_list.append(text)142 if(ac_list==ex_list):143 logger.info("test_multielement:Passed...")144 else:145 logger.info("test_multielement: Failed..")146 driver.close()147 logger.info('--------------------------------------------------------------------------------------')
...
test_firefox.py
Source:test_firefox.py
1from selenium import webdriver2import time3from logfile import *45driver=webdriver.Firefox(executable_path=r'C:\\Users\\Kothiya.kuman\\Desktop\\Testing\\selenium_sw\\geckodriver-v0.26.0-win64\\geckodriver.exe')6logger = logging.getLogger()7logger.setLevel(logging.INFO)8def test_checkGoogle_Url():9 logger.info("Open the Firefox browser..")10 logger.info('--------------------------------------------------------------------------------------')11 logger.info('test_checkGoogle_Url..............')1213 e_url='https://www.google.com/?gws_rd=ssl'14 logger.info("Enter Google URL...")15 logger.info('We are redirecting to the Google Webpage...')16 driver.get('http://www.google.com')17 a_url=driver.current_url18 logger.info('actual_url')19 logger.info(a_url)20 logger.info('expected_url')21 logger.info(e_url)22 if(a_url==e_url):23 logger.info("test_checkGoogle_URL: Passed...")24 else:25 logger.info("test_checkGoogle_URL: Failed...")26 time.sleep(3)272829303132def test_current_Url():33 logger.info('--------------------------------------------------------------------------------------')34 logger.info('test_current_Url..............')35 ex_url='https://online.actitime.com/tcs1/administration/manage_licenses.do'36 logger.info("Enter Actitime URL...")37 logger.info('enter correct username, password and click on Login Button and check it is redirected to the homepage.')38 driver.get("https://online.actitime.com/tcs1/login.do")39 logger.info("Enter username=kkj28kumanj@gmail.com")40 driver.find_element_by_id('username').send_keys('kkj28kumanj@gmail.com')41 logger.info("Enter password=manager")42 driver.find_element_by_name('pwd').send_keys('manager')43 logger.info("click on the Login button.")44 driver.find_element_by_xpath("//a[@id='loginButton']//div[contains(text(),'Login')]").click()45 time.sleep(4)4647 text=driver.current_url48 logger.info('current_url')49 logger.info(text)50 logger.info('expected_url')51 logger.info(ex_url)52 if(text==ex_url):53 logger.info("test_current_Url: Passed..")54 else:55 logger.info("test_current_Url: Failed..")56 print(text)575859def test_checkbox():60 logger.info('--------------------------------------------------------------------------------------')61 logger.info('test_checkbox..............')62 logger.info('Goto the Actitime webpage....')63 logger.info('click on the checkbox')64 driver.get("https://online.actitime.com/tcs1/login.do")65 chkbox = driver.find_element_by_id('keepLoggedInCheckBox')66 chkbox.click()6768 if (chkbox.is_selected()):6970 logger.info("test_checkbox: Passed..")71 print("Yes")72 else:73 logger.info("test_checkbox: Failed...")74 print("No")75767778def test_alert_popup():79 logger.info('--------------------------------------------------------------------------------------')80 logger.info('test_alert_popup..............')81 logger.info('Enter the GSRTC webpage url....')82 logger.info('check whether alert popup displayed when we click on search button..')83 ex_data=" 'From' place is required."84 print(ex_data)8586 driver.get('https://gsrtc.in/site/')87 logger.info('Click on the search button.')88 driver.find_element_by_xpath("//button[@id='cboxClose']").click()89 time.sleep(2)90 driver.find_element_by_xpath(91 "//div[@id='menu1']//button[@class='btn btn-primary btn-md'][contains(text(),'Search')]").click()9293 alert = driver.switch_to.alert9495 time.sleep(2)96 data = alert.text9798 print("Alert msg: ", data)99 alert.accept()100101 if(data==ex_data):102 logger.info("test_alert_popup: Passed..")103 else:104 logger.info("test_alert_popup: Failed..")105106 time.sleep(2)107108109def test_multielement():110 logger.info('--------------------------------------------------------------------------------------')111 logger.info('test_multielement..............')112 logger.info('enter the Google webpage url..')113 ex_list=['manual testing','manual','manual scavenging','manual testing interview questions','manual meaning','manual testing jobs','manually','manual testing pdf','manual testing tools'114]115116 driver.get('http://www.google.com')117 logger.info('Enter the manual in google searchtextbox')118 driver.find_element_by_name('q').send_keys('manual')119 time.sleep(7)120 lists = driver.find_elements_by_xpath("//span[contains(.,'manual')]") # list of all links which contain manual in it.121122 size = len(lists)123 ac_list=list()124 for i in range(0, size):125 text = lists[i].text # retrieve text from list.126 print(text)127 ac_list.append(text)128 if(ac_list==ex_list):129 logger.info("test_multielement:Passed...")130 else:131 logger.info("test_multielement: Failed..")132 driver.close()133 logger.info('--------------------------------------------------------------------------------------')134 logger.info("Close the browser")135136test_checkGoogle_Url()137test_checkbox()138test_current_Url()139test_alert_popup()
...
test_get_current_url.py
Source:test_get_current_url.py
1import webview2from .util import run_test3def test_current_url():4 run_test(webview, main_func, current_url_test)5def test_no_url():6 run_test(webview, no_url_func, no_url_test)7def main_func():8 webview.create_window('Evaluate JS test', 'https://example.org')9def no_url_func():10 webview.create_window('Evaluate JS test')11def current_url_test():12 assert webview.get_current_url() == 'https://example.org/'13def no_url_test():...
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!!