class HandlingObjectRepository: def __init__(self): self.driver = webdriver.Chrome( executable_path= "/home/easyway/Desktop/selnium jars/chromedriver_linux64/chromedriver" ) self.p = Properties() self.p.load( open( '/home/easyway/Music/github/SeleniumWithPython/config.properties' )) self.p.list() def Handling_Object_Repository(self): self.driver.get(self.p["url"]) print(self.driver.title) assert self.driver.title == self.p["title"], "Title is not as expected" def teardown(self): self.driver.close()
from pyjavaproperties import Properties import sys import os if __name__ == '__main__': if len(sys.argv) != 3: print "Usage: python prop_util.py <path to runtime.properties> <mydomain replacement>" sys.exit(1) runtime_filepath = sys.argv[1] print "Updating %s" % runtime_filepath p = Properties() p.load(open(runtime_filepath)) print "****Properties before****" p.list() #Add/replace environment variables that begin with v_ for key, value in [(key[2:], os.environ[key]) for key in os.environ if key.startswith("v_")]: print "Adding key %s: %s" % (key, value) p[key] = value #Replace mydomain in any values newdomain = sys.argv[2] for key, value in [(key, value) for (key, value) in p.iteritems() if "mydomain.edu" in value]: new_value = value.replace("mydomain.edu", newdomain) print "Changing key %s from %s to %s" % (key, value, new_value) p[key] = new_value #Set DB values based on docker-provided environment variables p['VitroConnection.DataSource.url'] = "http://db:8111/v1/graphs/sparql" p['VitroConnection.DataSource.username'] = '******' p['VitroConnection.DataSource.password'] = '******' print "****Properties after****" p.list() p.store(open(runtime_filepath,'w'))
from pyjavaproperties import Properties import sys import os if __name__ == '__main__': if len(sys.argv) != 3: print "Usage: python prop_util.py <path to runtime.properties> <mydomain replacement>" sys.exit(1) runtime_filepath = sys.argv[1] print "Updating %s" % runtime_filepath p = Properties() p.load(open(runtime_filepath)) print "****Properties before****" p.list() #Add/replace environment variables that begin with v_ for key, value in [(key[2:], os.environ[key]) for key in os.environ if key.startswith("v_")]: print "Adding key %s: %s" % (key, value) p[key] = value #Replace mydomain in any values newdomain = sys.argv[2] for key, value in [(key, value) for (key, value) in p.iteritems() if "mydomain.edu" in value]: new_value = value.replace("mydomain.edu", newdomain) print "Changing key %s from %s to %s" % (key, value, new_value) p[key] = new_value #Only set email keys if env var present. if os.environ.get('VIVO_EMAIL', False) != "true": print "Removing email settings." p['email.smtpHost'] = "" p['email.replyTo'] = ""
def main(): properties = Properties() properties.load(open("/home/khepry/home/distributions/PyDataGenerator/PyDataGenerator.properties")) properties.list() maxRows = 100 maxXlsRows = 10000 globalPath = '/home/khepry/home/distributions/PyDataGenerator/temp/' targetName = 'dataGenerator.csv' maxRows = int(properties.getProperty('maxRows', maxRows)) maxXlsRows = int(properties.getProperty('maxXlsRows', maxXlsRows)) globalPath = properties.getProperty('globalPath', globalPath) targetName = properties.getProperty('targetName', targetName) print("-- operating system --") print(platform.system()) print("-- processing messages --") if platform.system() == 'Windows': xlsPgmPath = '"/Program Files/Microsoft Office 15/root/office15/EXCEL.EXE"' txtPgmPath = '"/Program Files (x86)/Notepad++/notepad++.exe"' else: xlsPgmPath = "libreoffice" txtPgmPath = "gedit" tgtFileFullPath = os.path.abspath(globalPath + targetName) tgtFile = open(tgtFileFullPath, 'w', newline='') bgnTime = tyme.time() rows = 0 try: writer = csv.writer(tgtFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) for i in range(0, maxRows): rows += 1 record = Record() record.addField("UUID4", "UUID4").random() record.addField("Alpha", "Alpha").random(20, 25) record.addField("AlphaNumeric", "AlphaNumeric").random() record.addField("Numeric", "Numeric").random() record.addField("String", "String").random() record.addField("Range", "Range").random(12, 24) record.addField("Date", "Date").random(date(1980,1,1), date(2000,12,31)) record.addField("DateTime", "DateTime").random(date(1980,1,1), date(2000,12,31)) record.addField("AgeInYears","Numeric").years(date.today(), record.getField("Date").value) record.addField("AgeInMonths","Numeric").months(date.today(), record.getField("Date").value) record.addField("AgeInDays","Numeric").days(date.today(), record.getField("Date").value) if (i == 0): writer.writerow([key for key in record.fields.keys()]) writer.writerow([field.text for field in record.fields.values()]) finally: tgtFile.close() endTime = tyme.time() elapsedTime = endTime - bgnTime print("{:,}".format(rows) + ' records processed in ' + "{:,.4f}".format(elapsedTime) + ' seconds at ' + "{:,.4f}".format(rows / elapsedTime) + ' rows/second.') if (platform.system() == 'Windows'): if (rows < maxXlsRows): subprocess.call(xlsPgmPath + ' "' + tgtFileFullPath + '"') else: subprocess.call(txtPgmPath + ' "' + tgtFileFullPath + '"') else: if (rows < maxXlsRows): subprocess.call([xlsPgmPath, tgtFileFullPath]) else: subprocess.call([txtPgmPath, tgtFileFullPath])
class abc: global propAbhi global logger global driver def __init__(self): self.propAbhi = Properties() try: propertiesFile = open("./Files/Config.properties") self.propAbhi.load(propertiesFile) self.propAbhi.list() except FileNotFoundError as e: print(e) self.logger = logging.getLogger() self.logger.setLevel(logging.INFO) self.driver = null def GetElement(self, locatorKey): e = null a = self.propAbhi[locatorKey] try: if(locatorKey.endswith("_id")): e = self.driver.find_element_by_id(a) elif(locatorKey.endswith("_name")): e = self.driver.find_element_by_name(a) elif(locatorKey.endswith("_xpath")): e = self.driver.find_element_by_xpath(a) else: self.ReportFail("Locator not correct") assert False ("Locator not correct") return e except Exception as ex: self.ReportFail(self, ex.message) print(ex) assert False def OpenBrowser(self, browserName): print(self.propAbhi["email_xpath"]) if(browserName == "Chrome"): path = "../driver/chromedriver" self.driver = Chrome(executable_path=path) elif (browserName == "Mozilla"): path = "../driver/geckodriver" self.driver = Chrome(executable_path=path) self.driver.implicitly_wait(5) self.driver.maximize_window() def Navigate(self, StringURL): a = self.propAbhi[StringURL] print(a) self.driver.get(a) pass def Type(self, StringXpath, StringData): a = self.propAbhi[StringXpath] print(a) b = self.propAbhi[StringData] print(b) self.driver.find_element_by_xpath(a).send_keys(b) pass def Click(self, locatorKey): self.GetElement(locatorKey).click() pass def verify_title(self): return False def isElementPresent(self, locatorKey): self.list = null a = self.propAbhi[locatorKey] if(locatorKey.endswith("_id")): self.list = self.driver.find_elements_by_id(a) elif(locatorKey.endswith("_name")): self.list = self.driver.find_elements_by_name(a) elif(locatorKey.endswith("_xpath")): self.list = self.driver.find_elements_by_xpath(a) else: self.ReportFail("Locator not correct") assert False ("Locator not correct") if (len(self.list) == 0): return False else: return True def verifyText(self, locatorKey, expectedText): actualText = self.GetElement(locatorKey).text expectedText = self.propAbhi[expectedText] if(actualText == expectedText): return True else: return False def ReportPass(self, Stringmsg): pass def ReportFail(self, Stringmsg): allure.attach(self.driver.get_screenshot_as_png(), "Screenshot of the screen" , AttachmentType.PNG) self.logger.error("Loading Element or element not found") assert True def TakeScreenshot(self, Stringmsg): pass
class BaseTest(): global driver global prop global fake # Constructor def __init__(self): self.prop = Properties() try: propertiesFile = open("../Files/Config.properties", 'r') self.prop.load(propertiesFile) self.prop.list() except FileNotFoundError as e: print(e) def openBrowser(self, browserName): if (browserName == "Chrome"): p = self.prop["chromePath"] self.driver = webdriver.Chrome(executable_path=p) elif browserName == "Firefox": self.driver = webdriver.Firefox( executable_path="../driver/geckdriver") self.driver.implicitly_wait(5) self.driver.fullscreen_window() def navigate(self, stringUrl): a = self.prop[stringUrl] self.driver.get(a) def type(self, stringXapth, stringData): self.driver.find_element_by_xpath(stringXapth).send_keys(stringData) def Type(self, StringXpath, StringData): a = self.prop[StringXpath] print(a) b = self.prop[StringData] print(b) self.driver.find_element_by_xpath(a).send_keys(b) pass def click(self, stringXpath): self.driver.find_element_by_xpath(stringXpath).click() def sleep(self, sec): time.sleep(sec) def mouseHover(self, tgtElement): act = ActionChains(driver) act.move_to_element(self, tgtElement).perform() def dragDrop(self, srcElement, tgtElement): act = ActionChains(driver) act.drag_and_drop(self, srcElement, tgtElement).perform() def takeScreenShot(self, filename=".png"): self.driver.save_screenshot(self, filename=filename) def selectByVisibleTest(self, element, text): sel = Select(element) sel.select_by_visible_text(self, text) def scrollByPixcel(self, driver, pixcel): driver.execute_script("window.scrollBy(0," + pixcel + ")", "") def scrollByElement(self, driver, element): driver.execute_script("arguments[0].scrollIntoView();", element) def scrollTillEnd(self, driver): driver.execute_script("window.scrollBy(0,document.body.scrollHeight)") def colourElement(self, driver, element, colour="yellow"): driver.execute_script( "arguments[0].style.border = '3px solid " + colour + "'", element) def getCountOfElements(self, element): listOfElements = self.driver.find_elements(By.XPATH, element) print("No of elements: " + str(len(listOfElements))) logger.info("No of elements: " + str(len(listOfElements))) for li in listOfElements: print(li.text) def getLinks(self, element): listOfElements = self.driver.find_elements(By.XPATH, element) print("No of elements: " + str(len(listOfElements))) for li in listOfElements: print(li.text + "---> ", li.get_attribute("href")) def getFullName(self): fake = Faker() return fake.name() def getAddress(self): fake = Faker() return fake.address() def getFakeText(self): fake = Faker() return fake.text() def selectByVisbleText(self, element, text): ele = self.driver.find_element(By.XPATH, element) sel = Select(ele) sel.select_by_visible_text(text)