Advertisement
Guest User

Untitled

a guest
Nov 7th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.29 KB | None | 0 0
  1. namespace ObservatoryAutomatedFunctional.Tests
  2. {
  3. [TestClass]
  4. public class LineDetailAnalysisTests: IDisposable
  5. {
  6. private IWebDriver driver;
  7. private FirefoxBinary binary;
  8. private string baseUrl = Tests.Urls.BaseUrl;
  9. private string firefoxPath = Tests.DriverSetup.FirefoxPath;
  10. private string driverPath = Tests.DriverSetup.DriverPath;
  11. private string actualData = Tests.OutcomeFileLocations.ActualOutcome + "Analyse_SpendBySubjective_Act.csv";
  12. private string expectedData = Tests.OutcomeFileLocations.ExpectedOutcome + "Analyse_SpendBySubjective_Exp.csv";
  13. private string actualData2 = Tests.OutcomeFileLocations.ActualOutcome + "Analyse_SpendByDirectorate_Act.csv";
  14. private string expectedData2 = Tests.OutcomeFileLocations.ExpectedOutcome + "Analyse_SpendByDirectorate_Exp.csv";
  15. private string actualData3 = Tests.OutcomeFileLocations.ActualOutcome + "Analyse_SpendByCostCentre_Act.csv";
  16. private string expectedData3 = Tests.OutcomeFileLocations.ExpectedOutcome + "Analyse_SpendByCostCentre_Exp.csv";
  17. private string actualData4 = Tests.OutcomeFileLocations.ActualOutcome + "Analyse_SpendByDepartment_Act.csv";
  18. private string expectedData4 = Tests.OutcomeFileLocations.ExpectedOutcome + "Analyse_SpendByDepartment_Exp.csv";
  19.  
  20. [TestInitialize()]
  21. //Set the browswer from a build
  22. public void MyTestInitialize()
  23. {
  24. //Point to a specified version of FireFox
  25. FirefoxProfile profile = new FirefoxProfile();
  26. binary = new FirefoxBinary(firefoxPath);
  27.  
  28. //Choose browser based on value in ParameterValues file
  29. if (Tests.DriverSetup.Browser.Equals("ff"))
  30. {
  31. driver = new FirefoxDriver(binary, profile);
  32. }
  33. else if (Tests.DriverSetup.Browser.Equals("ie"))
  34. {
  35. driver = new InternetExplorerDriver(driverPath);
  36. }
  37. else if (Tests.DriverSetup.Browser.Equals("ch"))
  38. {
  39. driver = new ChromeDriver(driverPath);
  40. }
  41. }
  42.  
  43. [TestMethod]
  44. [TestCategory("Selenium")]
  45. public void LineDetailAnalysis()
  46. {
  47. //Maximize the browser window
  48. driver.Manage().Window.Maximize();
  49.  
  50. //Login with user
  51. driver.Url = baseUrl;
  52. IWebElement Username = driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_txtUsername"));
  53. IWebElement Password = driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_txtPassword"));
  54. Username.Clear();
  55. Username.SendKeys(Tests.UserDetails.User1);
  56. Password.Clear();
  57. Password.SendKeys(Tests.UserDetails.Password1);
  58. Password.SendKeys(Keys.Enter);
  59.  
  60. //Switch focus to the header frame
  61. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.HeaderMenuFrame);
  62.  
  63. WebDriverWait wait10 = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
  64. WebDriverWait wait30 = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
  65.  
  66. //Wait for "Home" menu to be visible
  67. wait10.Until(ExpectedConditions.ElementToBeClickable((By.XPath("//*[@alt='Home']")))).Click();
  68.  
  69. //Switch focus to the left side menu
  70. driver.SwitchTo().DefaultContent();
  71. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.LeftMenuFrame);
  72.  
  73. wait10.Until(ExpectedConditions.ElementIsVisible((By.
  74. XPath("//*[contains(@id, 'menuContainer')]/div/div[contains(text(),'Admin')]")))).GetAttribute("Id");
  75.  
  76. //Wait for the "Admin" arrow to be visible, then click
  77. wait10.Until(ExpectedConditions.ElementIsVisible((By.
  78. XPath("//*[contains(@id, 'menuContainer')]/div/div[contains(text(),'Admin')]/following-sibling::node()[contains(@id,'menuInfo')]")))).Click();
  79.  
  80. //Wait for the "Web Admin" report to be visible
  81. wait10.Until(ExpectedConditions.ElementIsVisible((By.
  82. XPath("//*[contains(@id,'menuContentArea')]/li[1]/span[contains(text(),'Web Admin')]")))).Click();
  83.  
  84. //Wait for 1 second to allowsub menu to drop
  85. Thread.Sleep(1000);
  86.  
  87. //Switch focus to the main frame
  88. driver.SwitchTo().DefaultContent();
  89. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.MainBodyFrame);
  90.  
  91. // select the client drop down list
  92. var client = driver.FindElement(By.Id("cboAccounts"));
  93. //create select element object
  94. var selectElement = new SelectElement(client);
  95. //select by value
  96. selectElement.SelectByText(Tests.SpendByDirectorate.ClientName);
  97.  
  98. //Click the "Move here" button
  99. driver.FindElement(By.XPath("//*[@id='cmdMoveHere']")).Click();
  100.  
  101. //Switch focus to the header frame
  102. driver.SwitchTo().DefaultContent();
  103. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.HeaderMenuFrame);
  104.  
  105. //Wait for "Spend Analysis" menu to be visible
  106. IWebElement menuitem = wait10.
  107. Until(ExpectedConditions.ElementIsVisible((By.
  108. XPath("//img[@alt='Spend Analysis']"))));
  109.  
  110. //Hover over "Measurement" menu
  111. Actions action = new Actions(driver);
  112. action.MoveToElement(menuitem).Perform();
  113.  
  114. //Wait for 1 second to allowsub menu to drop
  115. Thread.Sleep(1000);
  116.  
  117. //Switch focus to the main frame
  118. driver.SwitchTo().DefaultContent();
  119. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.MainBodyFrame);
  120.  
  121. //Wait for the "Measure" sub menu to be visible, then click
  122. wait10.Until(ExpectedConditions.ElementToBeClickable((By.
  123. XPath("//*[contains(text(),'Analyze')]")))).Click();
  124.  
  125. //Accept any alerts that may pop up
  126. for (int i = 0; i < 5; i++)
  127. {
  128. if (IsAlertPresent())
  129. {
  130. driver.SwitchTo().Alert().Accept();
  131. System.Diagnostics.Debug.WriteLine("Alert is present");
  132. }
  133. else
  134. {
  135. System.Diagnostics.Debug.WriteLine("No Alerts are present");
  136. break;
  137. }
  138. }
  139.  
  140. //Switch focus to the left side menu
  141. driver.SwitchTo().DefaultContent();
  142. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.LeftMenuFrame);
  143.  
  144. wait10.Until(ExpectedConditions.ElementIsVisible((By.
  145. XPath("//*[contains(@id, 'menuContainer')]/div/div[contains(text(),'Line Detail Analysis')]/following-sibling::node()[contains(@id,'menuInfo')]")))).Click();
  146.  
  147. //Wait for the "Gains by Lead Buyer" report to be visible
  148. wait10.Until(ExpectedConditions.ElementIsVisible((By.
  149. XPath("//*[contains(text(),'Spend by Subjective')]"))));
  150.  
  151. //Wait for 1 second to allowsub menu to drop
  152. Thread.Sleep(1000);
  153.  
  154. //Move to the "Gains by Lead Buyer" and click
  155. IWebElement element = driver.FindElement(By.
  156. XPath("//*[contains(text(),'Spend by Subjective')]"));
  157. Actions actions = new Actions(driver);
  158. actions.MoveToElement(element).Click().Perform();
  159.  
  160. //Switch focus back to the main frame
  161. driver.SwitchTo().DefaultContent();
  162. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.MainBodyFrame);
  163.  
  164. //Wait for the "Data" tabs frame to be visible
  165. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  166. Id(Tests.LineDetailAnalysis.TableFrame))));
  167.  
  168. //Switch focus back to the main frame
  169. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.TableFrame);
  170.  
  171.  
  172. //Wait for the "Measure" sub menu to be visible, then click
  173. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  174. XPath("//*[@id='lwDataGrid_Main_Header_Column1'][contains(text(),'Subjective Description')]"))));
  175.  
  176. //Switch focus back to the main frame
  177. driver.SwitchTo().DefaultContent();
  178. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.MainBodyFrame);
  179.  
  180.  
  181. //Select the required dataset from the dataset panel
  182. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  183. XPath("//*[@id='filter_panel_sidebar']")))).Click();
  184.  
  185. wait30.Until(ExpectedConditions.ElementToBeClickable((By.
  186. XPath("//*[@id='fp_dataset']")))).Click();
  187.  
  188. wait30.Until(ExpectedConditions.ElementToBeClickable(By.
  189. XPath("//*[@id='btn_clear_datasets']"))).Click();
  190.  
  191. Thread.Sleep(3000);
  192.  
  193. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.TableFrame);
  194.  
  195. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  196. XPath("//*[contains(text(),'Rows:')][contains(@id,'gpPanel')]"))));
  197.  
  198. //Switch focus back to the main frame
  199. driver.SwitchTo().DefaultContent();
  200. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.MainBodyFrame);
  201.  
  202. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  203. XPath("//*[@id='scrolling_dropdown_container']/div/ul/li/label[contains(text(),'UW Eau Claire (Jul 14-Jun 15)')]/preceding-sibling::node()"))));
  204.  
  205. wait30.Until(ExpectedConditions.InvisibilityOfElementLocated(By.
  206. XPath("//*[@id='dataset_busy_cover_panel']")));
  207.  
  208. driver.FindElement(By.
  209. XPath("//*[@id='scrolling_dropdown_container']/div/ul/li/label[contains(text(),'UW Eau Claire (Jul 14-Jun 15)')]/preceding-sibling::node()")).Click();
  210.  
  211. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  212. XPath("//*[@id='scrolling_dropdown_container']/div/ul/li/label[contains(text(),'UW Eau Claire (Jul 14-Jun 15)')]/preceding-sibling::node()"))));
  213.  
  214. wait30.Until(ExpectedConditions.InvisibilityOfElementLocated(By.
  215. XPath("//*[@id='dataset_busy_cover_panel']")));
  216.  
  217. wait30.Until(ExpectedConditions.ElementToBeClickable((By.
  218. XPath("//*[@id='btn_apply_datasets']")))).Click();
  219.  
  220. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  221. XPath("//*[@id='filter_panel_sidebar']")))).Click();
  222.  
  223. Thread.Sleep(3000);
  224.  
  225. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.TableFrame);
  226.  
  227. //Wait for the "Measure" sub menu to be visible, then click
  228. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  229. XPath("//*[@id='lwDataGrid_Main_Header_Column1'][contains(text(),'Subjective Description')]"))));
  230.  
  231. //Wait for the last cell in the table to be available
  232. wait30.Until(ExpectedConditions.ElementToBeClickable((By.
  233. XPath("//div[@id='lwDataGrid']/table/tbody/tr[last()]/td[last()]"))));
  234.  
  235. //divided xpath In three parts to pass Row_count and Col_count values.
  236. String firstPart = "//div[@id='lwDataGrid']/table/tbody/tr[";
  237. String secondPart = "]/td[";
  238. String thirdPart = "]";
  239.  
  240. //Row and Column counts
  241. int rowCount = driver.FindElements(By.XPath("//div[@id='lwDataGrid']/table/tbody/tr[*]")).Count - 3;
  242. int colCount = driver.FindElements(By.XPath("//div[@id='lwDataGrid']/table/tbody/tr[1]/td")).Count - 1;
  243. System.Diagnostics.Debug.WriteLine(rowCount + ": This is the number of rows in the table");
  244. System.Diagnostics.Debug.WriteLine(colCount + ": This is the number of columns in the table");
  245.  
  246. using (StreamWriter sw = new StreamWriter(actualData, false))
  247. {
  248. //Used for loop for number of rows
  249. for (int i = 1; i <= rowCount + 3; i++)
  250. {
  251. if (i == 2 | i == 3)
  252. {
  253. continue;
  254. }
  255.  
  256. string line = string.Empty;
  257. //Used for loop for number of columns
  258. for (int j = 2; j <= colCount + 1; j++)
  259. {
  260. //Prepared final xpath of specific cell as per values of i and j.
  261. String finalXpath = firstPart + i + secondPart + j + thirdPart;
  262. //Will retrieve value from located cell and print It.
  263. String tableData = driver.FindElement(By.XPath(finalXpath)).Text;
  264. tableData = tableData.Replace(",", "");
  265.  
  266. //Add double quotes to comma numbers
  267. if (j == colCount + 1)
  268. {
  269. //Do not include 1st (header) row
  270. line = line + string.Format(CultureInfo.CurrentCulture, "{0}", tableData);
  271. }
  272. else
  273. {
  274. line = line + string.Format(CultureInfo.CurrentCulture, "{0},", tableData);
  275. }
  276. }
  277. sw.WriteLine(line.ToString());
  278. //sw.WriteLine(line);
  279. }
  280. }
  281.  
  282. // Create the IEnumerable data sources.
  283. string[] firstCSV = System.IO.File.ReadAllLines(actualData);
  284. string[] secondCSV = System.IO.File.ReadAllLines(expectedData);
  285. int count = 0;
  286.  
  287. // Create the query. Note that method syntax must be used here.
  288. IEnumerable<string> szDifference =
  289. firstCSV.Except(secondCSV);
  290.  
  291. foreach (string szTest in szDifference)
  292. {
  293. count = count + 1;
  294. System.Diagnostics.Debug.WriteLine(szTest + " exist in firstCSV but not in secondCSV");
  295. }
  296.  
  297. if (count > 0)
  298. {
  299. Assert.Fail("The data does not match the expected outcome file!");
  300. }
  301. else
  302. {
  303. System.Diagnostics.Debug.WriteLine("Data is as expected");
  304. }
  305.  
  306.  
  307. //[* * * SPEND BY DIRECTORATES * * *]
  308.  
  309. driver.SwitchTo().DefaultContent();
  310. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.LeftMenuFrame);
  311.  
  312. driver.FindElement(By.
  313. XPath("//*[contains(text(),'Spend by Directorate')]")).Click();
  314.  
  315. //Switch focus back to the main frame
  316. driver.SwitchTo().DefaultContent();
  317. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.MainBodyFrame);
  318.  
  319. Thread.Sleep(3000);
  320.  
  321. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.TableFrame);
  322.  
  323. //Wait for the "Measure" sub menu to be visible, then click
  324. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  325. XPath("//*[@id='lwDataGrid_Main_Header_Column1'][contains(text(),'Directorate Description')]"))));
  326.  
  327. //Wait for the last cell in the table to be available
  328. wait30.Until(ExpectedConditions.ElementToBeClickable((By.
  329. XPath("//div[@id='lwDataGrid']/table/tbody/tr[last()]/td[last()]"))));
  330.  
  331. //Row and Column counts
  332. rowCount = driver.FindElements(By.XPath("//div[@id='lwDataGrid']/table/tbody/tr[*]")).Count - 3;
  333. colCount = driver.FindElements(By.XPath("//div[@id='lwDataGrid']/table/tbody/tr[1]/td")).Count - 1;
  334. System.Diagnostics.Debug.WriteLine(rowCount + ": This is the number of rows in the table");
  335. System.Diagnostics.Debug.WriteLine(colCount + ": This is the number of columns in the table");
  336.  
  337. using (StreamWriter sw = new StreamWriter(actualData2, false))
  338. {
  339. //Used for loop for number of rows
  340. for (int i = 1; i <= rowCount + 3; i++)
  341. {
  342. if (i == 2 | i == 3)
  343. {
  344. continue;
  345. }
  346.  
  347. string line = string.Empty;
  348. //Used for loop for number of columns
  349. for (int j = 2; j <= colCount + 1; j++)
  350. {
  351. //Prepared final xpath of specific cell as per values of i and j.
  352. String finalXpath = firstPart + i + secondPart + j + thirdPart;
  353. //Will retrieve value from located cell and print It.
  354. String tableData = driver.FindElement(By.XPath(finalXpath)).Text;
  355. tableData = tableData.Replace(",", "");
  356.  
  357. //Add double quotes to comma numbers
  358. if (j == colCount + 1)
  359. {
  360. //Do not include 1st (header) row
  361. line = line + string.Format(CultureInfo.CurrentCulture, "{0}", tableData);
  362. }
  363. else
  364. {
  365. line = line + string.Format(CultureInfo.CurrentCulture, "{0},", tableData);
  366. }
  367. }
  368. sw.WriteLine(line.ToString());
  369. //sw.WriteLine(line);
  370. }
  371. }
  372.  
  373. // Create the IEnumerable data sources.
  374. firstCSV = System.IO.File.ReadAllLines(actualData2);
  375. secondCSV = System.IO.File.ReadAllLines(expectedData2);
  376. count = 0;
  377.  
  378. // Create the query. Note that method syntax must be used here.
  379. szDifference =
  380. firstCSV.Except(secondCSV);
  381.  
  382. foreach (string szTest in szDifference)
  383. {
  384. count = count + 1;
  385. System.Diagnostics.Debug.WriteLine(szTest + " exist in firstCSV but not in secondCSV");
  386. }
  387.  
  388. if (count > 0)
  389. {
  390. Assert.Fail("The data does not match the expected outcome file!");
  391. }
  392. else
  393. {
  394. System.Diagnostics.Debug.WriteLine("Data is as expected");
  395. }
  396.  
  397.  
  398. //[* * * SPEND BY COST CENTRE * * *]
  399.  
  400. driver.SwitchTo().DefaultContent();
  401. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.LeftMenuFrame);
  402.  
  403. driver.FindElement(By.
  404. XPath("//*[contains(text(),'Spend by Cost Centre')]")).Click();
  405.  
  406. //Switch focus back to the main frame
  407. driver.SwitchTo().DefaultContent();
  408. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.MainBodyFrame);
  409.  
  410. Thread.Sleep(3000);
  411.  
  412. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.TableFrame);
  413.  
  414. //Wait for the "Measure" sub menu to be visible, then click
  415. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  416. XPath("//*[@id='lwDataGrid_Main_Header_Column1'][contains(text(),'CostCentre Description')]"))));
  417.  
  418. //Wait for the last cell in the table to be available
  419. wait30.Until(ExpectedConditions.ElementToBeClickable((By.
  420. XPath("//div[@id='lwDataGrid']/table/tbody/tr[last()]/td[last()]"))));
  421.  
  422. //Row and Column counts
  423. rowCount = driver.FindElements(By.XPath("//div[@id='lwDataGrid']/table/tbody/tr[*]")).Count - 3;
  424. colCount = driver.FindElements(By.XPath("//div[@id='lwDataGrid']/table/tbody/tr[1]/td")).Count - 1;
  425. System.Diagnostics.Debug.WriteLine(rowCount + ": This is the number of rows in the table");
  426. System.Diagnostics.Debug.WriteLine(colCount + ": This is the number of columns in the table");
  427.  
  428. using (StreamWriter sw = new StreamWriter(actualData3, false))
  429. {
  430. //Used for loop for number of rows
  431. for (int i = 1; i <= rowCount + 3; i++)
  432. {
  433. if (i == 2 | i == 3)
  434. {
  435. continue;
  436. }
  437.  
  438. string line = string.Empty;
  439. //Used for loop for number of columns
  440. for (int j = 2; j <= colCount + 1; j++)
  441. {
  442. //Prepared final xpath of specific cell as per values of i and j.
  443. String finalXpath = firstPart + i + secondPart + j + thirdPart;
  444. //Will retrieve value from located cell and print It.
  445. String tableData = driver.FindElement(By.XPath(finalXpath)).Text;
  446. tableData = tableData.Replace(",", "");
  447.  
  448. //Add double quotes to comma numbers
  449. if (j == colCount + 1)
  450. {
  451. //Do not include 1st (header) row
  452. line = line + string.Format(CultureInfo.CurrentCulture, "{0}", tableData);
  453. }
  454. else
  455. {
  456. line = line + string.Format(CultureInfo.CurrentCulture, "{0},", tableData);
  457. }
  458. }
  459. sw.WriteLine(line.ToString());
  460. //sw.WriteLine(line);
  461. }
  462. }
  463.  
  464. // Create the IEnumerable data sources.
  465. firstCSV = System.IO.File.ReadAllLines(actualData3);
  466. secondCSV = System.IO.File.ReadAllLines(expectedData3);
  467. count = 0;
  468.  
  469. // Create the query. Note that method syntax must be used here.
  470. szDifference =
  471. firstCSV.Except(secondCSV);
  472.  
  473. foreach (string szTest in szDifference)
  474. {
  475. count = count + 1;
  476. System.Diagnostics.Debug.WriteLine(szTest + " exist in firstCSV but not in secondCSV");
  477. }
  478.  
  479. if (count > 0)
  480. {
  481. Assert.Fail("The data does not match the expected outcome file!");
  482. }
  483. else
  484. {
  485. System.Diagnostics.Debug.WriteLine("Data is as expected");
  486. }
  487.  
  488. //[* * * SPEND BY DEPARTMENT * * *]
  489.  
  490. driver.SwitchTo().DefaultContent();
  491. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.LeftMenuFrame);
  492.  
  493. driver.FindElement(By.
  494. XPath("//*[contains(text(),'Spend by Department')]")).Click();
  495.  
  496. //Switch focus back to the main frame
  497. driver.SwitchTo().DefaultContent();
  498. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.MainBodyFrame);
  499.  
  500. Thread.Sleep(3000);
  501.  
  502. driver.SwitchTo().Frame(Tests.LineDetailAnalysis.TableFrame);
  503.  
  504. //Wait for the "Measure" sub menu to be visible, then click
  505. wait30.Until(ExpectedConditions.ElementIsVisible((By.
  506. XPath("//*[@id='lwDataGrid_Main_Header_Column1'][contains(text(),'Department Description')]"))));
  507.  
  508. //Wait for the last cell in the table to be available
  509. wait30.Until(ExpectedConditions.ElementToBeClickable((By.
  510. XPath("//div[@id='lwDataGrid']/table/tbody/tr[last()]/td[last()]"))));
  511.  
  512. //Row and Column counts
  513. rowCount = driver.FindElements(By.XPath("//div[@id='lwDataGrid']/table/tbody/tr[*]")).Count - 3;
  514. colCount = driver.FindElements(By.XPath("//div[@id='lwDataGrid']/table/tbody/tr[1]/td")).Count - 1;
  515. System.Diagnostics.Debug.WriteLine(rowCount + ": This is the number of rows in the table");
  516. System.Diagnostics.Debug.WriteLine(colCount + ": This is the number of columns in the table");
  517.  
  518. using (StreamWriter sw = new StreamWriter(actualData4, false))
  519. {
  520. //Used for loop for number of rows
  521. for (int i = 1; i <= 100 + 3; i++)
  522. {
  523. if (i == 2 | i == 3)
  524. {
  525. continue;
  526. }
  527.  
  528. string line = string.Empty;
  529. //Used for loop for number of columns
  530. for (int j = 2; j <= colCount + 1; j++)
  531. {
  532. //Prepared final xpath of specific cell as per values of i and j.
  533. String finalXpath = firstPart + i + secondPart + j + thirdPart;
  534. //Will retrieve value from located cell and print It.
  535. String tableData = driver.FindElement(By.XPath(finalXpath)).Text;
  536. tableData = tableData.Replace(",", "");
  537.  
  538. //Add double quotes to comma numbers
  539. if (j == colCount + 1)
  540. {
  541. //Do not include 1st (header) row
  542. line = line + string.Format(CultureInfo.CurrentCulture, "{0}", tableData);
  543. }
  544. else
  545. {
  546. line = line + string.Format(CultureInfo.CurrentCulture, "{0},", tableData);
  547. }
  548. }
  549. sw.WriteLine(line.ToString());
  550. //sw.WriteLine(line);
  551. }
  552. }
  553.  
  554. // Create the IEnumerable data sources.
  555. firstCSV = System.IO.File.ReadAllLines(actualData4);
  556. secondCSV = System.IO.File.ReadAllLines(expectedData4);
  557. count = 0;
  558.  
  559. // Create the query. Note that method syntax must be used here.
  560. szDifference =
  561. firstCSV.Except(secondCSV);
  562.  
  563. foreach (string szTest in szDifference)
  564. {
  565. count = count + 1;
  566. System.Diagnostics.Debug.WriteLine(szTest + " exist in firstCSV but not in secondCSV");
  567. }
  568.  
  569. if (count > 0)
  570. {
  571. Assert.Fail("The data does not match the expected outcome file!");
  572. }
  573. else
  574. {
  575. System.Diagnostics.Debug.WriteLine("Data is as expected");
  576. }
  577.  
  578. }
  579.  
  580.  
  581. public Boolean IsAlertPresent()
  582. {
  583. try
  584. {
  585. driver.SwitchTo().Alert();
  586. return true;
  587. } // try
  588.  
  589. catch (NoAlertPresentException)
  590. {
  591. return false;
  592. //throw;
  593. } // catch
  594. }
  595.  
  596. [TestCleanup()]
  597. protected virtual void Dispose(bool disposing)
  598. {
  599. if (disposing)
  600. {
  601. //dispose managed resources
  602. driver.Close();
  603. binary.Dispose();
  604. //sr.Dispose();
  605.  
  606. }
  607. //free native resources
  608. }
  609.  
  610. public void Dispose()
  611. {
  612. Dispose(true);
  613. GC.SuppressFinalize(this);
  614. }
  615. }
  616. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement