I have been testing various automation tasks using Selenium Python library. I faced a very serious issue in that process. That is the delay caused due to poor internet connection. The starting steps are same for all tasks, namely - open browser - go to website - login - open a specific link after login
These tasks take a long time, so I was hoping to find a method by which I could reuse an already open session and continue testing on that window instead of opening new browser window every time I run the script.
Here's what I have tested so far:
Example Original File:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(r'C:\testDir\chromedriver_win32\chromedriver.exe', chrome_options=chrome_options)
url = driver.command_executor._url
session_id = driver.session_id
print("URL:",url,"SESSION ID:",session_id)
driver.get('http://www.facebook.com')
username = "---"
password = "---"
driver.find_element_by_name('email').send_keys(username)
driver.find_element_by_name('pass').send_keys(password)
driver.find_element_by_name('login').click()
# time.sleep(2)
driver.maximize_window()
time.sleep(2)
driver.find_elements_by_name('q').send_keys('Ayush Mandowara')
# element = wait.until(EC.presence_of_element_located((By.xpath, '//input[@placeholder="Search"]'))
driver.find_element_by_xpath('//input[@placeholder="Search"]').send_keys('Ayush Mandowara' + Keys.RETURN)
time.sleep(4)
driver.find_element_by_xpath('//div[contains(text(), "Ayush Mandowara")]').click()
time.sleep(3)
driver.find_element_by_class_name('coverBorder').click()
time.sleep(2)
Connecting File:
from connectingToPrev import url, session_id
driver = webdriver.Remote(command_executor=url,desired_capabilities={})
driver.session_id = session_id
driver.get("http://www.google.com")
This connecting file is following what all has already happened in the previous window, I was expecting it either connect to previous window or to open the last link with correct credentials
Answer in Python is appreciated!