Exemple #1
0
        public void GetRowByRowData()
        {
            Assert.IsTrue(File.Exists(Path.Combine(_filePath, FileName)));
            // copy file
            _destFolder = Path.Combine(
                FileAndFolder.GetExecutionDirectory(),
                SolutionFolders.Resources.ToString(),
                SolutionFolders.Resources.ToString(),
                "HomePageLocator"
                );
            if (!Directory.Exists(_destFolder))
            {
                Directory.CreateDirectory(_destFolder);
            }
            FileAndFolder.CopyFile(FileName, _filePath, FileName, _destFolder);

            _destFile = Path.Combine(_destFolder, FileName);
            Assert.IsTrue(File.Exists(_destFile));
            var allObjects = _excel.GetExcelFileObjects(_destFile);

            var rows = allObjects.GetLength(0);

            //var columns = allObjects.GetLength(1);
            for (var r = 1; r < rows; r++)
            {
                var pageObject = new PageElement
                {
                    Name  = allObjects.GetValue(r, 0).ToString(),
                    By    = allObjects.GetValue(r, 1).ToString(),
                    Query = allObjects.GetValue(r, 2).ToString(),
                };
                Console.WriteLine(pageObject);
                Assert.NotNull(pageObject);
            }
        }
        public List <PageElement> GetPageElementsFromExccelFile(string filename, string[] folderStructure)
        {
            var exeDir = FileAndFolder.GetExecutionDirectory();

            Log.Info("Execution directory is: " + exeDir);
            var fileLocation = exeDir;

            foreach (var folder in folderStructure)
            {
                fileLocation = Path.Combine(fileLocation, folder);
                Log.Info("New Path: " + fileLocation);
            }
            fileLocation = Path.Combine(fileLocation, filename);
            if (!File.Exists(fileLocation))
            {
                var message = $"Trying to Open {filename} from {fileLocation}";
                Log.Error(message);
                throw new FileNotFoundException(message);
            }
            var spreadsheet  = new SpreadsheetUtility();
            var excelObjects = spreadsheet.GetExcelFileObjects(fileLocation);
            var pageElements = new List <PageElement>();

            var rows = excelObjects.GetLength(0);

            //var columns = allObjects.GetLength(1);
            for (var r = 1; r < rows; r++)
            {
                var pageElement = new PageElement()
                {
                    Name  = excelObjects.GetValue(r, 0).ToString(),
                    By    = excelObjects.GetValue(r, 1).ToString(),
                    Query = excelObjects.GetValue(r, 2).ToString(),
                };
                Log.Info(pageElement + " Added To the Collection");
                Console.WriteLine(pageElement);
                Assert.NotNull(pageElement);
                pageElements.Add(pageElement);
            }
            return(pageElements);
        }