I try to run my test in the folloing order (in DataDrivenFramework module 23)
TestB | |||||
Runmode | Browser | Username | Password | FirstName | LastName |
Y | Chrome | admin | test1 | David | Clark |
N | Mozilla | admin | test1 | Henry | Morris |
Y | Chrome | admin | test1234 | Sam | Legend |
It should run as following order
1 -- {David Clark}
2 -- {Henry Morris}
3 -- {Sam Legend}
However, it run as the following order
1 -- {Sam Legend}
2 -- {Henry Morris}
3 -- {David Clark}
Below are the code. Can you help?
==============
test_dummyB.py
==============
import time
import allure
import pytest
import logging
from delayed_assert import assert_expectations
from DataDrivenFramework import DataUtil
from DataDrivenFramework.BaseTest import abc
from DataDrivenFramework.ReadingData import XLReader
from _overlapped import NULL
testCaseName = NULL
readXLS = NULL
logger=logging.getLogger()
logger.setLevel(logging.INFO)
def getTestData():
global xls
global testCaseName
print("Get Test Data Called")
# Initializing XLS Reader
xls = XLReader("C:\\Users\\iuech\\Desktop\\Book2.xlsx")
# Specifying Test Case Name
testCaseName = "TestB"
return DataUtil.getTestData(testCaseName, xls)
@pytest.mark.parametrize("data", getTestData())
def test_a(data):
base = abc()
if(data.get('Runmode') == "Y"):
with allure.step("Step 1 : Open browser"):
base.OpenBrowser("Chrome")
with allure.step("Step 2 : Navigate to AeMS URL"):
base.Navigate("URL")
time.sleep(2)
with allure.step("Step 3 : Login to AeMS"):
print(data.get("FirstName"), data.get("LastName"))
base.Type("Login_username_xpath",data.get("Username"))
base.Type("Login_password_xpath",data.get("Password"))
base.DropDown("Login_option_xpath","Login_DB")
base.Click("Signin_Button_xpath")
time.sleep(10)
if(base.verify_title("AeMS")):
base.ReportPass("Login Successfully")
else:
base.ReportFail("Login Failed")
with allure.step("Step 4 : Test ended, close browser"):
base.TearDown()
else:
print("Runmode is set to N")
pytest.skip("Runmode is set to N")
def quit_test():
try:
assert_expectations()
except Exception as capturedError:
logger.error(capturedError)
================
DataUtil.py
================
mport logging
# import time
# import allure
# from delayed_assert.delayed_assert import assert_expectations, expect
# import pytest
# from DataDrivenFrameWork import DataUtil
# from DataDrivenFrameWork.Base import abc
from DataDrivenFramework.ReadingData import XLReader
logger = logging.getLogger()
logger.setLevel(logging.INFO)
global readXLS
def isRunnable(testCaseName, readXLS):
sheetName = "TestCases"
row = readXLS.rowCount(sheetName)
for i in range(0, row):
tName = readXLS.getDataUsingColumnName(i, "TCID", "TestCases")
if (tName == testCaseName):
runMode = readXLS.getDataUsingColumnName(i, "Runmode", "TestCases")
if (runMode == "Y"):
return True
else:
return False
def getTestData(testCaseName, xls):
try:
pass
except Exception as capturedError:
logger.error(capturedError)
# Initializing Array to be Returned
myData = []
# Calculating Test Start Row Index
# First Considering it as 0
testStartRowIndex = 0
# Now Calculating the same
while not xls.getDataUsingColumnIndex(testStartRowIndex, 0, "Data") == testCaseName:
testStartRowIndex = testStartRowIndex + 1
# Calculating Column Name Row Index
colStartRowIndex = testStartRowIndex + 1
# Calculating Data Start Row Index
dataStartRowIndex = testStartRowIndex + 2
# Calculating Maximum Number of Rows
maxRows = 0
while not xls.checkEmptyUsingColumnIndex(dataStartRowIndex + maxRows, 1, "Data"):
maxRows = maxRows + 1
# Calculating Maximum Columns
maxCols = 0
while not xls.checkEmptyUsingColumnIndex(colStartRowIndex, maxCols, "Data"):
maxCols = maxCols + 1
# Reading Data from Table
# Loop for Iterating over Rows
for rowNum in range(dataStartRowIndex, dataStartRowIndex + maxRows):
# Initializing Dictionary
Dict = {}
# Loop for Iterating over Cols
for colNum in range(0, maxCols):
# Reading Key
dataKey = xls.getDataUsingColumnIndex(colStartRowIndex, colNum, "Data")
# Reading Value
dataVal = xls.getDataUsingColumnIndex(rowNum, colNum, "Data")
# Inserting Data Into Dictionary
Dict[dataKey] = dataVal
# Inserting Dictionary Inside Array
myData.append(Dict)
return myData
===================
ReadingData.py
===================
'''
Created on 06-Apr-2019
@author: whizdom
'''
import xlrd
import xlwt
from _overlapped import NULL
class XLReader:
readXLS =NULL
# writeXLS = NULL
def __init__(self, path):
self.path = path
self.readXLS = xlrd.open_workbook(path)
self.writeXLS = xlwt.Workbook(encoding = 'ascii')
def rowCount(self, sheetName):
s = self.readXLS.sheet_by_name(sheetName)
return s.nrows
def columnCount(self, sheetName):
s = self.readXLS.sheet_by_name(sheetName)
return s.ncols
def getDataUsingColumnIndex(self,rowIndex, columnIndex, sheetName):
s = self.readXLS.sheet_by_name(sheetName)
return s.cell_value(rowIndex, columnIndex)
def checkEmptyUsingColumnIndex(self,rowIndex, columnIndex, sheetName):
s = self.readXLS.sheet_by_name(sheetName)
cellType = 0
try:
cellType = s.cell_type(rowIndex, columnIndex)
except Exception:
pass
if cellType == xlrd.XL_CELL_EMPTY:
return True
else:
return False
# return s.cell_type(rowIndex, columnIndex)
def getDataUsingColumnName(self,rowIndex, columnName, sheetName):
s = self.readXLS.sheet_by_name(sheetName)
for i in range(0, s.ncols):
extractedColumnName = s.cell_value(0,i)
if (columnName == extractedColumnName):
return s.cell_value(rowIndex, i)
Instructor
09914040666 Replied on 22/05/2020
Hey,
Kindly please zip the project and share
Here you go