Skip to content

Commit eb4d462

Browse files
RathoreRathore
authored andcommitted
Added grid code
1 parent d080e00 commit eb4d462

17 files changed

Lines changed: 645 additions & 77 deletions

SeleniumWebdriver/App.config

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<add key="Browser" value="Chrome" />
1414
<add key="Username" value="rahul@bugzila.com" />
1515
<add key="Password" value="welcome" />
16-
<add key="Website" value="http://192.168.1.11:5001/" />
16+
<add key="Website" value="https://www.google.com/" />
1717
<add key="PageLoadTimeout" value="40" />
1818
<add key="ElementLoadTimeout" value="2" />
1919
</appSettings>
@@ -55,10 +55,7 @@
5555
<appender-ref ref="RollingFileAppender" />
5656
</root>
5757
</log4net>
58-
<specFlow>
59-
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --><unitTestProvider name="MsTest" />
60-
61-
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --></specFlow>
58+
6259
<runtime>
6360
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
6461
<dependentAssembly>
@@ -67,4 +64,6 @@
6764
</dependentAssembly>
6865
</assemblyBinding>
6966
</runtime>
70-
</configuration>
67+
<specFlow>
68+
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
69+
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --><unitTestProvider name="MsTest" /><!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --></specFlow></configuration>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using OpenQA.Selenium;
7+
using SeleniumWebdriver.Settings;
8+
9+
namespace SeleniumWebdriver.ComponentHelper
10+
{
11+
public class GridHelper
12+
{
13+
internal static string GetTableXpath(string locator, int row, int col)
14+
{
15+
return $"{locator}//tbody//tr[{row}]//td[{col}]";
16+
}
17+
18+
private static IWebElement GetGridElement(string locator, int row, int col)
19+
{
20+
var xpath = GetTableXpath(locator, row, col);
21+
if (GenericHelper.IsElemetPresent(By.XPath(xpath + "//a")))
22+
{
23+
return ObjectRepository.Driver.FindElement(By.XPath(xpath + "//a"));
24+
}
25+
else if (GenericHelper.IsElemetPresent(By.XPath(xpath + "//input")))
26+
{
27+
return ObjectRepository.Driver.FindElement(By.XPath(xpath + "//input"));
28+
}
29+
else
30+
{
31+
return ObjectRepository.Driver.FindElement(By.XPath(xpath));
32+
}
33+
}
34+
/// <summary>
35+
/// Get the column value
36+
/// </summary>
37+
/// <param name="locator"> grid locator </param>
38+
/// <param name="row"> row index </param>
39+
/// <param name="col">column index </param>
40+
/// <returns></returns>
41+
public static string GetColumnValue(string @locator,int @row,int @col)
42+
{
43+
/* string tableXpath = GetTableXpath(locator, row, col);
44+
string value = string.Empty;
45+
46+
47+
if (GenericHelper.IsElemetPresent(By.XPath(tableXpath)))
48+
{
49+
value = ObjectRepository.Driver.FindElement(By.XPath(tableXpath)).Text;
50+
}
51+
52+
return value;*/
53+
return GetGridElement(locator, row, col).Text;
54+
}
55+
56+
public static IList<string> GetAllValues(string @locator)
57+
{
58+
List<string> list = new List<string>();
59+
60+
var row = 1;
61+
var col = 1;
62+
63+
while (GenericHelper.IsElemetPresent(By.XPath(GetTableXpath(locator,row,col))))
64+
{
65+
while (GenericHelper.IsElemetPresent(By.XPath(GetTableXpath(locator, row, col))))
66+
{
67+
list.Add(ObjectRepository.Driver.FindElement(By.XPath(GetTableXpath(locator, row, col))).Text);
68+
col++;
69+
}
70+
row++;
71+
col = 1;
72+
}
73+
return list;
74+
75+
}
76+
77+
public static IList<string> GetValues(string @locator, int column)
78+
{
79+
List<string> list = new List<string>();
80+
81+
var row = 1;
82+
83+
while (GenericHelper.IsElemetPresent(By.XPath(GetTableXpath(locator, row, column))))
84+
{
85+
list.Add(ObjectRepository.Driver.FindElement(By.XPath(GetTableXpath(locator, row, column))).Text);
86+
row++;
87+
}
88+
return list;
89+
}
90+
91+
public static void ClickButtonInGrid(string @locator, int @row, int @col)
92+
{
93+
GetGridElement(locator,row,col).Click();
94+
}
95+
96+
}
97+
}

SeleniumWebdriver/FeatureFiles/Arguments.feature.cs

Lines changed: 48 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)