Apr-19-2019, 04:25 PM
(This post was last modified: Apr-19-2019, 04:25 PM by leviathan54.)
I know there is a few discussion PermissionError: [Errno 13] Permission denied: error in the forums but must admit I don't understand it.
I'm trying to use openpyxl (and selenium) to read from and write data to. However I'm not using excel(as i dont have it) so instead am using Libre Office Calc and saving the file as .xlsx
I get the following error PermissionError: [Errno 13] Permission denied: 'C://FireFoxProfile/login1.xlsx'[/python] (see the last line immediately below)
I would be super grateful for any advise or guidance
I've also see commentary about needing to run it as system administrator??
Here is my code - the line of interest i path = "C://FireFoxProfile/login1.xlsx" which is found in the DataDrivenTestCase Module
Module XLUtils
I'm trying to use openpyxl (and selenium) to read from and write data to. However I'm not using excel(as i dont have it) so instead am using Libre Office Calc and saving the file as .xlsx
I get the following error PermissionError: [Errno 13] Permission denied: 'C://FireFoxProfile/login1.xlsx'[/python] (see the last line immediately below)
I would be super grateful for any advise or guidance
C:\Python37\python.exe C:/Users/David/PycharmProjects/POM/DataDrivenTestCase.py
test is passed
Traceback (most recent call last):
File "C:/Users/David/PycharmProjects/POM/DataDrivenTestCase.py", line 31, in <module>
XLUtils.writeData(path, "Sheet1", r, 3, "test passed")
File "C:\Users\David\PycharmProjects\POM\XLUtils.py", line 22, in writeData
workbook.save(file)
File "C:\Python37\lib\site-packages\openpyxl\workbook\workbook.py", line 397, in save
save_workbook(self, filename)
File "C:\Python37\lib\site-packages\openpyxl\writer\excel.py", line 292, in save_workbook
archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
File "C:\Python37\lib\zipfile.py", line 1204, in __init__
self.fp = io.open(file, filemode)
[b]PermissionError: [Errno 13] Permission denied: 'C://FireFoxProfile/login1.xlsx'[/b]I've seen commentary that it needs to be stored in home directly? So currencly i have it in C://FireFoxProfile/ does this mean i need to move the file to C://Python37 (where i have python.exe?)I've also see commentary about needing to run it as system administrator??
Here is my code - the line of interest i path = "C://FireFoxProfile/login1.xlsx" which is found in the DataDrivenTestCase Module
Module XLUtils
import openpyxl
def getRowCount(file, sheetName):
workbook = openpyxl.load_workbook(file)
sheet = workbook.get_sheet_by_name(sheetName)
return(sheet.max_row)
def getColumnCount(file, sheetName):
workbook = openpyxl.load.workbook(file)
sheet = workbook.get_sheet_by_name(sheetName)
return(sheet.max_column)
def readData(file, sheetName, rownum, columnno):
workbook = openpyxl.load_workbook(file)
sheet = workbook.get_sheet_by_name(sheetName)
return sheet.cell(row = rownum, column = columnno).value
def writeData(file, sheetName, rownum, columnno, data):
workbook = openpyxl.load_workbook(file)
sheet = workbook.get_sheet_by_name(sheetName)
sheet.cell(row=rownum, column=columnno).value = data
workbook.save(file)Module DataDrivenTestCasefrom selenium import webdriver
import unittest
import XLUtils
profile_path = 'C:/FireFoxProfile'
profile = webdriver.FirefoxProfile(profile_path)
driver = webdriver.Firefox(firefox_profile=profile_path)
driver.implicitly_wait(5)
driver.get('http://www.demoaut.com/')
driver.maximize_window()
[b]path = "C://FireFoxProfile/login1.xlsx"[/b]
rows = XLUtils.getRowCount(path, 'Sheet1')
for r in range(2, rows):
username = XLUtils.readData(path, "Sheet1", r, 1)
password = XLUtils.readData(path, "Sheet1", r, 2)
driver.find_element_by_name("userName").send_keys(username)
driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_name("login").click()
if driver.title == "Find a Flight: Mercury Tours:":
print("test is passed")
XLUtils.writeData(path, "Sheet1", r, 3, "test passed")
else:
print("test failed")
XLUtils.writeData(path, "Sheet1", r, 3, "test failed")
driver.find_element_by_link_text("Home").click()
@classmethod
def tearDownClass(cls):
cls.driver.quit()
if __name__ == '__main__':
unittest.main(verbosity=2)
