def setup(request, setUpClass): print("initiating chrome driverd") driver = Browser().getbrowser("chrome") url = URL() driver.get(url.webViewerUAT) utility = Utility() # utility.createLogFolder() log = open(utility.logpath + "/WV-00.txt", "a+") driverUtility = DriverUtility(driver, log) loginPageObject = LoginPageObject(driverUtility, log) request.cls.driver = driver request.cls.url1 = url request.cls.utility = utility request.cls.driverUtility = driverUtility request.cls.loginPageObject = loginPageObject print("setup ended") yield driver driver.close()
def _get(self, url, sub_dir): capture = Capture(sub_dir, self.conf) browser = Browser(url, sub_dir, self.conf) links = [] try: capture.run() sleep(3) html = browser.get() links = self._get_links(html) sleep(30) except WebDriverException: self._create_exception_file(traceback.format_exc(), sub_dir) except KeyboardInterrupt: self._create_exception_file(traceback.format_exc(), sub_dir) finally: capture.kill() browser.close() return links
class WV00(unittest.TestCase): # @pytest.fixture(scope="module") def setUpClass(self): self.utility = Utility() # CHANGE THE LOG FILE NAME IN THE NEXT LINE****************************************************************************************** self.log = open(self.utility.logpath + "/WV-00.txt", "a+") self.suite_start_time = time.time() self.log.write("Suite started at {}\n".format( str(time.ctime(int(self.suite_start_time))))) self.url = URL() self.loginPageStaticTexts = LoginPageStaticText() self.loginPageTestData = LoginPageTestData() self.configTestCase = configparser.RawConfigParser() # CHANGE THE CONFIG PROPERTY FILE NAME IN THE NEXT LINE****************************************************************************************** self.configTestCase.read( os.path.dirname(os.getcwd()) + '/TestCases/WV_00_Config.properties') self.configECG = configparser.RawConfigParser() self.configECG.read( os.path.dirname(os.getcwd()) + '/Scripts/ECGRelatedData.properties') self.configDevice = configparser.RawConfigParser() self.configDevice.read( os.path.dirname(os.getcwd()) + '/Scripts/DeviceRelatedData.properties') self.sendECG = SendECG() yield self.suite_end_time = time.time() self.total_time_taken_suite = self.suite_end_time - self.suite_start_time self.log.write("Suite ended at {}\n".format( str(time.ctime(int(self.suite_end_time))))) self.log.write( "Total time taken by Test Suite to finish: {} seconds\n".format( self.total_time_taken_suite)) self.log.close() @pytest.fixture() def setUp(self): self.driver = Browser().getbrowser("chrome") self.driver.get(self.url.webViewerUAT) self.driverUtility = DriverUtility(self.driver, self.log) self.loginPageObject = LoginPageObject(self.driverUtility, self.log) yield self.driver.close() # WV-00-000 # Description : # Procedure/Protocol : # - Generate a test ECG # Acceptance Criteria : def test_WV00(self, setUpClass, setUp): testCaseID = "WV-00-000" if self.configTestCase.get(testCaseID, 'Enabled') == "Yes": startTime = self.driverUtility.startTestCase(testCaseID) try: # code here for test cases without ECGs******************************************************************************** self.driverUtility.passedTestCase(testCaseID, startTime) except AssertionError as error: self.driverUtility.failedTestCase(testCaseID) except Exception as e: self.driverUtility.erroredTestCase(testCaseID) else: self.log.write("Test case {} not enabled\n".format(testCaseID)) self.log.write( "********************************************************************************\n" )
def setup(request, setUpClass): print("initiating chrome driverd") driver = Browser().getbrowser("chrome") url = URL() driver.get(url.webViewerUAT) utility = Utility() # utility.createLogFolder() log = open(utility.logpath + "/WV-00.txt", "a+") driverUtility = DriverUtility(driver, log) loginPageObject = LoginPageObject(driverUtility, log) request.cls.driver = driver request.cls.url1 = url request.cls.utility = utility request.cls.driverUtility = driverUtility request.cls.loginPageObject = loginPageObject print("setup ended") yield driver driver.close() # from datetime import datetime # def pytest_logger_config(logger_config): # logger_config.add_loggers(['foo', 'bar', 'baz'], stdout_level='debug') # logger_config.set_log_option_default('foo,bar') # def pytest_logger_logdirlink(config): # print("1") # path = os.path.dirname(os.getcwd()) + '/Logs/' # foldername = datetime.now().strftime("%Y%m%d-%H%M%S") # logpath = path+foldername # try: # # return os.mkdir(logpath) # return os.path.join(path, foldername) # # return logpath # except OSError as e: # print("Creation of the directory failed") # print(traceback.format_exc()) # else: # print("Successfully created the directory") # return os.path.join(os.path.dirname(__file__), 'mylogs') # @pytest.yield_fixture(scope='session') # def session_thing(): # foo.debug('constructing session thing') # yield # foo.debug('destroying session thing') # @pytest.yield_fixture # def testcase_thing(): # foo.debug('constructing testcase thing') # yield # foo.debug('destroying testcase thing') # @pytest.fixture(scope="class") # def setup(request): # print("initiating chrome driver") # driver = Browser().getbrowser("chrome") #if not added in PATH # url = URL() # utility = Utility() # # driver.maximize_window() # request.cls.d = driver # request.cls.u = utility # request.cls.url1 = url # yield # driver.close() # import pytest # from selenium import webdriver # @pytest.fixture(scope="class") # def setup(request): # print("initiating chrome driver") # driver = Browser().getbrowser("chrome") #if not added in PATH # url = URL() # utility = Utility() # # driver.maximize_window() # request.cls.d = driver # request.cls.u = utility # request.cls.url1 = url # yield driver # driver.close() # @pytest.fixture(scope='session') # def config(): # with open('WV_00_Config.json') as config_file: # data = json.load(config_file) # for r in data['Enabled']: # print (r[b]) # return data
class Upload: def __init__(self, user): self.bot = None self.lang = "en" self.url = f"https://www.tiktok.com/upload?lang={self.lang}" self.cookies = None self.userRequest = {"dir": "", "cap": "", "vidTxt": ""} self.video = None self.IO = IO("hashtags.txt", "schedule.csv") self.videoFormats = ["mov", "flv", "avi"] self.userPreference = user # Class used to upload video. def uploadVideo(self, video_dir, videoText, startTime=0, endTime=0, private=True, test=False, scheduled=False, schdate="", schtime=""): video_dir = self.downloadIfYoutubeURL(video_dir) if not video_dir: return if self.bot is None: self.bot = Browser().getBot() self.webbot = Bot(self.bot) self.userRequest["dir"] = video_dir self.checkFileExtensionValid() self.userRequest["cap"] = self.IO.getHashTagsFromFile() # Initiate bot if isn't already. self.bot.get(self.url) self.userRequest["vidTxt"] = videoText # Cookies loaded here. self.cookies = Cookies(self.bot) self.bot.refresh() # User now has logged on and can upload videos time.sleep(3) self.inputVideo(startTime, endTime) self.addCaptions() utils.randomTimeQuery() if private: self.webbot.selectPrivateRadio() # private video selection else: self.webbot.selectPublicRadio() # public video selection utils.randomTimeQuery() if not test: self.webbot.uploadButtonClick() # upload button input("Press any button to exit") def createVideo(self, video_dir, videoText, startTime=0, endTime=0): video_dir = self.downloadIfYoutubeURL(video_dir) if not video_dir: return self.inputVideo(startTime, endTime) self.addCaptions() print(f"Video has been created: {self.dir}") # Method to check file is valid. def checkFileExtensionValid(self): if self.userRequest["dir"].endswith('.mp4'): pass else: self.bot.close() exit(f"File: {self.userRequest['dir']} has wrong file extension.") # This gets the hashtags from file and adds them to the website input def addCaptions(self, hashtag_file=None): if not hashtag_file: caption_elem = self.webbot.getCaptionElem() for hashtag in self.IO.getHashTagsFromFile(): caption_elem.send_keys(hashtag) def clearCaptions(self): caption_elem = self.webbot.getCaptionElem() caption_elem.send_keys("") def inputScheduler(self, schdate, schtime): # In charge of selecting scheduler in the input. utils.randomTimeQuery() self.webbot.selectScheduleToggle() # This is in charge of adding the video into tiktok input element. def inputVideo(self, startTime=0, endTime=0): try: file_input_element = self.webbot.getVideoUploadInput() except Exception as e: print( "Major error, cannot find the upload button, please update getVideoUploadInput() in Bot.py" ) print(f"Actual Error: {e}") file_input_element = "" exit() # Check if file has correct .mp4 extension, else throw error. self.video = Video(self.userRequest["dir"], self.userRequest["vidTxt"], self.userPreference) print(f"startTime: {startTime}, endTime: {endTime}") if startTime != 0 and endTime != 0 or endTime != 0: print(f"Cropping Video timestamps: {startTime}, {endTime}") self.video.customCrop(startTime, endTime) # Crop first and then make video. self.video.createVideo() # Link to video class method while not os.path.exists(self.video.dir): # Wait for path to exist time.sleep(1) abs_path = os.path.join(os.getcwd(), self.video.dir) file_input_element.send_keys(abs_path) def downloadIfYoutubeURL(self, video_dir) -> str: """ Function will determine whether given video directory is a youtube link, returning the downloaded video path Else it will just return current path. """ url_variants = [ "http://youtu.be/", "https://youtu.be/", "http://youtube.com/", "https://youtube.com/", "https://m.youtube.com/", "http://www.youtube.com/", "https://www.youtube.com/" ] if any(ext in video_dir for ext in url_variants): print("Detected Youtube Video...") video_dir = Video.get_youtube_video(self.userPreference, video_dir) return video_dir def directUpload(self, filename, private=False, test=False): if self.bot is None: self.bot = Browser().getBot() self.webbot = Bot(self.bot) self.bot.get(self.url) utils.randomTimeQuery() self.cookies = Cookies(self.bot) self.bot.refresh() try: file_input_element = self.webbot.getVideoUploadInput() except Exception as e: print(f"Error: {e}") print( "Major error, cannot find the file upload button, please update getVideoUploadInput() in Bot.py" ) file_input_element = None exit() abs_path = os.path.join(os.getcwd(), filename) try: file_input_element.send_keys(abs_path) except StaleElementReferenceException as e: try: self.bot.implicitly_wait(5) file_input_element = self.webbot.getVideoUploadInput() file_input_element.send_keys(abs_path) except Exception as e: print( "Major error, cannot find the file upload button, please update getVideoUploadInput() in Bot.py" ) exit() # We need to wait until it is uploaded and then clear input. self.addCaptions() utils.randomTimeQuery() if private: self.webbot.selectPrivateRadio() # private video selection utils.randomTimeQuery() else: """ self.webbot.selectPublicRadio() # public video selection utils.randomTimeQuery() """ pass if not test: self.webbot.uploadButtonClick() # upload button input("Press any button to exit")