Sur
Sur
Sur
import time
import unittest
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from transformers import pipeline
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %
(message)s')
# Function to login
@retry()
def login(driver, url, username, password):
try:
driver.get(url)
logging.info(f"Navigated to {url}")
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME,
"login"))).send_keys(username)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME,
"password"))).send_keys(password, Keys.RETURN)
logging.info("Logged in successfully")
except Exception as e:
logging.error(f"Login failed: {e}")
driver.save_screenshot("login_error.png")
raise
# Main workflow
def main():
url = "https://example-survey-website.com"
username = "your_username"
password = "your_password"
driver = init_driver()
try:
login(driver, url, username, password)
find_surveys(driver)
questions = extract_questions(driver)
fill_survey(driver, questions)
submit_survey(driver)
except Exception as e:
logging.error(f"Main workflow encountered an error: {e}")
finally:
driver.quit()
logging.info("Closed WebDriver")
if __name__ == "__main__":
main()
def tearDown(self):
self.driver.quit()
def test_login(self):
login(self.driver, "https://example-survey-website.com", "test_user",
"test_pass")
self.assertIn("Dashboard", self.driver.title)
logging.info("Login test passed")
if __name__ == "__main__":
unittest.main()