1

import unittest

from selenium import webdriver

from datetime import datetime

class Index(unittest.TestCase):

@classmethod
def setUpClass(cls):
    chrome_options = webdriver.ChromeOptions()
    prefs = {"profile.default_content_setting_values.notifications": 2}
    chrome_options.add_experimental_option("prefs", prefs)
    chrome_options.add_argument("start-maximized")
    driver = webdriver.Chrome(chrome_options=chrome_options, executable_path= r'/home/sourav/Desktop/chromedriver')
    driver.maximize_window()

def test_all_links_test(self):
    now = datetime.now()
    date_time = now.strftime("%m%d%Y%H%M%S")
    self.driver.get("https://www.easemytrip.com/")
    links = []
    elems = self.driver.find_elements_by_xpath("//a[@href]")
    for elem in elems:
        href = elem.get_attribute("href")
        links.append(href)
    file1 = open("/home/sourav/PycharmProjects/" + date_time + ".xlsx", "x")
    file1.write("\n".join(links))
    file1.close()

def test_login(self):
    my_account = self.driver.find_element_by_id("spnMyAcc")
    print(my_account)

@classmethod
#def tearDown(self):
def tearDownClass(cls):
    #self.driver.close()
    cls.driver1.quit()

if name == "main": unittest.main()

I'm not able to run multiple test cases

1 Answers1

0

In selenium you can run multiple test class in single file called as xml file. You can create xml file from project folder I have mention my xml file here (class names are test classes for each test cases)

[![See this xml file sample][1]][1]
Justin Lambert
  • 940
  • 1
  • 7
  • 13