├── .gitignore
├── README.md
├── SeleniumWebdriver.sln
└── SeleniumWebdriver
├── App.config
├── App2.config
├── BaseClasses
├── BaseClass.cs
└── PageBase.cs
├── ComponentHelper
├── AssertHelper.cs
├── BrowserHelper.cs
├── ButtonHelper.cs
├── CheckBoxHelper.cs
├── ComboBoxHelper.cs
├── CustomWebElement.cs
├── FileHelper.cs
├── GenericHelper.cs
├── GridHelper.cs
├── JavaScriptExecutor.cs
├── JavaScriptPopHelper.cs
├── LinkHelper.cs
├── Log4NetHelper.cs
├── MenuHelper.cs
├── NavigationHelper.cs
├── RadioButtonHelper.cs
├── TextBoxHelper.cs
└── WindowHelper.cs
├── Configuration
├── AppConfigReader.cs
└── BrowserType.cs
├── CustomException
├── NoKeywordFoundException.cs
└── NoSutiableDriverFound.cs
├── DataDriven
├── Script
│ └── TestCreateBug.cs
└── TestDataFiles
│ ├── CreateData.csv
│ ├── ExcelData.xlsx
│ └── TestData.xml
├── ExcelReader
├── DataFiles
│ ├── KeywordOne.xlsx
│ └── KeywordTwo.xlsx
├── ExcelReader.cs
└── TestExcelData.cs
├── FeatureFiles
├── Arguments.feature
├── Arguments.feature.cs
├── Hooks.feature
├── Hooks.feature.cs
├── TestFeature.feature
├── TestFeature.feature.cs
├── TestFeature2.feature
└── TestFeature2.feature.cs
├── GeneralHook
└── GeneralHook.cs
├── Interfaces
└── IConfig.cs
├── Keyword
└── DataEngine.cs
├── NLog.config
├── NLog.xsd
├── OrderedTest.orderedtest
├── PageObject
├── BugDetail.cs
├── EnterBug.cs
├── HomePage.cs
└── LoginPage.cs
├── Properties
└── AssemblyInfo.cs
├── Reports
└── Reporter.cs
├── Resources
├── ExcelData.xlsx
├── FileUpload.exe
├── IEDriverServer.exe
├── SampleFile.txt
├── chromedriver.exe
└── phantomjs.exe
├── SeleniumWebdriver.csproj
├── Settings
├── AppConfigKeys.cs
└── ObjectRepository.cs
├── StepDefinition
├── Arguments.cs
├── Hooks.cs
├── TestFeature.cs
└── TestFeature2.cs
├── TestScript
├── AngularScript
│ └── TestProtractor.cs
├── AutoSuggest
│ └── TestAutoSuggest.cs
├── BrowserActions
│ └── TestBrowserActions.cs
├── Button
│ └── HandleButton.cs
├── CheckBox
│ └── TestCheckBox.cs
├── DefaultWait
│ └── HandleDefaultWait.cs
├── EmptyDataTable
│ ├── EmptyDataTable.feature
│ ├── EmptyDataTable.feature.cs
│ └── EmptyDataTableStepDfn.cs
├── FileUpload
│ └── TestFileUploadAction.cs
├── FindElements
│ └── HandleElements.cs
├── Form
│ └── TestSubmitForm.cs
├── Grid
│ └── TestWebTable.cs
├── HandleDropDown
│ └── DropDownList.cs
├── HyperLink
│ └── TestHyperLink.cs
├── JavaScript
│ └── TestJavaScriptClass.cs
├── Keyword
│ └── TestKeywordDriven.cs
├── Log4Net
│ └── TestLogger.cs
├── MouseAction
│ └── TestMouseAction.cs
├── MultipleBrowser
│ └── TestMultipleBrowserWindow.cs
├── NLogScript
│ └── NLogExample.cs
├── NgWebDriverTest
│ └── TestAngularApp.cs
├── PageNavigation
│ └── TestPageNavigation.cs
├── PageObject
│ └── TestPageObject.cs
├── PhantomJS
│ └── TestPhantomJS.cs
├── Popups
│ └── TestPopups.cs
├── Question
│ ├── Frameset
│ │ └── TestFrameSet.cs
│ ├── GetExecutionPath
│ │ └── TestGetExecutionPath.cs
│ ├── MinMax.cs
│ ├── SubString.cs
│ ├── TestAppConfig.cs
│ ├── TestFileDownload.cs
│ ├── TestGetDataFromPage.cs
│ ├── TestKendoUI.cs
│ └── TestReadExcelFile.cs
├── RadAutoCompleteBox
│ └── TC-AutoSuggestComboBox.cs
├── RadioButton
│ └── HandleRadioButton.cs
├── ScreenShot
│ └── TakeScreenShots.cs
├── SikuliScript
│ └── TestSikuliScript.cs
├── StringToByClass
│ └── TestPage.cs
├── TestClassContext
│ └── TestClassContext.cs
├── TextBox
│ └── TestTextBox.cs
├── WebDriverWaiter
│ └── TestWebDeriverWait.cs
└── WebElement
│ └── TestWebElement.cs
├── UnitTest1.cs
├── extent-config.xml
├── license
├── packages.config
└── phantomjs-license.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.pch
68 | *.pdb
69 | *.pgc
70 | *.pgd
71 | *.rsp
72 | *.sbr
73 | *.tlb
74 | *.tli
75 | *.tlh
76 | *.tmp
77 | *.tmp_proj
78 | *.log
79 | *.vspscc
80 | *.vssscc
81 | .builds
82 | *.pidb
83 | *.svclog
84 | *.scc
85 |
86 | # Chutzpah Test files
87 | _Chutzpah*
88 |
89 | # Visual C++ cache files
90 | ipch/
91 | *.aps
92 | *.ncb
93 | *.opendb
94 | *.opensdf
95 | *.sdf
96 | *.cachefile
97 | *.VC.db
98 | *.VC.VC.opendb
99 |
100 | # Visual Studio profiler
101 | *.psess
102 | *.vsp
103 | *.vspx
104 | *.sap
105 |
106 | # Visual Studio Trace Files
107 | *.e2e
108 |
109 | # TFS 2012 Local Workspace
110 | $tf/
111 |
112 | # Guidance Automation Toolkit
113 | *.gpState
114 |
115 | # ReSharper is a .NET coding add-in
116 | _ReSharper*/
117 | *.[Rr]e[Ss]harper
118 | *.DotSettings.user
119 |
120 | # JustCode is a .NET coding add-in
121 | .JustCode
122 |
123 | # TeamCity is a build add-in
124 | _TeamCity*
125 |
126 | # DotCover is a Code Coverage Tool
127 | *.dotCover
128 |
129 | # AxoCover is a Code Coverage Tool
130 | .axoCover/*
131 | !.axoCover/settings.json
132 |
133 | # Visual Studio code coverage results
134 | *.coverage
135 | *.coveragexml
136 |
137 | # NCrunch
138 | _NCrunch_*
139 | .*crunch*.local.xml
140 | nCrunchTemp_*
141 |
142 | # MightyMoose
143 | *.mm.*
144 | AutoTest.Net/
145 |
146 | # Web workbench (sass)
147 | .sass-cache/
148 |
149 | # Installshield output folder
150 | [Ee]xpress/
151 |
152 | # DocProject is a documentation generator add-in
153 | DocProject/buildhelp/
154 | DocProject/Help/*.HxT
155 | DocProject/Help/*.HxC
156 | DocProject/Help/*.hhc
157 | DocProject/Help/*.hhk
158 | DocProject/Help/*.hhp
159 | DocProject/Help/Html2
160 | DocProject/Help/html
161 |
162 | # Click-Once directory
163 | publish/
164 |
165 | # Publish Web Output
166 | *.[Pp]ublish.xml
167 | *.azurePubxml
168 | # Note: Comment the next line if you want to checkin your web deploy settings,
169 | # but database connection strings (with potential passwords) will be unencrypted
170 | *.pubxml
171 | *.publishproj
172 |
173 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
174 | # checkin your Azure Web App publish settings, but sensitive information contained
175 | # in these scripts will be unencrypted
176 | PublishScripts/
177 |
178 | # NuGet Packages
179 | *.nupkg
180 | # The packages folder can be ignored because of Package Restore
181 | **/[Pp]ackages/*
182 | # except build/, which is used as an MSBuild target.
183 | !**/[Pp]ackages/build/
184 | # Uncomment if necessary however generally it will be regenerated when needed
185 | #!**/[Pp]ackages/repositories.config
186 | # NuGet v3's project.json files produces more ignorable files
187 | *.nuget.props
188 | *.nuget.targets
189 |
190 | # Microsoft Azure Build Output
191 | csx/
192 | *.build.csdef
193 |
194 | # Microsoft Azure Emulator
195 | ecf/
196 | rcf/
197 |
198 | # Windows Store app package directories and files
199 | AppPackages/
200 | BundleArtifacts/
201 | Package.StoreAssociation.xml
202 | _pkginfo.txt
203 | *.appx
204 |
205 | # Visual Studio cache files
206 | # files ending in .cache can be ignored
207 | *.[Cc]ache
208 | # but keep track of directories ending in .cache
209 | !*.[Cc]ache/
210 |
211 | # Others
212 | ClientBin/
213 | ~$*
214 | *~
215 | *.dbmdl
216 | *.dbproj.schemaview
217 | *.jfm
218 | *.pfx
219 | *.publishsettings
220 | orleans.codegen.cs
221 |
222 | # Including strong name files can present a security risk
223 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
224 | #*.snk
225 |
226 | # Since there are multiple workflows, uncomment next line to ignore bower_components
227 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
228 | #bower_components/
229 |
230 | # RIA/Silverlight projects
231 | Generated_Code/
232 |
233 | # Backup & report files from converting an old project file
234 | # to a newer Visual Studio version. Backup files are not needed,
235 | # because we have git ;-)
236 | _UpgradeReport_Files/
237 | Backup*/
238 | UpgradeLog*.XML
239 | UpgradeLog*.htm
240 |
241 | # SQL Server files
242 | *.mdf
243 | *.ldf
244 | *.ndf
245 |
246 | # Business Intelligence projects
247 | *.rdl.data
248 | *.bim.layout
249 | *.bim_*.settings
250 |
251 | # Microsoft Fakes
252 | FakesAssemblies/
253 |
254 | # GhostDoc plugin setting file
255 | *.GhostDoc.xml
256 |
257 | # Node.js Tools for Visual Studio
258 | .ntvs_analysis.dat
259 | node_modules/
260 |
261 | # TypeScript v1 declaration files
262 | typings/
263 |
264 | # Visual Studio 6 build log
265 | *.plg
266 |
267 | # Visual Studio 6 workspace options file
268 | *.opt
269 |
270 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
271 | *.vbw
272 |
273 | # Visual Studio LightSwitch build output
274 | **/*.HTMLClient/GeneratedArtifacts
275 | **/*.DesktopClient/GeneratedArtifacts
276 | **/*.DesktopClient/ModelManifest.xml
277 | **/*.Server/GeneratedArtifacts
278 | **/*.Server/ModelManifest.xml
279 | _Pvt_Extensions
280 |
281 | # Paket dependency manager
282 | .paket/paket.exe
283 | paket-files/
284 |
285 | # FAKE - F# Make
286 | .fake/
287 |
288 | # JetBrains Rider
289 | .idea/
290 | *.sln.iml
291 |
292 | # CodeRush
293 | .cr/
294 |
295 | # Python Tools for Visual Studio (PTVS)
296 | __pycache__/
297 | *.pyc
298 |
299 | # Cake - Uncomment if you are using it
300 | # tools/**
301 | # !tools/packages.config
302 |
303 | # Tabs Studio
304 | *.tss
305 |
306 | # Telerik's JustMock configuration file
307 | *.jmconfig
308 |
309 | # BizTalk build output
310 | *.btp.cs
311 | *.btm.cs
312 | *.odx.cs
313 | *.xsd.cs
314 |
315 | # OpenCover UI analysis results
316 | OpenCover/
317 |
318 | # Azure Stream Analytics local run output
319 | ASALocalRun/
320 |
321 | # MSBuild Binary and Structured Log
322 | *.binlog
323 |
324 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # BDD with Selenium Webdriver and Specflow using C#
3 |
4 | Selenium WebDriver using CSharp as language binding
5 |
6 | ## Course Link (Discount Coupon)
7 |
8 | https://www.udemy.com/course/bdd-with-selenium-webdriver-and-speckflow-using-c/?couponCode=21PERCENTOFF
9 |
10 | ## YouTube Playlist
11 |
12 | * Selenium Webdriver with C# https://www.youtube.com/playlist?list=PLlsKgYi2Lw724ozNSmdSrrtU8q6a1m3ob
13 |
14 | * Rest API Testing using RestSharp in C# https://www.youtube.com/playlist?list=PLlsKgYi2Lw73ox9LF5VfYMrA1eo9e7rIq
15 |
16 | * API Testing Using C# Http Client https://www.youtube.com/playlist?list=PLlsKgYi2Lw722PMqESdivKJQgRtJAdbzn
17 |
--------------------------------------------------------------------------------
/SeleniumWebdriver.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SeleniumWebdriver", "SeleniumWebdriver\SeleniumWebdriver.csproj", "{84CF58CE-CA65-40E9-9041-625D8B529170}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {84CF58CE-CA65-40E9-9041-625D8B529170}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {84CF58CE-CA65-40E9-9041-625D8B529170}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {84CF58CE-CA65-40E9-9041-625D8B529170}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {84CF58CE-CA65-40E9-9041-625D8B529170}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/App.config:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/App2.config:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/BaseClasses/BaseClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using OpenQA.Selenium.Chrome;
10 | using OpenQA.Selenium.Firefox;
11 | using OpenQA.Selenium.IE;
12 | using OpenQA.Selenium.PhantomJS;
13 | using OpenQA.Selenium.Remote;
14 | using SeleniumWebdriver.ComponentHelper;
15 | using SeleniumWebdriver.Configuration;
16 | using SeleniumWebdriver.CustomException;
17 | using SeleniumWebdriver.Reports;
18 | using SeleniumWebdriver.Settings;
19 | using TechTalk.SpecFlow;
20 |
21 | namespace SeleniumWebdriver.BaseClasses
22 | {
23 | [TestClass]
24 |
25 | public class BaseClass
26 | {
27 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof (BaseClass));
28 | private static FirefoxProfile GetFirefoxptions()
29 | {
30 | FirefoxProfile profile = new FirefoxProfile();
31 | FirefoxProfileManager manager = new FirefoxProfileManager();
32 | //profile = manager.GetProfile("default");
33 | Logger.Info(" Using Firefox Profile ");
34 | return profile;
35 | }
36 |
37 | private static FirefoxOptions GetOptions()
38 | {
39 | FirefoxProfileManager manager = new FirefoxProfileManager();
40 |
41 | FirefoxOptions options = new FirefoxOptions()
42 | {
43 | Profile = manager.GetProfile("default"),
44 | AcceptInsecureCertificates = true,
45 |
46 | };
47 | return options;
48 | }
49 | private static ChromeOptions GetChromeOptions()
50 | {
51 | ChromeOptions option = new ChromeOptions();
52 | option.AddArgument("start-maximized");
53 | //option.AddArgument("--headless");
54 | //option.AddExtension(@"C:\Users\rahul.rathore\Desktop\Cucumber\extension_3_0_12.crx");
55 | Logger.Info(" Using Chrome Options ");
56 | return option;
57 | }
58 |
59 | private static InternetExplorerOptions GetIEOptions()
60 | {
61 | InternetExplorerOptions options = new InternetExplorerOptions();
62 | options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
63 | options.EnsureCleanSession = true;
64 | options.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Bottom;
65 | Logger.Info(" Using Internet Explorer Options ");
66 | return options;
67 | }
68 |
69 |
70 | private static FirefoxDriver GetFirefoxDriver()
71 | {
72 | FirefoxOptions options = new FirefoxOptions();
73 | FirefoxDriver driver = new FirefoxDriver(GetFirefoxptions());
74 | return driver;
75 | }
76 |
77 | private static ChromeDriver GetChromeDriver()
78 | {
79 | ChromeDriver driver = new ChromeDriver(GetChromeOptions());
80 | return driver;
81 | }
82 |
83 | private static InternetExplorerDriver GetIEDriver()
84 | {
85 | InternetExplorerDriver driver = new InternetExplorerDriver(GetIEOptions());
86 | return driver;
87 | }
88 |
89 | private static PhantomJSDriver GetPhantomJsDriver()
90 | {
91 | PhantomJSDriver driver = new PhantomJSDriver(GetPhantomJsDrvierService());
92 |
93 | return driver;
94 | }
95 |
96 | private static PhantomJSOptions GetPhantomJsptions()
97 | {
98 | PhantomJSOptions option = new PhantomJSOptions();
99 | option.AddAdditionalCapability("handlesAlerts", true);
100 | Logger.Info(" Using PhantomJS Options ");
101 | return option;
102 | }
103 |
104 | private static PhantomJSDriverService GetPhantomJsDrvierService()
105 | {
106 | PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
107 | service.LogFile = "TestPhantomJS.log";
108 | service.HideCommandPromptWindow = false;
109 | service.LoadImages = true;
110 | Logger.Info(" Using PhantomJS Driver Service ");
111 | return service;
112 | }
113 |
114 |
115 | [AssemblyInitialize]
116 | //[BeforeFeature()]
117 | public static void InitWebdriver(TestContext tc)
118 | {
119 | ObjectRepository.Config = new AppConfigReader();
120 | Reporter.GetReportManager();
121 | Reporter.AddTestCaseMetadataToHtmlReport(tc);
122 | switch (ObjectRepository.Config.GetBrowser())
123 | {
124 | case BrowserType.Firefox:
125 | ObjectRepository.Driver = GetFirefoxDriver();
126 | Logger.Info(" Using Firefox Driver ");
127 |
128 | break;
129 |
130 | case BrowserType.Chrome:
131 | ObjectRepository.Driver = GetChromeDriver();
132 | Logger.Info(" Using Chrome Driver ");
133 | break;
134 |
135 | case BrowserType.IExplorer:
136 | ObjectRepository.Driver = GetIEDriver();
137 | Logger.Info(" Using Internet Explorer Driver ");
138 | break;
139 |
140 | case BrowserType.PhantomJs:
141 | ObjectRepository.Driver = GetPhantomJsDriver();
142 | Logger.Info(" Using PhantomJs Driver ");
143 | break;
144 |
145 | default:
146 | throw new NoSutiableDriverFound("Driver Not Found : " + ObjectRepository.Config.GetBrowser().ToString());
147 | }
148 | ObjectRepository.Driver.Manage()
149 | .Timeouts().PageLoad = TimeSpan.FromSeconds(ObjectRepository.Config.GetPageLoadTimeOut());
150 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(ObjectRepository.Config.GetElementLoadTimeOut());
151 | BrowserHelper.BrowserMaximize();
152 | }
153 |
154 |
155 | [AssemblyCleanup]
156 | //[AfterScenario()]
157 | public static void TearDown()
158 | {
159 | if (ObjectRepository.Driver != null)
160 | {
161 | ObjectRepository.Driver.Close();
162 | ObjectRepository.Driver.Quit();
163 | }
164 | Logger.Info(" Stopping the Driver ");
165 | }
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/BaseClasses/PageBase.cs:
--------------------------------------------------------------------------------
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 SeleniumExtras.PageObjects;
8 | using SeleniumWebdriver.ComponentHelper;
9 |
10 | namespace SeleniumWebdriver.BaseClasses
11 | {
12 | public class PageBase
13 | {
14 | private IWebDriver driver;
15 |
16 | [FindsBy(How = How.LinkText,Using = "Home")]
17 | private IWebElement HomeLink;
18 | //private IWebElement HomeLink => driver.FindElement(By.LinkText("Home"));
19 |
20 | public PageBase(IWebDriver _driver)
21 | {
22 | PageFactory.InitElements(_driver,this);
23 | this.driver = _driver;
24 | }
25 |
26 | public void Logout()
27 | {
28 | if (GenericHelper.IsElemetPresent(By.XPath("//div[@id='header']/ul[1]/li[11]/a")))
29 | {
30 | ButtonHelper.ClickButton(By.XPath("//div[@id='header']/ul[1]/li[11]/a"));
31 | }
32 | GenericHelper.WaitForWebElementInPage(By.Id("welcome"), TimeSpan.FromSeconds(30));
33 |
34 | }
35 |
36 | protected void NaviGateToHomePage()
37 | {
38 | HomeLink.Click();
39 | }
40 |
41 | public string Title
42 | {
43 | get { return driver.Title; }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/AssertHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 |
8 | namespace SeleniumWebdriver.ComponentHelper
9 | {
10 | public class AssertHelper
11 | {
12 | public static void AreEqual(string expected, string actual)
13 | {
14 | try
15 | {
16 | Assert.AreEqual(expected,actual);
17 | }
18 | catch (Exception)
19 | {
20 | //ignore
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/BrowserHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using log4net;
9 | using OpenQA.Selenium;
10 | using SeleniumWebdriver.BaseClasses;
11 | using SeleniumWebdriver.Settings;
12 |
13 | namespace SeleniumWebdriver.ComponentHelper
14 | {
15 | public class BrowserHelper
16 | {
17 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof(BrowserHelper));
18 | public static void BrowserMaximize()
19 | {
20 | ObjectRepository.Driver.Manage().Window.Maximize();
21 | Logger.Info(" Browser Maximize ");
22 | }
23 |
24 | public static void GoBack()
25 | {
26 | ObjectRepository.Driver.Navigate().Back();
27 |
28 | }
29 |
30 | public static void Forward()
31 | {
32 | ObjectRepository.Driver.Navigate().Forward();
33 | }
34 |
35 | public static void RefreshPage()
36 | {
37 | ObjectRepository.Driver.Navigate().Refresh();
38 | }
39 |
40 | public static void SwitchToWindow(int index = 0)
41 | {
42 | Thread.Sleep(1000);
43 | ReadOnlyCollection windows = ObjectRepository.Driver.WindowHandles;
44 |
45 | if ((windows.Count - 1) < index)
46 | {
47 | throw new NoSuchWindowException("Invalid Browser Window Index" + index);
48 | }
49 |
50 |
51 | ObjectRepository.Driver.SwitchTo().Window(windows[index]);
52 | Thread.Sleep(1000);
53 | BrowserMaximize();
54 |
55 | }
56 |
57 |
58 | public static void SwitchToParent()
59 | {
60 | var windowids = ObjectRepository.Driver.WindowHandles;
61 |
62 |
63 | for (int i = windowids.Count - 1; i > 0;)
64 | {
65 | ObjectRepository.Driver.Close();
66 | i = i - 1;
67 | Thread.Sleep(2000);
68 | ObjectRepository.Driver.SwitchTo().Window(windowids[i]);
69 | }
70 | ObjectRepository.Driver.SwitchTo().Window(windowids[0]);
71 |
72 | }
73 |
74 | public static void SwitchToFrame(By locatot)
75 | {
76 | ObjectRepository.Driver.SwitchTo().Frame(ObjectRepository.Driver.FindElement(locatot));
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/ButtonHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using OpenQA.Selenium;
8 |
9 | namespace SeleniumWebdriver.ComponentHelper
10 | {
11 | public class ButtonHelper
12 | {
13 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof (ButtonHelper));
14 | private static IWebElement _element;
15 |
16 | public static void ClickButton(By locator)
17 | {
18 | _element = GenericHelper.GetElement(locator);
19 | _element.Click();
20 | Logger.Info(" Button Click @ " + locator);
21 | }
22 |
23 | public static bool IsButtonEnabled(By locator)
24 | {
25 | _element = GenericHelper.GetElement(locator);
26 | Logger.Info(" Checking Is Button Enabled ");
27 | return _element.Enabled;
28 | }
29 |
30 | public static string GetButtonText(By locator)
31 | {
32 | _element = GenericHelper.GetElement(locator);
33 | if (_element.GetAttribute("value") == null)
34 | return string.Empty;
35 | return _element.GetAttribute("value");
36 | }
37 |
38 | public static void Logout()
39 | {
40 | if (GenericHelper.IsElemetPresent(By.XPath("//div[@id='header']/ul[1]/li[11]/a")))
41 | {
42 | ClickButton(By.XPath("//div[@id='header']/ul[1]/li[11]/a"));
43 | GenericHelper.WaitForWebElementInPage(By.Id("welcome"), TimeSpan.FromSeconds(30));
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/CheckBoxHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using OpenQA.Selenium;
8 |
9 | namespace SeleniumWebdriver.ComponentHelper
10 | {
11 | public class CheckBoxHelper
12 | {
13 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof (CheckBoxHelper));
14 | private static IWebElement element;
15 |
16 | public static void CheckedCheckBox(By locator)
17 | {
18 | element = GenericHelper.GetElement(locator);
19 | element.Click();
20 | Logger.Info(" Click on Check box : " + locator);
21 | }
22 |
23 | public static bool IsCheckBoxChecked(By locator)
24 | {
25 | element = GenericHelper.GetElement(locator);
26 | string flag = element.GetAttribute("checked");
27 | Logger.Info(" Is CheckBox Checked : " + locator);
28 | if (flag == null)
29 | return false;
30 | else
31 | return flag.Equals("true") || flag.Equals("checked");
32 | }
33 | }
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/ComboBoxHelper.cs:
--------------------------------------------------------------------------------
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 OpenQA.Selenium.Support.UI;
8 | using SeleniumWebdriver.Settings;
9 | using ExpectedConditions = SeleniumExtras.WaitHelpers.ExpectedConditions;
10 |
11 | namespace SeleniumWebdriver.ComponentHelper
12 | {
13 | public class ComboBoxHelper
14 | {
15 | private static SelectElement select;
16 | private static WebDriverWait GetWebDriverWait(IWebDriver driver,TimeSpan timeout)
17 | {
18 | WebDriverWait wait = new WebDriverWait(driver,timeout)
19 | {
20 | PollingInterval = TimeSpan.FromMilliseconds(250)
21 | };
22 | wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
23 | return wait;
24 | }
25 |
26 | public static void SelectElementWitWait(By locator, int index)
27 | {
28 | WebDriverWait wait = GetWebDriverWait(ObjectRepository.Driver, TimeSpan.FromSeconds(60));
29 | IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(locator));
30 | select = new SelectElement(element);
31 | select.SelectByIndex(index);
32 | }
33 |
34 | public static void SelectElement(By locator, int index)
35 | {
36 | select = new SelectElement(GenericHelper.GetElement(locator));
37 | select.SelectByIndex(index);
38 | }
39 |
40 | public static void SelectElement(By locator, string visibletext)
41 | {
42 | select = new SelectElement(GenericHelper.GetElement(locator));
43 | select.SelectByText(visibletext);
44 | }
45 |
46 | public static void SelectElementByValue(By locator, string valueTexts)
47 | {
48 | select = new SelectElement(GenericHelper.GetElement(locator));
49 | select.SelectByValue(valueTexts);
50 | }
51 |
52 | public static IList GetAllItem(By locator)
53 | {
54 | select = new SelectElement(GenericHelper.GetElement(locator));
55 | return select.Options.Select((x) => x.Text).ToList();
56 | }
57 |
58 | public static void SelectElement(IWebElement element, string visibletext)
59 | {
60 | select = new SelectElement(element);
61 | select.SelectByValue(visibletext);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/CustomWebElement.cs:
--------------------------------------------------------------------------------
1 | using OpenQA.Selenium;
2 | using OpenQA.Selenium.Firefox;
3 | using OpenQA.Selenium.Remote;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Collections.ObjectModel;
7 | using System.Drawing;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace SeleniumWebdriver.ComponentHelper
13 | {
14 | public class CustomWebElement : RemoteWebElement
15 | {
16 | private string ElementName = "Default Name";
17 | public string Name
18 | {
19 | set
20 | {
21 | ElementName = value;
22 | }
23 | }
24 |
25 | public CustomWebElement(RemoteWebDriver parentDriver, string id) : base(parentDriver,id)
26 | {
27 |
28 | }
29 |
30 | public override string ToString()
31 | {
32 | return ElementName;
33 | }
34 |
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/FileHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace SeleniumWebdriver.ComponentHelper
9 | {
10 | class FileHelper
11 | {
12 | public static String SaveScreenShot(String absolutePath, String fileName)
13 | {
14 | var dir = Directory.Exists(absolutePath);
15 | if (!dir)
16 | {
17 | Directory.CreateDirectory(absolutePath);
18 | }
19 |
20 | return absolutePath;
21 |
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/GenericHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing.Imaging;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Runtime.InteropServices;
7 | using System.Text;
8 | using System.Threading;
9 | using System.Threading.Tasks;
10 | using log4net;
11 | using OpenQA.Selenium;
12 | using OpenQA.Selenium.Support.Extensions;
13 | using OpenQA.Selenium.Support.UI;
14 | using SeleniumWebdriver.Settings;
15 | using ExpectedConditions = SeleniumExtras.WaitHelpers.ExpectedConditions;
16 |
17 | namespace SeleniumWebdriver.ComponentHelper
18 | {
19 | public class GenericHelper
20 | {
21 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof (GenericHelper));
22 | private static Func WaitForWebElementFunc(By locator)
23 | {
24 | return ((x) =>
25 | {
26 | if (x.FindElements(locator).Count == 1)
27 | return true;
28 | Logger.Info(" Waiting for Element : " + locator);
29 | return false;
30 | });
31 | }
32 |
33 | private static Func> GetAllElements(By locator)
34 | {
35 | return ((x) =>
36 | {
37 | return x.FindElements(locator);
38 | });
39 | }
40 |
41 | private static Func WaitForWebElementInPageFunc(By locator)
42 | {
43 | return ((x) =>
44 | {
45 | if (x.FindElements(locator).Count == 1)
46 | return x.FindElement(locator);
47 | return null;
48 | });
49 | }
50 |
51 | public static void SelecFromAutoSuggest(By autoSuggesLocator, string initialStr, string strToSelect,
52 | By autoSuggestistLocator)
53 | {
54 | var autoSuggest = ObjectRepository.Driver.FindElement(autoSuggesLocator);
55 | autoSuggest.SendKeys(initialStr);
56 | Thread.Sleep(1000);
57 |
58 | var wait = GenericHelper.GetWebdriverWait(TimeSpan.FromSeconds(40));
59 | var elements = wait.Until(GetAllElements(autoSuggestistLocator));
60 | var select = elements.First((x => x.Text.Equals(strToSelect, StringComparison.OrdinalIgnoreCase)));
61 | select.Click();
62 | Thread.Sleep(1000);
63 | }
64 |
65 | public static WebDriverWait GetWebdriverWait(TimeSpan timeout)
66 | {
67 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(1));
68 | WebDriverWait wait = new WebDriverWait(ObjectRepository.Driver,timeout)
69 | {
70 | PollingInterval = TimeSpan.FromMilliseconds(500),
71 | };
72 | wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(ElementNotVisibleException));
73 | Logger.Info(" Wait Object Created ");
74 | return wait;
75 | }
76 | public static bool IsElemetPresent(By locator)
77 | {
78 | try
79 | {
80 | Logger.Info(" Checking for the element " + locator);
81 | return ObjectRepository.Driver.FindElements(locator).Count == 1;
82 | }
83 | catch (Exception)
84 | {
85 | return false;
86 | }
87 |
88 | }
89 |
90 | public static IWebElement GetElement(By locator)
91 | {
92 | if (IsElemetPresent(locator))
93 | return ObjectRepository.Driver.FindElement(locator);
94 | else
95 | throw new NoSuchElementException("Element Not Found : " + locator.ToString());
96 | }
97 |
98 | public static void TakeScreenShot(string filename = "Screen")
99 | {
100 | var screen = ObjectRepository.Driver.TakeScreenshot();
101 | if (filename.Equals("Screen"))
102 | {
103 | filename = filename + DateTime.UtcNow.ToString("yyyy-MM-dd-mm-ss") + ".jpeg";
104 | screen.SaveAsFile(filename, ScreenshotImageFormat.Jpeg);
105 | Logger.Info(" ScreenShot Taken : " + filename);
106 | return;
107 | }
108 | screen.SaveAsFile(filename, ScreenshotImageFormat.Jpeg); Logger.Info(" ScreenShot Taken : " + filename);
109 | }
110 |
111 | public static bool WaitForWebElement(By locator,TimeSpan timeout)
112 | {
113 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(1));
114 | Logger.Info(" Setting the Explicit wait to 1 sec ");
115 | var wait = GetWebdriverWait(timeout);
116 | var flag = wait.Until(WaitForWebElementFunc(locator));
117 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(ObjectRepository.Config.GetElementLoadTimeOut()));
118 | Logger.Info(" Setting the Explicit wait Configured value ");
119 | return flag;
120 | }
121 |
122 | public static IWebElement WaitForWebElementVisisble(By locator, TimeSpan timeout)
123 | {
124 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(1));
125 | Logger.Info(" Setting the Explicit wait to 1 sec ");
126 | var wait = GetWebdriverWait(timeout);
127 | var flag = wait.Until(ExpectedConditions.ElementIsVisible(locator));
128 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(ObjectRepository.Config.GetElementLoadTimeOut()));
129 | Logger.Info(" Setting the Explicit wait Configured value ");
130 | return flag;
131 | }
132 |
133 | public static IWebElement WaitForWebElementInPage(By locator, TimeSpan timeout)
134 | {
135 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(1));
136 | Logger.Info(" Setting the Explicit wait to 1 sec ");
137 | var wait = GetWebdriverWait(timeout);
138 | var flag = wait.Until(WaitForWebElementInPageFunc(locator));
139 | Logger.Info(" Setting the Explicit wait Configured value ");
140 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(ObjectRepository.Config.GetElementLoadTimeOut()));
141 | return flag;
142 | }
143 |
144 | public static IWebElement Wait(Func conditions,TimeSpan timeout)
145 | {
146 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(1));
147 | Logger.Info(" Setting the Explicit wait to 1 sec ");
148 | var wait = GetWebdriverWait(timeout);
149 | var flag = wait.Until(conditions);
150 | Logger.Info(" Setting the Explicit wait Configured value ");
151 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(ObjectRepository.Config.GetElementLoadTimeOut()));
152 | return flag;
153 | }
154 |
155 |
156 |
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/GridHelper.cs:
--------------------------------------------------------------------------------
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 | ///
35 | /// Get the column value
36 | ///
37 | /// grid locator
38 | /// row index
39 | /// column index
40 | ///
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 GetAllValues(string @locator)
57 | {
58 | List list = new List();
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 GetValues(string @locator, int column)
78 | {
79 | List list = new List();
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 | }
98 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/JavaScriptExecutor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using OpenQA.Selenium;
8 | using SeleniumWebdriver.Settings;
9 | using log4net;
10 |
11 | namespace SeleniumWebdriver.ComponentHelper
12 | {
13 | public class JavaScriptExecutor
14 | {
15 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof(JavaScriptExecutor));
16 | public static object ExecuteScript(string script)
17 | {
18 | IJavaScriptExecutor executor = ((IJavaScriptExecutor) ObjectRepository.Driver);
19 | Logger.Info($" Execute Script @ {script}");
20 | return executor.ExecuteScript(script);
21 |
22 | }
23 |
24 | public static object ExecuteScript(string script,params object[] args)
25 | {
26 | IJavaScriptExecutor executor = ((IJavaScriptExecutor)ObjectRepository.Driver);
27 | return executor.ExecuteScript(script,args);
28 | }
29 |
30 | public static void ScrollToAndClick(IWebElement element)
31 | {
32 | ExecuteScript("window.scrollTo(0," + element.Location.Y + ")");
33 | Thread.Sleep(300);
34 | element.Click();
35 | }
36 |
37 | public static void ScrollToAndClick(By locator)
38 | {
39 | IWebElement element = GenericHelper.GetElement(locator);
40 | ExecuteScript("window.scrollTo(0," + element.Location.Y + ")");
41 | Thread.Sleep(300);
42 | element.Click();
43 | }
44 |
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/JavaScriptPopHelper.cs:
--------------------------------------------------------------------------------
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 JavaScriptPopHelper
12 | {
13 | public static bool IsPopupPresent()
14 | {
15 | try
16 | {
17 | ObjectRepository.Driver.SwitchTo().Alert();
18 | return true;
19 | }
20 | catch (NoAlertPresentException)
21 | {
22 | return false;
23 | }
24 | }
25 |
26 | public static string GetPopUpText()
27 | {
28 | if (!IsPopupPresent())
29 | return String.Empty;
30 | return ObjectRepository.Driver.SwitchTo().Alert().Text;
31 | }
32 |
33 | public static void ClickOkOnPopup()
34 | {
35 | if (!IsPopupPresent())
36 | return;
37 | ObjectRepository.Driver.SwitchTo().Alert().Accept();
38 | }
39 |
40 | public static void ClickCancelOnPopup()
41 | {
42 | if (!IsPopupPresent())
43 | return;
44 | ObjectRepository.Driver.SwitchTo().Alert().Dismiss();
45 | }
46 |
47 | public static void SendKeys(string text)
48 | {
49 | if (!IsPopupPresent())
50 | return;
51 | ObjectRepository.Driver.SwitchTo().Alert().SendKeys(text);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/LinkHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using OpenQA.Selenium;
8 |
9 | namespace SeleniumWebdriver.ComponentHelper
10 | {
11 | public class LinkHelper
12 | {
13 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof (LinkHelper));
14 | private static IWebElement element;
15 |
16 | public static void ClickLink(By Locator)
17 | {
18 | element = GenericHelper.GetElement(Locator);
19 | element.Click();
20 | Logger.Info(" Clicking on link : " + Locator);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/Log4NetHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using log4net.Appender;
8 | using log4net.Config;
9 | using log4net.Core;
10 | using log4net.Layout;
11 |
12 | namespace SeleniumWebdriver.ComponentHelper
13 | {
14 | public class Log4NetHelper
15 | {
16 | #region Field
17 |
18 | private static ILog _logger;
19 | private static ILog _xmlLogger;
20 | private static ConsoleAppender _consoleAppender;
21 | private static FileAppender _fileAppender;
22 | private static RollingFileAppender _rollingFileAppender;
23 | private static string _layout = "%date{dd-MMM-yyyy-HH:mm:ss} [%class] [%level] [%method] - %message%newline";
24 |
25 | #endregion
26 |
27 | #region Property
28 |
29 | public static string Layout
30 | {
31 | set { _layout = value; }
32 | }
33 |
34 | #endregion
35 |
36 | #region Private
37 |
38 | private static PatternLayout GetPatternLayout()
39 | {
40 | var patterLayout = new PatternLayout()
41 | {
42 | ConversionPattern = _layout
43 | };
44 | patterLayout.ActivateOptions();
45 | return patterLayout;
46 | }
47 |
48 | private static ConsoleAppender GetConsoleAppender()
49 | {
50 | var consoleAppender = new ConsoleAppender()
51 | {
52 | Name = "ConsoleAppender",
53 | Layout = GetPatternLayout(),
54 | Threshold = Level.Error
55 | };
56 | consoleAppender.ActivateOptions();
57 | return consoleAppender;
58 | }
59 |
60 | private static FileAppender GetFileAppender()
61 | {
62 | var fileAppender = new FileAppender()
63 | {
64 | Name = "FileAppender",
65 | Layout = GetPatternLayout(),
66 | Threshold = Level.All,
67 | AppendToFile = true,
68 | File = "FileLogger.log",
69 | };
70 | fileAppender.ActivateOptions();
71 | return fileAppender;
72 | }
73 |
74 | private static RollingFileAppender GetRollingFileAppender()
75 | {
76 | var rollingAppender = new RollingFileAppender()
77 | {
78 | Name = "Rolling File Appender",
79 | AppendToFile = true,
80 | File = "RollingFile.log",
81 | Layout = GetPatternLayout(),
82 | Threshold = Level.All,
83 | MaximumFileSize = "1MB",
84 | MaxSizeRollBackups = 15 //file1.log,file2.log.....file15.log
85 | };
86 | rollingAppender.ActivateOptions();
87 | return rollingAppender;
88 | }
89 |
90 | #endregion
91 |
92 | #region Public
93 |
94 | public static ILog GetLogger(Type type)
95 | {
96 | if (_consoleAppender == null)
97 | _consoleAppender = GetConsoleAppender();
98 |
99 | if (_fileAppender == null)
100 | _fileAppender = GetFileAppender();
101 |
102 | if (_rollingFileAppender == null)
103 | _rollingFileAppender = GetRollingFileAppender();
104 |
105 | if (_logger != null)
106 | return _logger;
107 |
108 | BasicConfigurator.Configure(_consoleAppender, _fileAppender, _rollingFileAppender);
109 | _logger = LogManager.GetLogger(type);
110 | return _logger;
111 |
112 | }
113 |
114 | public static ILog GetXmlLogger(Type type)
115 | {
116 | if (_xmlLogger != null)
117 | return _xmlLogger;
118 |
119 | XmlConfigurator.Configure();
120 | _xmlLogger = LogManager.GetLogger(type);
121 | return _xmlLogger;
122 | }
123 |
124 | #endregion
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/MenuHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using SeleniumWebdriver.Settings;
7 |
8 | namespace SeleniumWebdriver.ComponentHelper
9 | {
10 | public class MenuHelper
11 | {
12 | public void test()
13 | {
14 | ObjectRepository.
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/NavigationHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using SeleniumWebdriver.Settings;
8 |
9 | namespace SeleniumWebdriver.ComponentHelper
10 | {
11 | public class NavigationHelper
12 | {
13 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof (NavigationHelper));
14 | public static void NavigateToUrl(string Url)
15 | {
16 | ObjectRepository.Driver.Navigate().GoToUrl(Url);
17 | Logger.Info(" Navigate To Page " + Url);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/RadioButtonHelper.cs:
--------------------------------------------------------------------------------
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 |
8 | namespace SeleniumWebdriver.ComponentHelper
9 | {
10 | public class RadioButtonHelper
11 | {
12 | private static IWebElement element;
13 |
14 | public static void ClickRadioButton(By locator)
15 | {
16 | element = GenericHelper.GetElement(locator);
17 | element.Click();
18 | }
19 |
20 | public static bool IsRadioButtonSelected(By locator)
21 | {
22 | element = GenericHelper.GetElement(locator);
23 | string flag = element.GetAttribute("checked");
24 |
25 | if (flag == null)
26 | return false;
27 | else
28 | return flag.Equals("true") || flag.Equals("checked");
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/TextBoxHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using OpenQA.Selenium;
8 |
9 | namespace SeleniumWebdriver.ComponentHelper
10 | {
11 | public class TextBoxHelper
12 | {
13 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof(TextBoxHelper));
14 | private static IWebElement element;
15 | public static void TypeInTextBox(By locator, string text)
16 | {
17 | element = GenericHelper.GetElement(locator);
18 | element.SendKeys(text);
19 | Logger.Info($" Type in Textbox @ {locator} : value : {text}");
20 | }
21 |
22 | public static void ClearTextBox(By locator)
23 | {
24 | element = GenericHelper.GetElement(locator);
25 | element.Clear();
26 | Logger.Info($" Clear the Textbox @ {locator}");
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ComponentHelper/WindowHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using SeleniumWebdriver.Settings;
7 |
8 | namespace SeleniumWebdriver.ComponentHelper
9 | {
10 | public class WindowHelper
11 | {
12 | public static string GetTitle()
13 | {
14 | return ObjectRepository.Driver.Title;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/Configuration/AppConfigReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using SeleniumWebdriver.Interfaces;
8 | using SeleniumWebdriver.Settings;
9 |
10 | namespace SeleniumWebdriver.Configuration
11 | {
12 | public class AppConfigReader : IConfig
13 | {
14 | public BrowserType? GetBrowser()
15 | {
16 | string browser = ConfigurationManager.AppSettings.Get(AppConfigKeys.Browser);
17 | try
18 | {
19 | return (BrowserType)Enum.Parse(typeof(BrowserType), browser);
20 | }
21 | catch (Exception)
22 | {
23 | return null;
24 | }
25 | }
26 |
27 | public int GetElementLoadTimeOut()
28 | {
29 | string timeout = ConfigurationManager.AppSettings.Get(AppConfigKeys.ElementLoadTimeout);
30 | if (timeout == null)
31 | return 30;
32 | return Convert.ToInt32(timeout);
33 | }
34 |
35 | public int GetPageLoadTimeOut()
36 | {
37 | string timeout = ConfigurationManager.AppSettings.Get(AppConfigKeys.PageLoadTimeout);
38 | if (timeout == null)
39 | return 30;
40 | return Convert.ToInt32(timeout);
41 | }
42 |
43 | public string GetPassword()
44 | {
45 | return ConfigurationManager.AppSettings.Get(AppConfigKeys.Password);
46 | }
47 |
48 | public string GetUsername()
49 | {
50 | return ConfigurationManager.AppSettings.Get(AppConfigKeys.Username);
51 | }
52 |
53 | public string GetWebsite()
54 | {
55 | return ConfigurationManager.AppSettings.Get(AppConfigKeys.Website);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/Configuration/BrowserType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SeleniumWebdriver.Configuration
8 | {
9 | public enum BrowserType
10 | {
11 | Firefox,
12 | Chrome,
13 | IExplorer,
14 | PhantomJs
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/CustomException/NoKeywordFoundException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SeleniumWebdriver.CustomException
8 | {
9 | public class NoSuchKeywordFoundException : Exception
10 | {
11 | public NoSuchKeywordFoundException(string msg) : base(msg)
12 | {
13 |
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/CustomException/NoSutiableDriverFound.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SeleniumWebdriver.CustomException
8 | {
9 | public class NoSutiableDriverFound :Exception
10 | {
11 | public NoSutiableDriverFound(string msg) : base(msg)
12 | {
13 |
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/DataDriven/Script/TestCreateBug.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using SeleniumWebdriver.ComponentHelper;
9 | using SeleniumWebdriver.ExcelReader;
10 | using SeleniumWebdriver.PageObject;
11 | using SeleniumWebdriver.Settings;
12 | using xl=SeleniumWebdriver.ExcelReader.ExcelReaderHelper;
13 |
14 | namespace SeleniumWebdriver.DataDriven.Script
15 | {
16 | [TestClass]
17 | public class TestCreateBug
18 | {
19 | private TestContext _testContext;
20 |
21 | public TestContext TestContext
22 | {
23 | get { return _testContext; }
24 | set { _testContext = value; }
25 | }
26 |
27 | [TestMethod]
28 | [DataSource("System.Data.Odbc", @"Dsn=Excel Files;dbq=C:\downloads\ExcelData.xlsx;", "TestExcelData$", DataAccessMethod.Sequential)]
29 | //[DeploymentItem(@"DataDriven\TestDataFiles", @"DataDriven\TestDataFiles")]
30 | public void TestBug()
31 | {
32 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
33 | HomePage hpPage = new HomePage(ObjectRepository.Driver);
34 | LoginPage loginPage = hpPage.NavigateToLogin();
35 | var ePage = loginPage.Login(ObjectRepository.Config.GetUsername(), ObjectRepository.Config.GetPassword());
36 | var bugPage = ePage.NavigateToDetail();
37 | bugPage.SelectFromCombo(TestContext.DataRow["Severity"].ToString(), TestContext.DataRow["HardWare"].ToString(), TestContext.DataRow["OS"].ToString());
38 | bugPage.TypeIn(TestContext.DataRow["Summary"].ToString(), TestContext.DataRow["Desc"].ToString());
39 | bugPage.ClickSubmit();
40 | bugPage.Logout();
41 | Thread.Sleep(5000);
42 | }
43 |
44 | [TestMethod]
45 | public void TestBugDdF()
46 | {
47 | string xlPath = @"C:\downloads\ExcelData.xlsx";
48 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
49 | HomePage hpPage = new HomePage(ObjectRepository.Driver);
50 | LoginPage loginPage = hpPage.NavigateToLogin();
51 | var ePage = loginPage.Login(ObjectRepository.Config.GetUsername(), ObjectRepository.Config.GetPassword());
52 | var bugPage = ePage.NavigateToDetail();
53 | //bugPage.SelectFromCombo(TestContext.DataRow["Severity"].ToString(), TestContext.DataRow["HardWare"].ToString(), TestContext.DataRow["OS"].ToString());
54 | //bugPage.TypeIn(TestContext.DataRow["Summary"].ToString(), TestContext.DataRow["Desc"].ToString());
55 | bugPage.SelectFromCombo(xl.GetCellData(xlPath, "TestExcelData",1,0).ToString(), xl.GetCellData(xlPath, "TestExcelData", 1, 1).ToString(), ExcelReaderHelper.GetCellData(xlPath, "TestExcelData", 1, 2).ToString());
56 | bugPage.TypeIn(ExcelReaderHelper.GetCellData(xlPath, "TestExcelData", 1, 3).ToString(), ExcelReaderHelper.GetCellData(xlPath, "TestExcelData", 1, 4).ToString());
57 | bugPage.ClickSubmit();
58 | bugPage.Logout();
59 | Thread.Sleep(5000);
60 | }
61 |
62 |
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/DataDriven/TestDataFiles/CreateData.csv:
--------------------------------------------------------------------------------
1 | Severity,HardWare,OS,Summary,Desc
2 | blocker,Other,Linux,Summay One - Excel,Description One - Excel
3 | major,Macintosh,Other,Summay Two - Excel,Description Two - Excel
4 | normal,All,All,Summay Three - Excel,Description Three - Excel
5 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/DataDriven/TestDataFiles/ExcelData.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/DataDriven/TestDataFiles/ExcelData.xlsx
--------------------------------------------------------------------------------
/SeleniumWebdriver/DataDriven/TestDataFiles/TestData.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | blocker
5 | Other
6 | Linux
7 | Summay One - XML
8 | Description One - XML
9 |
10 |
11 | major
12 | Macintosh
13 | Other
14 | Summay Two - XML
15 | Description Two - XML
16 |
17 |
18 | normal
19 | All
20 | All
21 | Summay Three - XML
22 | Description Three - XML
23 |
24 |
25 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ExcelReader/DataFiles/KeywordOne.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/ExcelReader/DataFiles/KeywordOne.xlsx
--------------------------------------------------------------------------------
/SeleniumWebdriver/ExcelReader/DataFiles/KeywordTwo.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/ExcelReader/DataFiles/KeywordTwo.xlsx
--------------------------------------------------------------------------------
/SeleniumWebdriver/ExcelReader/ExcelReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using ExcelDataReader;
9 |
10 | namespace SeleniumWebdriver.ExcelReader
11 | {
12 | public class ExcelReaderHelper
13 | {
14 | private static IDictionary _cache;
15 | private static FileStream stream;
16 | private static IExcelDataReader reader;
17 |
18 | static ExcelReaderHelper()
19 | {
20 | _cache = new Dictionary();
21 | }
22 |
23 | private static IExcelDataReader GetExcelReader(string xlPath, string sheetName)
24 | {
25 | if (_cache.ContainsKey(sheetName))
26 | {
27 | reader = _cache[sheetName];
28 | }
29 | else
30 | {
31 | stream = new FileStream(xlPath, FileMode.Open, FileAccess.Read);
32 | reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
33 | _cache.Add(sheetName, reader);
34 | }
35 | return reader;
36 | }
37 |
38 | public static int GetTotalRows(string xlPath, string sheetName)
39 | {
40 | IExcelDataReader _reader = GetExcelReader(xlPath, sheetName);
41 | return _reader.AsDataSet().Tables[sheetName].Rows.Count;
42 | }
43 |
44 | public static object GetCellData(string xlPath, string sheetName, int row, int column)
45 | {
46 |
47 | IExcelDataReader _reader = GetExcelReader(xlPath, sheetName);
48 | DataTable table = _reader.AsDataSet().Tables[sheetName];
49 | return table.Rows[row][column];
50 | }
51 |
52 | private static object GetData(Type type, object data)
53 | {
54 | switch (type.Name)
55 | {
56 | case "String":
57 | return data.ToString();
58 | case "Double":
59 | return Convert.ToDouble(data);
60 | case "DateTime":
61 | return Convert.ToDateTime(data);
62 | default:
63 | return data.ToString();
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/ExcelReader/TestExcelData.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using ExcelDataReader;
9 | using Microsoft.VisualStudio.TestTools.UnitTesting;
10 |
11 | namespace SeleniumWebdriver.ExcelReader
12 | {
13 | [TestClass]
14 | public class TestExcelData
15 | {
16 | [TestMethod]
17 | public void TestReadExcel()
18 | {
19 | //FileStream stream = new FileStream(@"C:\Users\rahul.rathore\Desktop\Cucumber\Data.xlsx",FileMode.Open,FileAccess.Read);
20 | //IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
21 | //DataTable table = reader.AsDataSet().Tables["Bugzilla"];
22 | //for (int i = 0; i < table.Rows.Count; i++)
23 | //{
24 | // var col = table.Rows[i];
25 | // for (int j = 0; j < col.ItemArray.Length; j++)
26 | // {
27 | // Console.Write("Data : {0}", col.ItemArray[j]);
28 | // }
29 | // Console.WriteLine();
30 | //}
31 | string xlPath = @"C:\Users\rahul.rathore\Desktop\Cucumber\Test.xlsx";
32 | Console.WriteLine(ExcelReaderHelper.GetCellData(xlPath, "Bugzilla",0,0));
33 | Console.WriteLine(ExcelReaderHelper.GetCellData(xlPath, "Bugzilla", 0, 1));
34 | Console.WriteLine(ExcelReaderHelper.GetCellData(xlPath, "Bugzilla", 0, 2));
35 |
36 |
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/FeatureFiles/Arguments.feature:
--------------------------------------------------------------------------------
1 | Feature: Arguments
2 | To demo passing of argument value from the feature file
3 |
4 |
5 | Background: Pre-Condition
6 | # Given Stpe
7 | Given User is at Home Page with url "http://localhost:5001/"
8 | And File a Bug should be visible
9 |
10 | #@Smoke
11 | Scenario: Login scenario of BugZilla
12 | # Steps - A Given Step
13 | When I click on "File a Bug" Link
14 | Then User should be at Login Page with title "Log in to Bugzilla"
15 | When I provide the "rahul@bugzila.com", "rathore" and click on Login button
16 | Then User Should be at Enter Bug page with title "Enter Bug"
17 | When I click on Logout button at enter bug page
18 | Then User should be logged out and should be at Home Page
19 |
20 | Scenario: Create Bug scenario of Bugzilla
21 | When I click on "File a Bug" Link
22 | Then User should be at Login Page with title "Log in to Bugzilla1"
23 | When I provide the "rahul@bugzila.com", "rathore" and click on Login button
24 | Then User Should be at Enter Bug page with title "Enter Bug"
25 | When I click on Testng link in the page
26 | Then User Should be at Bug Detail page with title "Enter Bug: Testng"
27 | When I provide the severity , harware , platform , summary and desc
28 | | Severity | Harware | Platform | Summary | Desc |
29 | | critical | Macintosh | Other | Summary - 1 | Desc - 1 |
30 | | major | Other | Linux | Summary - 2 | Desc - 2 |
31 | And click on Submit button in page
32 | Then Bug should get created
33 | And User should be at Search page
34 | When I click on Logout button at bug detail page
35 | Then User should be logged out and should be at Home Page
36 | @ignore
37 | Scenario Outline: Create Bug scenario of Bugzilla with scenario outline
38 | When I click on "" Link
39 | Then User should be at Login Page with title ""
40 | When I provide the "", "" and click on Login button
41 | Then User Should be at Enter Bug page with title ""
42 | When I click on Testng link in the page
43 | Then User Should be at Bug Detail page with title ""
44 | When I provide the "" , "" , "" , "" and ""
45 | And click on Submit button in page
46 | Then Bug should get created
47 | And User should be at Search page
48 | When I click on Logout button at bug detail page
49 | Then User should be logged out and should be at Home Page
50 | Examples:
51 | | TestCase | flink | lTitle | user | pass | eTitle | bTitle | Severity | Harware | Platform | Summary | Desc |
52 | | A | File a Bug | Log in to Bugzilla | rahul@bugzila.com | rathore | Enter Bug | Enter Bug: Testng | critical | Macintosh | Other | Summary - 1 | Desc - 1 |
53 | | B | File a Bug | Log in to Bugzilla | rahul@bugzila.com | rathore | Enter Bug | Enter Bug: Testng | major | Other | Linux | Summary - 2 | Desc - 2 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/FeatureFiles/Hooks.feature:
--------------------------------------------------------------------------------
1 | Feature: Hooks
2 | To demo the hooks functionality
3 |
4 |
5 | Scenario: Add two numbers
6 | Given I have entered 50 into the calculator
7 | And I have entered 70 into the calculator
8 | When I press add
9 | Then the result should be 120 on the screen
10 |
11 | @Tag1
12 | Scenario: Sus two numbers
13 | Given I have entered 50 into the calculator
14 | And I have entered 70 into the calculator
15 | When I press sub
16 | Then the result should be 120 on the screen
17 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/FeatureFiles/Hooks.feature.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This code was generated by SpecFlow (http://www.specflow.org/).
4 | // SpecFlow Version:2.4.0.0
5 | // SpecFlow Generator Version:2.4.0.0
6 | //
7 | // Changes to this file may cause incorrect behavior and will be lost if
8 | // the code is regenerated.
9 | //
10 | // ------------------------------------------------------------------------------
11 | #region Designer generated code
12 | #pragma warning disable
13 | namespace SeleniumWebdriver.FeatureFiles
14 | {
15 | using TechTalk.SpecFlow;
16 |
17 |
18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.4.0.0")]
19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
20 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
21 | public partial class HooksFeature
22 | {
23 |
24 | private static TechTalk.SpecFlow.ITestRunner testRunner;
25 |
26 | private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext;
27 |
28 | #line 1 "Hooks.feature"
29 | #line hidden
30 |
31 | public virtual Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext
32 | {
33 | get
34 | {
35 | return this._testContext;
36 | }
37 | set
38 | {
39 | this._testContext = value;
40 | }
41 | }
42 |
43 | [Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()]
44 | public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)
45 | {
46 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(null, 0);
47 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Hooks", "\tTo demo the hooks functionality", ProgrammingLanguage.CSharp, ((string[])(null)));
48 | testRunner.OnFeatureStart(featureInfo);
49 | }
50 |
51 | [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()]
52 | public static void FeatureTearDown()
53 | {
54 | testRunner.OnFeatureEnd();
55 | testRunner = null;
56 | }
57 |
58 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()]
59 | public virtual void TestInitialize()
60 | {
61 | if (((testRunner.FeatureContext != null)
62 | && (testRunner.FeatureContext.FeatureInfo.Title != "Hooks")))
63 | {
64 | global::SeleniumWebdriver.FeatureFiles.HooksFeature.FeatureSetup(null);
65 | }
66 | }
67 |
68 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()]
69 | public virtual void ScenarioTearDown()
70 | {
71 | testRunner.OnScenarioEnd();
72 | }
73 |
74 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
75 | {
76 | testRunner.OnScenarioInitialize(scenarioInfo);
77 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testContext);
78 | }
79 |
80 | public virtual void ScenarioStart()
81 | {
82 | testRunner.OnScenarioStart();
83 | }
84 |
85 | public virtual void ScenarioCleanup()
86 | {
87 | testRunner.CollectScenarioErrors();
88 | }
89 |
90 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
91 | [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Add two numbers")]
92 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "Hooks")]
93 | public virtual void AddTwoNumbers()
94 | {
95 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add two numbers", null, ((string[])(null)));
96 | #line 5
97 | this.ScenarioInitialize(scenarioInfo);
98 | this.ScenarioStart();
99 | #line 6
100 | testRunner.Given("I have entered 50 into the calculator", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
101 | #line 7
102 | testRunner.And("I have entered 70 into the calculator", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
103 | #line 8
104 | testRunner.When("I press add", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
105 | #line 9
106 | testRunner.Then("the result should be 120 on the screen", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
107 | #line hidden
108 | this.ScenarioCleanup();
109 | }
110 |
111 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
112 | [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Sus two numbers")]
113 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "Hooks")]
114 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("Tag1")]
115 | public virtual void SusTwoNumbers()
116 | {
117 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Sus two numbers", null, new string[] {
118 | "Tag1"});
119 | #line 12
120 | this.ScenarioInitialize(scenarioInfo);
121 | this.ScenarioStart();
122 | #line 13
123 | testRunner.Given("I have entered 50 into the calculator", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
124 | #line 14
125 | testRunner.And("I have entered 70 into the calculator", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
126 | #line 15
127 | testRunner.When("I press sub", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
128 | #line 16
129 | testRunner.Then("the result should be 120 on the screen", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
130 | #line hidden
131 | this.ScenarioCleanup();
132 | }
133 | }
134 | }
135 | #pragma warning restore
136 | #endregion
137 |
138 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/FeatureFiles/TestFeature.feature:
--------------------------------------------------------------------------------
1 | Feature: Login and Create Bug Feature of the BugZila web page
2 |
3 | Background: Pre-Condition
4 | # Given Stpe
5 | Given User is at Home Page
6 | And File a Bug should be visible
7 |
8 | Scenario: Login scenario of BugZilla
9 | # Steps - A Given Step
10 | When I click on File a Bug Link
11 | Then User should be at Login Page
12 | When I provide the username, password and click on Login button
13 | Then User Should be at Enter Bug page
14 | When I click on Logout button
15 | Then User should be logged out and should be at Home Page
16 |
17 |
18 | Scenario: Create Bug scenario of Bugzilla
19 | When I click on File a Bug Link
20 | # Then Step
21 | Then User should be at Login Page
22 | When I provide the username, password and click on Login button
23 | Then User Should be at Enter Bug page
24 | When I click on Testng link
25 | Then User Should be at Bug Detail page
26 | When I provide the severity , harware , platform and summary
27 | And click on Submit button
28 | Then Bug should get created
29 | And User should be at Search page
30 | When I click on Logout button
31 | Then User should be logged out and should be at Home Page
--------------------------------------------------------------------------------
/SeleniumWebdriver/FeatureFiles/TestFeature2.feature:
--------------------------------------------------------------------------------
1 | Feature: TestFeature2
2 |
3 | Background: Pre-Condition
4 | # Given Stpe
5 | Given User is at Home Page
6 | And File a Bug should be visible
7 |
8 | Scenario: Login scenario of BugZilla
9 | # Steps - A Given Step
10 | When I click on File a Bug Link
11 | Then User should be at Login Page
12 | When I provide the "rahul@bugzila.com", "rathore" and click on Login button
13 | Then User Should be at Enter Bug page
14 | When I click on Logout button
15 | Then User should be logged out and should be at Home Page
--------------------------------------------------------------------------------
/SeleniumWebdriver/FeatureFiles/TestFeature2.feature.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This code was generated by SpecFlow (http://www.specflow.org/).
4 | // SpecFlow Version:2.4.0.0
5 | // SpecFlow Generator Version:2.4.0.0
6 | //
7 | // Changes to this file may cause incorrect behavior and will be lost if
8 | // the code is regenerated.
9 | //
10 | // ------------------------------------------------------------------------------
11 | #region Designer generated code
12 | #pragma warning disable
13 | namespace SeleniumWebdriver.FeatureFiles
14 | {
15 | using TechTalk.SpecFlow;
16 |
17 |
18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.4.0.0")]
19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
20 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
21 | public partial class TestFeature2Feature
22 | {
23 |
24 | private static TechTalk.SpecFlow.ITestRunner testRunner;
25 |
26 | private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext;
27 |
28 | #line 1 "TestFeature2.feature"
29 | #line hidden
30 |
31 | public virtual Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext
32 | {
33 | get
34 | {
35 | return this._testContext;
36 | }
37 | set
38 | {
39 | this._testContext = value;
40 | }
41 | }
42 |
43 | [Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()]
44 | public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)
45 | {
46 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(null, 0);
47 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "TestFeature2", null, ProgrammingLanguage.CSharp, ((string[])(null)));
48 | testRunner.OnFeatureStart(featureInfo);
49 | }
50 |
51 | [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()]
52 | public static void FeatureTearDown()
53 | {
54 | testRunner.OnFeatureEnd();
55 | testRunner = null;
56 | }
57 |
58 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()]
59 | public virtual void TestInitialize()
60 | {
61 | if (((testRunner.FeatureContext != null)
62 | && (testRunner.FeatureContext.FeatureInfo.Title != "TestFeature2")))
63 | {
64 | global::SeleniumWebdriver.FeatureFiles.TestFeature2Feature.FeatureSetup(null);
65 | }
66 | }
67 |
68 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()]
69 | public virtual void ScenarioTearDown()
70 | {
71 | testRunner.OnScenarioEnd();
72 | }
73 |
74 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
75 | {
76 | testRunner.OnScenarioInitialize(scenarioInfo);
77 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testContext);
78 | }
79 |
80 | public virtual void ScenarioStart()
81 | {
82 | testRunner.OnScenarioStart();
83 | }
84 |
85 | public virtual void ScenarioCleanup()
86 | {
87 | testRunner.CollectScenarioErrors();
88 | }
89 |
90 | public virtual void FeatureBackground()
91 | {
92 | #line 3
93 | #line 5
94 | testRunner.Given("User is at Home Page", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
95 | #line 6
96 | testRunner.And("File a Bug should be visible", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
97 | #line hidden
98 | }
99 |
100 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
101 | [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Login scenario of BugZilla")]
102 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "TestFeature2")]
103 | public virtual void LoginScenarioOfBugZilla()
104 | {
105 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Login scenario of BugZilla", null, ((string[])(null)));
106 | #line 8
107 | this.ScenarioInitialize(scenarioInfo);
108 | this.ScenarioStart();
109 | #line 3
110 | this.FeatureBackground();
111 | #line 10
112 | testRunner.When("I click on File a Bug Link", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
113 | #line 11
114 | testRunner.Then("User should be at Login Page", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
115 | #line 12
116 | testRunner.When("I provide the \"rahul@bugzila.com\", \"rathore\" and click on Login button", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
117 | #line 13
118 | testRunner.Then("User Should be at Enter Bug page", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
119 | #line 14
120 | testRunner.When("I click on Logout button", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
121 | #line 15
122 | testRunner.Then("User should be logged out and should be at Home Page", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
123 | #line hidden
124 | this.ScenarioCleanup();
125 | }
126 | }
127 | }
128 | #pragma warning restore
129 | #endregion
130 |
131 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/GeneralHook/GeneralHook.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using SeleniumWebdriver.ComponentHelper;
6 | using TechTalk.SpecFlow;
7 |
8 | namespace SeleniumWebdriver.GeneralHook
9 | {
10 | [Binding]
11 | public sealed class GeneralHook
12 | {
13 | [BeforeTestRun]
14 | public static void BeforeTestRun()
15 | {
16 | Console.WriteLine("BeforeTestRun Hook");
17 | }
18 |
19 | [AfterTestRun]
20 | public static void AfterTestRun()
21 | {
22 | Console.WriteLine("AfterTestRun Hook");
23 | }
24 |
25 | [BeforeFeature("Tag1")]
26 | public static void BeforeFeature()
27 | {
28 | Console.WriteLine("BeforeFeature Hook");
29 | }
30 |
31 | [AfterFeature("Tag1")]
32 | public static void AfterFeature()
33 | {
34 | Console.WriteLine("AfterFeature Hook");
35 | }
36 |
37 | [BeforeScenario("Tag1")]
38 | public static void BeforeScenario()
39 | {
40 | Console.WriteLine("BeforeScenario Hook");
41 | }
42 |
43 | [AfterScenario]
44 | public static void AfterScenario()
45 | {
46 | Console.WriteLine("AfterScenario Hook");
47 | if (ScenarioContext.Current.TestError != null)
48 | {
49 | string name = ScenarioContext.Current.ScenarioInfo.Title + ".jpeg";
50 | GenericHelper.TakeScreenShot(name);
51 | Console.WriteLine(ScenarioContext.Current.TestError.Message);
52 | Console.WriteLine(ScenarioContext.Current.TestError.StackTrace);
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/Interfaces/IConfig.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using SeleniumWebdriver.Configuration;
7 |
8 | namespace SeleniumWebdriver.Interfaces
9 | {
10 | public interface IConfig
11 | {
12 | BrowserType? GetBrowser();
13 | string GetUsername();
14 | string GetPassword();
15 | string GetWebsite();
16 | int GetPageLoadTimeOut();
17 | int GetElementLoadTimeOut();
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/Keyword/DataEngine.cs:
--------------------------------------------------------------------------------
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.ComponentHelper;
8 | using SeleniumWebdriver.CustomException;
9 | using SeleniumWebdriver.ExcelReader;
10 |
11 | namespace SeleniumWebdriver.Keyword
12 | {
13 | public class DataEngine
14 | {
15 | private readonly int _keywordCol;
16 | private readonly int _locatorTypeCol;
17 | private readonly int _locatorValueCol;
18 | private readonly int _parameterCol;
19 |
20 | public DataEngine(int keywordCol = 2, int locatorTypeCol = 3, int locatorValueCol = 4, int parameterCol = 5)
21 | {
22 | this._keywordCol = keywordCol;
23 | this._locatorTypeCol = locatorTypeCol;
24 | this._locatorValueCol = locatorValueCol;
25 | this._parameterCol = parameterCol;
26 | }
27 |
28 | private By GetElementLocator(string locatorType,string locatorValue)
29 | {
30 | switch (locatorType)
31 | {
32 | case "ClassName":
33 | return By.ClassName(locatorValue);
34 | case "CssSelector":
35 | return By.CssSelector(locatorValue);
36 | case "Id":
37 | return By.Id(locatorValue);
38 | case "PartialLinkText":
39 | return By.PartialLinkText(locatorValue);
40 | case "Name":
41 | return By.Name(locatorValue);
42 | case "XPath":
43 | return By.XPath(locatorValue);
44 | case "TagName":
45 | return By.TagName(locatorValue);
46 | default:
47 | return By.Id(locatorValue);
48 | }
49 | }
50 |
51 | private void PerformAction(string keyword,string locatorType, string locatorValue,params string[] args)
52 | {
53 | switch (keyword)
54 | {
55 | case "Click":
56 | ButtonHelper.ClickButton(GetElementLocator(locatorType,locatorValue));
57 | break;
58 | case "SendKeys":
59 | TextBoxHelper.TypeInTextBox(GetElementLocator(locatorType,locatorValue),args[0]);
60 | break;
61 | case "Select":
62 | ComboBoxHelper.SelectElementByValue(GetElementLocator(locatorType,locatorValue),args[0]);
63 | break;
64 | case "WaitForEle":
65 | GenericHelper.WaitForWebElementInPage(GetElementLocator(locatorType, locatorValue),
66 | TimeSpan.FromSeconds(50));
67 | break;
68 | case "Navigate":
69 | NavigationHelper.NavigateToUrl(args[0]);
70 | break;
71 | default:
72 | throw new NoSuchKeywordFoundException("Keyword Not Found : " + keyword);
73 | }
74 | }
75 |
76 | public void ExecuteScript(string xlPath, string sheetName)
77 | {
78 | int totalRows = ExcelReaderHelper.GetTotalRows(xlPath, sheetName);
79 | for (int i = 1; i < totalRows; i++)
80 | {
81 | var lctType = ExcelReaderHelper.GetCellData(xlPath, sheetName, i, _locatorTypeCol).ToString();
82 | var lctValue = ExcelReaderHelper.GetCellData(xlPath, sheetName, i, _locatorValueCol).ToString();
83 | var keyword = ExcelReaderHelper.GetCellData(xlPath, sheetName, i, _keywordCol).ToString();
84 | var param = ExcelReaderHelper.GetCellData(xlPath, sheetName, i, _parameterCol).ToString();
85 | PerformAction(keyword,lctType,lctValue,param);
86 | }
87 | }
88 |
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/NLog.config:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
14 |
18 |
19 |
20 |
25 |
26 |
29 |
30 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/OrderedTest.orderedtest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/PageObject/BugDetail.cs:
--------------------------------------------------------------------------------
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 SeleniumExtras.PageObjects;
8 | using SeleniumWebdriver.BaseClasses;
9 | using SeleniumWebdriver.ComponentHelper;
10 | using SeleniumWebdriver.Settings;
11 |
12 | namespace SeleniumWebdriver.PageObject
13 | {
14 | public class BugDetail : PageBase
15 | {
16 | private IWebDriver driver;
17 |
18 | #region WebElement
19 |
20 | [FindsBy(How = How.Id, Using = "bug_severity")]
21 | private IWebElement SeverityDropDown;
22 | //private IWebElement SeverityDropDown => driver.FindElement(By.Id("bug_severity"));
23 |
24 | [FindsBy(How = How.Id,Using = "rep_platform")]
25 | private IWebElement Hardware;
26 | //private IWebElement Hardware => driver.FindElement(By.Id("rep_platform"));
27 |
28 | [FindsBy(How = How.Id, Using = "op_sys")]
29 | private IWebElement OpSys;
30 | //private IWebElement OpSys => driver.FindElement(By.Id("op_sys"));
31 |
32 | [FindsBy(How = How.Id, Using = "short_desc")]
33 | private IWebElement ShortDesc;
34 | //private IWebElement ShortDesc => driver.FindElement(By.Id("short_desc"));
35 |
36 | [FindsBy(How = How.Id, Using = "comment")]
37 | private IWebElement Comment;
38 | //private IWebElement Comment => driver.FindElement(By.Id("comment"));
39 |
40 | [FindsBy(How = How.Id, Using = "commit")]
41 | private IWebElement Commit;
42 | //private IWebElement Commit => driver.FindElement(By.Id("commit"));
43 | #endregion
44 |
45 | public BugDetail(IWebDriver _driver) : base(_driver)
46 | {
47 | this.driver = _driver;
48 | }
49 |
50 | #region Action
51 |
52 | public void SelectFromSeverity(string value)
53 | {
54 | ComboBoxHelper.SelectElement(SeverityDropDown, value);
55 | }
56 |
57 | public void SelectFromCombo(string severity = null, string hardware = null, string os = null)
58 | {
59 | if(severity != null)
60 | ComboBoxHelper.SelectElement(SeverityDropDown,severity);
61 | if(hardware != null)
62 | ComboBoxHelper.SelectElement(Hardware,hardware);
63 | if(os != null)
64 | ComboBoxHelper.SelectElement(OpSys,os);
65 | }
66 |
67 | public void TypeIn(string summary = null, string desc = null)
68 | {
69 | if(summary != null)
70 | ShortDesc.SendKeys(summary);
71 | if(desc != null)
72 | Comment.SendKeys(desc);
73 | }
74 |
75 | public void ClickSubmit()
76 | {
77 | Commit.Click();
78 | GenericHelper.WaitForWebElementInPage(By.Id("bugzilla-body"), TimeSpan.FromSeconds(30));
79 | }
80 |
81 | public new HomePage Logout()
82 | {
83 | base.Logout();
84 | return new HomePage(driver);
85 | }
86 | #endregion
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/PageObject/EnterBug.cs:
--------------------------------------------------------------------------------
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 SeleniumExtras.PageObjects;
8 | using SeleniumWebdriver.BaseClasses;
9 | using SeleniumWebdriver.ComponentHelper;
10 | using SeleniumWebdriver.Settings;
11 |
12 | namespace SeleniumWebdriver.PageObject
13 | {
14 | public class EnterBug : PageBase
15 | {
16 | private IWebDriver driver;
17 | #region WenElement
18 |
19 | [FindsBy(How = How.LinkText, Using = "Testng")]
20 | private IWebElement Testng;
21 | //private IWebElement Testng => driver.FindElement(By.LinkText("Testng"));
22 |
23 | #endregion
24 |
25 | public EnterBug(IWebDriver _driver) : base(_driver)
26 | {
27 | this.driver = _driver;
28 | }
29 |
30 | #region Navigation
31 |
32 | public BugDetail NavigateToDetail()
33 | {
34 | Testng.Click();
35 | GenericHelper.WaitForWebElementInPage(By.Id("component"), TimeSpan.FromSeconds(30));
36 | return new BugDetail(driver);
37 | }
38 |
39 |
40 | #endregion
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/PageObject/HomePage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using SeleniumExtras.PageObjects;
9 | using SeleniumWebdriver.BaseClasses;
10 | using SeleniumWebdriver.ComponentHelper;
11 | using SeleniumWebdriver.Settings;
12 |
13 | namespace SeleniumWebdriver.PageObject
14 | {
15 | public class HomePage : PageBase
16 | {
17 | private IWebDriver driver;
18 | #region WebElement
19 |
20 | [FindsBy(How = How.Id, Using = "quicksearch_main")]
21 | public IWebElement QuickSearchTextBox;
22 | //private IWebElement QuickSearchTextBox => driver.FindElement(By.Id("quicksearch_main"));
23 |
24 | [FindsBy(How = How.Id, Using = "find")]
25 | [CacheLookup]
26 | public IWebElement QuickSearchBtn;
27 | //private IWebElement QuickSearchBtn => driver.FindElement(By.Id("find"));
28 |
29 | [FindsBy(How = How.LinkText, Using = "File a Bug")]
30 | private IWebElement FileABugLink;
31 | //private IWebElement FileABugLink => driver.FindElement(By.LinkText("File a Bug"));
32 |
33 | #endregion
34 |
35 | public HomePage(IWebDriver _driver) : base(_driver)
36 | {
37 | this.driver = _driver;
38 | }
39 |
40 | #region Actions
41 |
42 | public void QuickSearch(string text)
43 | {
44 | QuickSearchTextBox.SendKeys(text);
45 | QuickSearchBtn.Click();
46 | }
47 |
48 | #endregion
49 |
50 | #region Navigation
51 |
52 | public LoginPage NavigateToLogin()
53 | {
54 | FileABugLink.Click();
55 | GenericHelper.WaitForWebElementInPage(By.Id("log_in"), TimeSpan.FromSeconds(30));
56 | return new LoginPage(driver);
57 | }
58 |
59 | #endregion
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/PageObject/LoginPage.cs:
--------------------------------------------------------------------------------
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 SeleniumExtras.PageObjects;
8 | using SeleniumWebdriver.BaseClasses;
9 | using SeleniumWebdriver.ComponentHelper;
10 | using SeleniumWebdriver.Settings;
11 |
12 | namespace SeleniumWebdriver.PageObject
13 | {
14 | public class LoginPage : PageBase
15 | {
16 | private IWebDriver driver;
17 |
18 |
19 | #region WebElement
20 | [FindsBy(How = How.Id, Using = "Bugzilla_login")]
21 | private IWebElement LoginTextBox;
22 | //private IWebElement LoginTextBox => driver.FindElement(By.Id("Bugzilla_login"));
23 |
24 | [FindsBy(How = How.Id, Using = "Bugzilla_password")]
25 | private IWebElement PassTextBox;
26 | //private IWebElement PassTextBox => driver.FindElement(By.Id("Bugzilla_password"));
27 |
28 | [FindsBy(How = How.Id, Using = "log_in")]
29 | [CacheLookup]
30 | private IWebElement LoginButton;
31 | //private IWebElement LoginButton => driver.FindElement(By.Id ("log_in"));
32 |
33 | [FindsBy(How = How.LinkText, Using = "Home")]
34 | private IWebElement HomeLink;
35 | //private IWebElement HomeLink => driver.FindElement(By.LinkText("Home"));
36 |
37 |
38 | #endregion
39 |
40 | public LoginPage(IWebDriver _driver) : base(_driver)
41 | {
42 | this.driver = _driver;
43 |
44 | }
45 |
46 | #region Actions
47 |
48 | public EnterBug Login(string usename, string password)
49 | {
50 | LoginTextBox.SendKeys(usename);
51 | PassTextBox.SendKeys(password);
52 | LoginButton.Click();
53 | GenericHelper.WaitForWebElementInPage(By.LinkText("Testng"), TimeSpan.FromSeconds(30));
54 | return new EnterBug(driver);
55 |
56 | }
57 |
58 | #endregion
59 |
60 | #region Navigation
61 |
62 | public void NavigateToHome()
63 | {
64 | HomeLink.Click();
65 | }
66 |
67 | #endregion
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SeleniumWebdriver")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SeleniumWebdriver")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("84cf58ce-ca65-40e9-9041-625d8b529170")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/Reports/Reporter.cs:
--------------------------------------------------------------------------------
1 | using AventStack.ExtentReports;
2 | using AventStack.ExtentReports.Reporter;
3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
4 | using NLog;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace SeleniumWebdriver.Reports
13 | {
14 | public class Reporter
15 | {
16 | private static readonly Logger TheLogger = LogManager.GetCurrentClassLogger();
17 | private static ExtentReports ReportManager { get; set; }
18 | private static string ApplicationDebuggingFolder => @"C:\Data\report";
19 |
20 | private static string HtmlReportFullPath { get; set; }
21 |
22 | public static string LatestResultsReportFolder { get; set; }
23 |
24 | private static TestContext MyTestContext { get; set; }
25 |
26 | private static ExtentTest CurrentTestCase { get; set; }
27 |
28 | private static bool IsExtenetReportStarted = false;
29 |
30 | public static void StartReporter()
31 | {
32 | TheLogger.Trace("Starting a one time setup for the entire" +
33 | " .CreatingReports namespace." +
34 | "Going to initialize the reporter next...");
35 | CreateReportDirectory();
36 | var htmlReporter = new ExtentHtmlReporter(HtmlReportFullPath);
37 | ReportManager = new ExtentReports();
38 | ReportManager.AttachReporter(htmlReporter);
39 | }
40 |
41 | private static void CreateReportDirectory()
42 | {
43 | var filePath = Path.GetFullPath(ApplicationDebuggingFolder);
44 | LatestResultsReportFolder = Path.Combine(filePath, DateTime.Now.ToString("MMdd_HHmm"));
45 | Directory.CreateDirectory(LatestResultsReportFolder);
46 |
47 | HtmlReportFullPath = $"{LatestResultsReportFolder}\\TestResults.html";
48 | TheLogger.Trace("Full path of HTML report=>" + HtmlReportFullPath);
49 | }
50 |
51 | public static void AddTestCaseMetadataToHtmlReport(TestContext testContext)
52 | {
53 | MyTestContext = testContext;
54 | CurrentTestCase = ReportManager.CreateTest(MyTestContext.TestName);
55 | }
56 |
57 | public static void LogPassingTestStepToBugLogger(string message)
58 | {
59 | TheLogger.Info(message);
60 | CurrentTestCase.Log(Status.Pass, message);
61 | }
62 |
63 | public static void ReportTestOutcome(string screenshotPath)
64 | {
65 | var status = MyTestContext.CurrentTestOutcome;
66 |
67 | switch (status)
68 | {
69 | case UnitTestOutcome.Failed:
70 | TheLogger.Error($"Test Failed=>{MyTestContext.FullyQualifiedTestClassName}");
71 | CurrentTestCase.AddScreenCaptureFromPath(screenshotPath);
72 | CurrentTestCase.Fail("Fail");
73 | break;
74 | case UnitTestOutcome.Inconclusive:
75 | CurrentTestCase.AddScreenCaptureFromPath(screenshotPath);
76 | CurrentTestCase.Warning("Inconclusive");
77 | break;
78 | case UnitTestOutcome.Unknown:
79 | CurrentTestCase.Skip("Test skipped");
80 | break;
81 | default:
82 | CurrentTestCase.Pass("Pass");
83 | break;
84 | }
85 |
86 | ReportManager.Flush();
87 | }
88 |
89 | public static void LogTestStepForBugLogger(Status status, string message)
90 | {
91 | TheLogger.Info(message);
92 | CurrentTestCase.Log(status, message);
93 | }
94 |
95 | public static void GetReportManager()
96 | {
97 | if (!IsExtenetReportStarted)
98 | {
99 | IsExtenetReportStarted = true;
100 | StartReporter();
101 | }
102 | }
103 | }
104 | }
105 |
106 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/Resources/ExcelData.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/Resources/ExcelData.xlsx
--------------------------------------------------------------------------------
/SeleniumWebdriver/Resources/FileUpload.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/Resources/FileUpload.exe
--------------------------------------------------------------------------------
/SeleniumWebdriver/Resources/IEDriverServer.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/Resources/IEDriverServer.exe
--------------------------------------------------------------------------------
/SeleniumWebdriver/Resources/SampleFile.txt:
--------------------------------------------------------------------------------
1 | This is a sample file
--------------------------------------------------------------------------------
/SeleniumWebdriver/Resources/chromedriver.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/Resources/chromedriver.exe
--------------------------------------------------------------------------------
/SeleniumWebdriver/Resources/phantomjs.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/Resources/phantomjs.exe
--------------------------------------------------------------------------------
/SeleniumWebdriver/Settings/AppConfigKeys.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SeleniumWebdriver.Settings
8 | {
9 | public class AppConfigKeys
10 | {
11 | public const string Browser = "Browser";
12 | public const string Username = "Username";
13 | public const string Password = "Password";
14 | public const string Website = "Website";
15 | public const string PageLoadTimeout = "PageLoadTimeout";
16 | public const string ElementLoadTimeout = "ElementLoadTimeout";
17 |
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/Settings/ObjectRepository.cs:
--------------------------------------------------------------------------------
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.Interfaces;
8 | using SeleniumWebdriver.PageObject;
9 |
10 | namespace SeleniumWebdriver.Settings
11 | {
12 | public class ObjectRepository
13 | {
14 | public static IConfig Config { get; set; }
15 | public static IWebDriver Driver { get; set; }
16 |
17 | public static HomePage hPage;
18 | public static LoginPage lPage;
19 | public static EnterBug ePage;
20 | public static BugDetail bPage;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/StepDefinition/Arguments.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
6 | using SeleniumWebdriver.ComponentHelper;
7 | using SeleniumWebdriver.PageObject;
8 | using SeleniumWebdriver.Settings;
9 | using TechTalk.SpecFlow;
10 |
11 | namespace SeleniumWebdriver.StepDefinition
12 | {
13 | [Binding]
14 | public sealed class Arguments
15 | {
16 | private HomePage hPage;
17 | private LoginPage lPage;
18 | private EnterBug ePage;
19 | private BugDetail bPage;
20 |
21 | #region Given
22 |
23 | [Given(@"User is at Home Page with url in the browser ""(.*)""")]
24 | [Given(@"User is at Home Page with url ""(.*)""")]
25 | public void GivenUserIsAtHomePageWithUrl(string url)
26 | {
27 | NavigationHelper.NavigateToUrl(url);
28 | }
29 | #endregion
30 |
31 | #region When
32 | [When(@"I click on ""(.*)"" Link")]
33 | public void WhenIClickOnLink(string linkText)
34 | {
35 | ObjectRepository.hPage = new HomePage(ObjectRepository.Driver);
36 | ObjectRepository.lPage = ObjectRepository.hPage.NavigateToLogin();
37 | }
38 |
39 | [When(@"I provide the ""(.*)"", ""(.*)"" and click on Login button")]
40 | public void WhenIProvideTheAndClickOnLoginButton(string user, string pass)
41 | {
42 | ObjectRepository.ePage = ObjectRepository.lPage.Login(user, pass);
43 | }
44 |
45 |
46 | [When(@"I click on Logout button at bug detail page")]
47 | [When(@"I click on Logout button at enter bug page")]
48 | public void WhenIClickOnLogoutButtonAtEnterBugPage()
49 | {
50 | ObjectRepository.ePage.Logout();
51 | }
52 | [When(@"I click on Testng link in the page")]
53 | public void WhenIClickOnTestngLinkInThePage()
54 | {
55 | ObjectRepository.bPage = ObjectRepository.ePage.NavigateToDetail();
56 | }
57 |
58 | [When(@"I provide the severity , harware , platform , summary and desc")]
59 | public void WhenIProvideTheSeverityHarwarePlatformSummaryAndDesc(Table table)
60 | {
61 | foreach (var row in table.Rows)
62 | {
63 | ObjectRepository.bPage.SelectFromCombo(row["Severity"], row["Harware"], row["Platform"]);
64 | ObjectRepository.bPage.TypeIn(row["Summary"], row["Desc"]);
65 | }
66 |
67 |
68 | }
69 |
70 | [When(@"I provide the ""(.*)"" , ""(.*)"" , ""(.*)"" , ""(.*)"" and ""(.*)""")]
71 | public void WhenIProvideTheAnd(string severity, string harware, string platform, string summary, string desc)
72 | {
73 | bPage.SelectFromCombo(severity,harware, platform);
74 | bPage.TypeIn(summary, desc);
75 | }
76 |
77 |
78 |
79 | #endregion
80 |
81 | #region Then
82 |
83 | [Then(@"User should be at Login Page with title ""(.*)""")]
84 | public void ThenUserShouldBeAtLoginPageWithTitle(string title)
85 | {
86 | Assert.AreEqual(title,ObjectRepository.lPage.Title);
87 | }
88 |
89 | [Then(@"User Should be at Enter Bug page with title ""(.*)""")]
90 | public void ThenUserShouldBeAtEnterBugPageWithTitle(string title)
91 | {
92 | Assert.AreEqual(title, ObjectRepository.ePage.Title);
93 | }
94 |
95 | [Then(@"User Should be at Bug Detail page with title ""(.*)""")]
96 | public void ThenUserShouldBeAtBugDetailPageWithTitle(string title)
97 | {
98 | Assert.AreEqual(title, ObjectRepository.bPage.Title);
99 | }
100 |
101 |
102 | #endregion
103 |
104 | #region And
105 |
106 | [When(@"click on Submit button in page")]
107 | public void WhenClickOnSubmitButtonInPage()
108 | {
109 | ObjectRepository.bPage.ClickSubmit();
110 | }
111 |
112 |
113 | #endregion
114 |
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/StepDefinition/Hooks.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
6 | using TechTalk.SpecFlow;
7 |
8 | namespace SeleniumWebdriver.StepDefinition
9 | {
10 | [Binding]
11 | public sealed class Hooks
12 | {
13 | [Given(@"I have entered (.*) into the calculator")]
14 | public void GivenIHaveEnteredIntoTheCalculator(int p0)
15 | {
16 | //ScenarioContext.Current.Pending();
17 | //Assert.Fail();
18 | }
19 |
20 | [When(@"I press add")]
21 | public void WhenIPressAdd()
22 | {
23 | //ScenarioContext.Current.Pending();
24 | }
25 |
26 | [Then(@"the result should be (.*) on the screen")]
27 | public void ThenTheResultShouldBeOnTheScreen(int p0)
28 | {
29 | //ScenarioContext.Current.Pending();
30 | }
31 | [When(@"I press sub")]
32 | public void WhenIPressSub()
33 | {
34 | // ScenarioContext.Current.Pending();
35 | //Assert.Fail();
36 | }
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/StepDefinition/TestFeature.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
6 | using OpenQA.Selenium;
7 | using SeleniumWebdriver.ComponentHelper;
8 | using SeleniumWebdriver.PageObject;
9 | using SeleniumWebdriver.Settings;
10 | using TechTalk.SpecFlow;
11 |
12 | namespace SeleniumWebdriver.StepDefinition
13 | {
14 | [Binding]
15 | public sealed class TestFeature
16 | {
17 |
18 | private HomePage hPage;
19 | private LoginPage lPage;
20 | private EnterBug ePage;
21 | private BugDetail bPage;
22 |
23 | #region Given
24 |
25 | [Given(@"User is at Home Page")]
26 | public void GivenUserIsAtHomePage()
27 | {
28 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
29 | }
30 |
31 | [Given(@"File a Bug should be visible")]
32 | public void GivenFileABugShouldBeVisible()
33 | {
34 | Assert.IsTrue(GenericHelper.IsElemetPresent(By.Id("enter_bug")));
35 | }
36 |
37 | #endregion
38 |
39 | #region When
40 |
41 | [When(@"I click on File a Bug Link")]
42 | public void WhenIClickOnFileABugLink()
43 | {
44 | ObjectRepository.hPage = new HomePage(ObjectRepository.Driver);
45 | ObjectRepository.lPage = ObjectRepository.hPage.NavigateToLogin();
46 | }
47 |
48 | [When(@"I provide the username, password and click on Login button")]
49 | public void WhenIProvideTheUsernamePasswordAndClickOnLoginButton()
50 | {
51 | ePage = lPage.Login(ObjectRepository.Config.GetUsername(), ObjectRepository.Config.GetPassword());
52 | }
53 |
54 | [When(@"I click on Logout button")]
55 | public void WhenIClickOnLogoutButton()
56 | {
57 | ObjectRepository.ePage.Logout();
58 | }
59 |
60 | [When(@"I click on Testng link")]
61 | public void WhenIClickOnTestngLink()
62 | {
63 | bPage = ePage.NavigateToDetail();
64 | }
65 |
66 |
67 | [When(@"I provide the severity , harware , platform and summary")]
68 | public void WhenIProvideTheSeverityHarwarePlatformAndSummary()
69 | {
70 | bPage.SelectFromCombo("critical", "Macintosh", "Other");
71 | bPage.TypeIn("Summary 1","Desc - 1");
72 | }
73 |
74 | #endregion
75 |
76 | #region Then
77 |
78 | [Then(@"User should be at Login Page")]
79 | public void ThenUserShouldBeAtLoginPage()
80 | {
81 | Assert.AreEqual("Log in to Bugzilla",ObjectRepository.lPage.Title);
82 | //AssertHelper.AreEqual("Log in to Bugzilla 1", lPage.Title);
83 | }
84 |
85 | [Then(@"User Should be at Enter Bug page")]
86 | public void ThenUserShouldBeAtEnterBugPage()
87 | {
88 | Assert.AreEqual("Enter Bug",ObjectRepository.ePage.Title);
89 | }
90 |
91 | [Then(@"User should be logged out and should be at Home Page")]
92 | public void ThenUserShouldBeLoggedOutAndShouldBeAtHomePage()
93 | {
94 | Assert.IsTrue(GenericHelper.IsElemetPresent(By.Id("welcome")));
95 | }
96 |
97 | [Then(@"User Should be at Bug Detail page")]
98 | public void ThenUserShouldBeAtBugDetailPage()
99 | {
100 | Assert.AreEqual("Enter Bug: Testng",ObjectRepository.bPage.Title);
101 | }
102 |
103 |
104 | [Then(@"Bug should get created")]
105 | public void ThenBugShouldGetCreated()
106 | {
107 | Assert.IsTrue(GenericHelper.IsElemetPresent(By.Id("commit_top")));
108 | }
109 |
110 |
111 | #endregion
112 |
113 | #region And
114 |
115 | [When(@"click on Submit button")]
116 | public void WhenClickOnSubmitButton()
117 | {
118 | bPage.ClickSubmit();
119 | }
120 |
121 | [Then(@"User should be at Search page")]
122 | public void ThenUserShouldBeAtSearchPage()
123 | {
124 | }
125 |
126 | #endregion
127 |
128 |
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/StepDefinition/TestFeature2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using TechTalk.SpecFlow;
6 |
7 | namespace SeleniumWebdriver.StepDefinition
8 | {
9 | [Binding]
10 | public sealed class TestFeature2
11 | {
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/AngularScript/TestProtractor.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using OpenQA.Selenium;
3 | using Protractor;
4 | using SeleniumWebdriver.Settings;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading;
10 | using System.Threading.Tasks;
11 |
12 | namespace SeleniumWebdriver.TestScript.AngularScript
13 | {
14 | [TestClass]
15 | public class TestProtractor
16 | {
17 | [TestMethod]
18 | public void TestMethod()
19 | {
20 | ObjectRepository.Driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(60);
21 | ObjectRepository.Driver.Navigate().GoToUrl("https://www.copaair.com/en/web/us");
22 | var ngDriver = new NgWebDriver(ObjectRepository.Driver);
23 | var list = ngDriver.FindElements(NgBy.Repeater("item in desktopBookingTabs"));
24 | var element = list.First((x) =>
25 | {
26 | return x.Text.Contains("Manage your booking");
27 | });
28 |
29 | element.Click();
30 | ngDriver.WaitForAngular();
31 |
32 | ngDriver.FindElement(NgBy.Model("remoteSearchCriteria.travelerLastName")).SendKeys("Thisistest");
33 | ngDriver.FindElement(NgBy.Model("bookingReference")).SendKeys("121421445252");
34 | ngDriver.FindElement(By.Id("sendReservationForm")).Click();
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | Thread.Sleep(TimeSpan.FromSeconds(5));
43 |
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/AutoSuggest/TestAutoSuggest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using Microsoft.VisualStudio.TestTools.UnitTesting;
9 | using OpenQA.Selenium;
10 | using SeleniumWebdriver.ComponentHelper;
11 | using SeleniumWebdriver.Settings;
12 |
13 | namespace SeleniumWebdriver.TestScript.AutoSuggest
14 | {
15 | [TestClass]
16 | public class TestAutoSuggest
17 | {
18 | [TestMethod]
19 | public void TestAutoSug()
20 | {
21 | NavigationHelper.NavigateToUrl("http://demos.telerik.com/kendo-ui/autocomplete/index");
22 | //step - 1 to supply the initial string
23 | IWebElement ele = ObjectRepository.Driver.FindElement(By.Id("countries"));
24 | ele.SendKeys("a");
25 | Thread.Sleep(1000);
26 | //step -2 wait for auto suggest list
27 |
28 | var wait = GenericHelper.GetWebdriverWait(TimeSpan.FromSeconds(40));
29 | IList elements = wait.Until(GetAllElements(By.XPath("//ul[@id='countries_listbox']/child::li")));
30 | foreach (var ele1 in elements)
31 | {
32 | if (ele1.Text.Equals("Austria"))
33 | {
34 | ele1.Click();
35 | }
36 | }
37 |
38 | Thread.Sleep(5000);
39 | }
40 |
41 | [TestMethod]
42 | public void MultiSelect()
43 | {
44 | NavigationHelper.NavigateToUrl("http://demos.telerik.com/kendo-ui/multiselect/index");
45 | //step - 1 to click on the text box
46 | IWebElement ele = ObjectRepository.Driver.FindElement(By.XPath("//div[@id='example']/child::div/descendant::div[position()=2]"));
47 | List eleList = new List() { 10,12,14 };
48 | //step - 2 wait for list
49 | ele.Click();
50 | var wait = GenericHelper.GetWebdriverWait(TimeSpan.FromSeconds(40));
51 | var dropdownlist = wait.Until(GetAllElement(By.XPath("//ul[@id='required_listbox']/child::li")));
52 | foreach (var str in eleList)
53 | {
54 | ele.Click();
55 |
56 | dropdownlist = wait.Until(GetAllElement(By.XPath("//ul[@id='required_listbox']/child::li[position()="+ str + "]")));
57 | Thread.Sleep(1000);
58 |
59 | dropdownlist.Click();
60 | }
61 |
62 | Thread.Sleep(5000);
63 |
64 | }
65 | private Func GetAllElement(By locator)
66 | {
67 | return ((x) =>
68 | {
69 | return x.FindElement(locator);
70 | });
71 | }
72 |
73 | private Func> GetAllElements(By locator)
74 | {
75 | return ((x) =>
76 | {
77 | return x.FindElements(locator);
78 | });
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/BrowserActions/TestBrowserActions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using SeleniumWebdriver.ComponentHelper;
9 | using SeleniumWebdriver.Settings;
10 |
11 | namespace SeleniumWebdriver.TestScript.BrowserActions
12 | {
13 | [TestClass]
14 | public class TestBrowserActions
15 | {
16 | [TestMethod]
17 | public void TestActions()
18 | {
19 | NavigationHelper.NavigateToUrl("https://www.udemy.com/bdd-with-selenium-webdriver-and-speckflow-using-c/");
20 | ButtonHelper.ClickButton(By.XPath("//div[@id='related']/descendant::a[position()=1]"));
21 | BrowserHelper.GoBack();
22 | BrowserHelper.Forward();
23 | BrowserHelper.RefreshPage();
24 |
25 |
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Button/HandleButton.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using SeleniumWebdriver.ComponentHelper;
9 | using SeleniumWebdriver.Settings;
10 |
11 | namespace SeleniumWebdriver.TestScript.Button
12 | {
13 | [TestClass]
14 | public class HandleButton
15 | {
16 | [TestMethod]
17 | public void TestButton()
18 | {
19 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
20 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
21 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
22 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
23 | //IWebElement element = ObjectRepository.Driver.FindElement(By.Id("log_in"));
24 | // element.Click();
25 | Console.WriteLine("Enabled : {0}",ButtonHelper.IsButtonEnabled(By.Id("log_in")));
26 | Console.WriteLine("Button Text : {0}",ButtonHelper.GetButtonText(By.Id("log_in")));
27 | ButtonHelper.ClickButton(By.Id("log_in"));
28 |
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/CheckBox/TestCheckBox.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing.Imaging;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.VisualStudio.TestTools.UnitTesting;
9 | using OpenQA.Selenium;
10 | using OpenQA.Selenium.Support.Extensions;
11 | using SeleniumWebdriver.ComponentHelper;
12 | using SeleniumWebdriver.Settings;
13 |
14 | namespace SeleniumWebdriver.TestScript.CheckBox
15 | {
16 | [TestClass]
17 | public class TestCheckBox
18 | {
19 | [TestMethod,TestCategory("Smoke")]
20 | public void TestBox()
21 | {
22 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
23 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
24 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
25 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
26 | // TextBoxHelper.ClearTextBox(By.Id("Bugzilla_login"));
27 | IWebElement ele = ObjectRepository.Driver.FindElement(By.Id("Bugzilla_login"));
28 | Console.WriteLine(ele.Text);
29 | Console.WriteLine(CheckBoxHelper.IsCheckBoxChecked(By.Id("Bugzilla_restrictlogin")));
30 | CheckBoxHelper.CheckedCheckBox(By.Id("Bugzilla_restrictlogin"));
31 | Console.WriteLine(CheckBoxHelper.IsCheckBoxChecked(By.Id("Bugzilla_restrictlogin")));
32 | ButtonHelper.Logout();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/DefaultWait/HandleDefaultWait.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using OpenQA.Selenium.Support.UI;
10 | using SeleniumWebdriver.ComponentHelper;
11 | using SeleniumWebdriver.Settings;
12 |
13 | namespace SeleniumWebdriver.TestScript.DefaultWait
14 | {
15 | [TestClass]
16 | public class HandleDefaultWait
17 | {
18 | [TestMethod]
19 | public void TestDefaultWait()
20 | {
21 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
22 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
23 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
24 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
25 | ButtonHelper.ClickButton(By.Id("log_in"));
26 | LinkHelper.ClickLink(By.LinkText("Testng"));
27 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(1));
28 |
29 | GenericHelper.WaitForWebElement(By.Id("bug_severity"), TimeSpan.FromSeconds(50));
30 | IWebElement ele = GenericHelper.WaitForWebElementInPage(By.Id("bug_severity"), TimeSpan.FromSeconds(50));
31 |
32 | DefaultWait wait = new DefaultWait(ObjectRepository.Driver.FindElement(By.Id("bug_severity")));
33 | wait.PollingInterval = TimeSpan.FromMilliseconds(200);
34 | wait.Timeout = TimeSpan.FromSeconds(50);
35 | wait.IgnoreExceptionTypes(typeof(NoSuchElementException),typeof(ElementNotVisibleException));
36 | Console.WriteLine("After wait : {0}",wait.Until(changeofvalue()));
37 | }
38 |
39 | private Func changeofvalue()
40 | {
41 | return ((x) =>
42 | {
43 | Console.WriteLine("Waiting for value change");
44 | SelectElement select = new SelectElement(x);
45 | if (select.SelectedOption.Text.Equals("major"))
46 | return select.SelectedOption.Text;
47 | return null;
48 | });
49 | }
50 |
51 | [TestMethod]
52 | public void TestFreeCharge()
53 | {
54 | NavigationHelper.NavigateToUrl("https://www.freecharge.in/#");
55 | LinkHelper.ClickLink(By.XPath("//ul[@id='couponTypes']/descendant::a[text()='Mobile']"));
56 | Assert.IsTrue(GenericHelper.WaitForWebElement(By.XPath("//legend[contains(text(),'Enter your mobile number')]"), TimeSpan.FromSeconds(50)));
57 | Thread.Sleep(3000);
58 | LinkHelper.ClickLink(By.XPath("//a[contains(text(),'Dth')]"));
59 | Assert.IsTrue(GenericHelper.WaitForWebElement(By.XPath("//legend[contains(text(),'Pay your DTH bill. Which operator?')]"), TimeSpan.FromSeconds(50)));
60 | Thread.Sleep(3000);
61 | LinkHelper.ClickLink(By.XPath("//a[contains(text(),'Datacard')]"));
62 | Assert.IsTrue(GenericHelper.WaitForWebElement(By.XPath("//legend[contains(text(),'Enter your datacard number')]"), TimeSpan.FromSeconds(50)));
63 | Thread.Sleep(3000);
64 | LinkHelper.ClickLink(By.XPath("//a[contains(text(),'Metro')]"));
65 | Assert.IsTrue(GenericHelper.WaitForWebElement(By.XPath("//legend[contains(text(),'Which Operator?')]"), TimeSpan.FromSeconds(50)));
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/EmptyDataTable/EmptyDataTable.feature:
--------------------------------------------------------------------------------
1 | Feature: EmptyDataTable
2 |
3 | Scenario Outline: To test the data example with empty column vlaue
4 | Given User read "" and "" from examples
5 | Examples:
6 | | name | password |
7 | | pqr | sdf |
8 | | abc | |
9 | | | fgh |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/EmptyDataTable/EmptyDataTable.feature.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This code was generated by SpecFlow (http://www.specflow.org/).
4 | // SpecFlow Version:2.4.0.0
5 | // SpecFlow Generator Version:2.4.0.0
6 | //
7 | // Changes to this file may cause incorrect behavior and will be lost if
8 | // the code is regenerated.
9 | //
10 | // ------------------------------------------------------------------------------
11 | #region Designer generated code
12 | #pragma warning disable
13 | namespace SeleniumWebdriver.TestScript.EmptyDataTable
14 | {
15 | using TechTalk.SpecFlow;
16 |
17 |
18 | [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.4.0.0")]
19 | [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
20 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
21 | public partial class EmptyDataTableFeature
22 | {
23 |
24 | private static TechTalk.SpecFlow.ITestRunner testRunner;
25 |
26 | private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext;
27 |
28 | #line 1 "EmptyDataTable.feature"
29 | #line hidden
30 |
31 | public virtual Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext
32 | {
33 | get
34 | {
35 | return this._testContext;
36 | }
37 | set
38 | {
39 | this._testContext = value;
40 | }
41 | }
42 |
43 | [Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()]
44 | public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)
45 | {
46 | testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(null, 0);
47 | TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "EmptyDataTable", null, ProgrammingLanguage.CSharp, ((string[])(null)));
48 | testRunner.OnFeatureStart(featureInfo);
49 | }
50 |
51 | [Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()]
52 | public static void FeatureTearDown()
53 | {
54 | testRunner.OnFeatureEnd();
55 | testRunner = null;
56 | }
57 |
58 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()]
59 | public virtual void TestInitialize()
60 | {
61 | if (((testRunner.FeatureContext != null)
62 | && (testRunner.FeatureContext.FeatureInfo.Title != "EmptyDataTable")))
63 | {
64 | global::SeleniumWebdriver.TestScript.EmptyDataTable.EmptyDataTableFeature.FeatureSetup(null);
65 | }
66 | }
67 |
68 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()]
69 | public virtual void ScenarioTearDown()
70 | {
71 | testRunner.OnScenarioEnd();
72 | }
73 |
74 | public virtual void ScenarioInitialize(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
75 | {
76 | testRunner.OnScenarioInitialize(scenarioInfo);
77 | testRunner.ScenarioContext.ScenarioContainer.RegisterInstanceAs(_testContext);
78 | }
79 |
80 | public virtual void ScenarioStart()
81 | {
82 | testRunner.OnScenarioStart();
83 | }
84 |
85 | public virtual void ScenarioCleanup()
86 | {
87 | testRunner.CollectScenarioErrors();
88 | }
89 |
90 | public virtual void ToTestTheDataExampleWithEmptyColumnVlaue(string name, string password, string[] exampleTags)
91 | {
92 | TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("To test the data example with empty column vlaue", null, exampleTags);
93 | #line 3
94 | this.ScenarioInitialize(scenarioInfo);
95 | this.ScenarioStart();
96 | #line 4
97 | testRunner.Given(string.Format("User read \"{0}\" and \"{1}\" from examples", name, password), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
98 | #line hidden
99 | this.ScenarioCleanup();
100 | }
101 |
102 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
103 | [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("To test the data example with empty column vlaue: pqr")]
104 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "EmptyDataTable")]
105 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "pqr")]
106 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:name", "pqr")]
107 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:password", "sdf")]
108 | public virtual void ToTestTheDataExampleWithEmptyColumnVlaue_Pqr()
109 | {
110 | #line 3
111 | this.ToTestTheDataExampleWithEmptyColumnVlaue("pqr", "sdf", ((string[])(null)));
112 | #line hidden
113 | }
114 |
115 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
116 | [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("To test the data example with empty column vlaue: abc")]
117 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "EmptyDataTable")]
118 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "abc")]
119 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:name", "abc")]
120 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:password", "")]
121 | public virtual void ToTestTheDataExampleWithEmptyColumnVlaue_Abc()
122 | {
123 | #line 3
124 | this.ToTestTheDataExampleWithEmptyColumnVlaue("abc", "", ((string[])(null)));
125 | #line hidden
126 | }
127 |
128 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
129 | [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("To test the data example with empty column vlaue: ")]
130 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "EmptyDataTable")]
131 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:name", "")]
132 | [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:password", "fgh")]
133 | public virtual void ToTestTheDataExampleWithEmptyColumnVlaue_()
134 | {
135 | #line 3
136 | this.ToTestTheDataExampleWithEmptyColumnVlaue("", "fgh", ((string[])(null)));
137 | #line hidden
138 | }
139 | }
140 | }
141 | #pragma warning restore
142 | #endregion
143 |
144 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/EmptyDataTable/EmptyDataTableStepDfn.cs:
--------------------------------------------------------------------------------
1 | using SeleniumWebdriver.ComponentHelper;
2 | using SeleniumWebdriver.Settings;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using TechTalk.SpecFlow;
8 |
9 | namespace SeleniumWebdriver.TestScript.EmptyDataTable
10 | {
11 | [Binding]
12 | public sealed class EmptyDataTableStepDfn
13 | {
14 | // For additional details on SpecFlow step definitions see https://go.specflow.org/doc-stepdef
15 |
16 | private readonly ScenarioContext context;
17 |
18 | public EmptyDataTableStepDfn(ScenarioContext injectedContext)
19 | {
20 | context = injectedContext;
21 | }
22 |
23 | [Given(@"User read ""(.*)"" and ""(.*)"" from examples")]
24 | public void GivenUserReadAndFromExamples(string user, string password)
25 | {
26 | NavigationHelper.NavigateToUrl("https://www.udemy.com");
27 | var title = ObjectRepository.Driver.Title;
28 | Console.WriteLine(string.Format("Name : {0} and Password : {1}", user, password));
29 | Console.WriteLine("Title : " + title);
30 | }
31 |
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/FileUpload/TestFileUploadAction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 | using Microsoft.VisualStudio.TestTools.UnitTesting;
10 | using OpenQA.Selenium;
11 | using SeleniumWebdriver.ComponentHelper;
12 | using SeleniumWebdriver.Settings;
13 |
14 | namespace SeleniumWebdriver.TestScript.FileUpload
15 | {
16 | [TestClass]
17 | public class TestFileUploadAction
18 | {
19 | [TestMethod,TestCategory("Smoke")]
20 | [DeploymentItem("Resources")]
21 | public void TestUpload()
22 | {
23 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
24 | ButtonHelper.ClickButton(By.Id("enter_bug"));
25 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
26 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
27 | ButtonHelper.ClickButton(By.Id("log_in"));
28 | ButtonHelper.ClickButton(By.LinkText("Testng"));
29 | ButtonHelper.ClickButton(By.XPath("//div[@id='attachment_false']/input"));
30 | GenericHelper.WaitForWebElement(By.Id("data"), TimeSpan.FromSeconds(30));
31 | ButtonHelper.ClickButton(By.Id("data"));
32 |
33 | Console.WriteLine("\"" + Directory.GetCurrentDirectory() + @"\ExcelData.xlsx" + "\"");
34 |
35 | var processinfo = new ProcessStartInfo()
36 | {
37 | FileName = "FileUpload.exe",
38 | Arguments = "\"" + Directory.GetCurrentDirectory() + @"\ExcelData.xlsx" + "\""
39 | };
40 |
41 | //processinfo.FileName = @"F:\Auto\FileUpload.exe";
42 | //processinfo.Arguments = @"C:\downloads\ExcelData.xlsx";
43 |
44 | //Process process = Process.Start(processinfo);
45 | //process.WaitForExit();
46 | //process.Close();
47 |
48 | using (var process = Process.Start(processinfo))
49 | {
50 | process.WaitForExit();
51 | }
52 |
53 |
54 | Thread.Sleep(5000);
55 | ButtonHelper.Logout();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/FindElements/HandleElements.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using OpenQA.Selenium.Support.UI;
10 | using SeleniumWebdriver.ComponentHelper;
11 | using SeleniumWebdriver.Settings;
12 |
13 | namespace SeleniumWebdriver.TestScript.FindElements
14 | {
15 | [TestClass]
16 | public class HandleElements
17 | {
18 | [TestMethod]
19 | public void GetAllElements()
20 | {
21 |
22 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
23 | ReadOnlyCollection elements = ObjectRepository.Driver.FindElements(By.XPath("//input"));
24 | ReadOnlyCollection elements2 = ObjectRepository.Driver.FindElements(By.Id("123"));
25 | foreach (var ele in elements)
26 | {
27 | Console.WriteLine("ID : {0}",ele.GetAttribute("id"));
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Form/TestSubmitForm.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using OpenQA.Selenium;
3 | using OpenQA.Selenium.Support.UI;
4 | using SeleniumWebdriver.ComponentHelper;
5 | using SeleniumWebdriver.Settings;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading;
11 | using System.Threading.Tasks;
12 | using ExpectedConditions = SeleniumExtras.WaitHelpers.ExpectedConditions;
13 |
14 | namespace SeleniumWebdriver.TestScript.Form
15 | {
16 | [TestClass]
17 | public class TestSubmitForm
18 | {
19 | [TestMethod]
20 | public void TestSubmit()
21 | {
22 | NavigationHelper.NavigateToUrl("https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit");
23 | WebDriverWait wait = GetWait();
24 | wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(OpenQA.Selenium.By.Id("iframeResult")));
25 | TextBoxHelper.TypeInTextBox(By.CssSelector("[name='firstname']"), "Testing");
26 | Thread.Sleep(2000);
27 | Assert.AreEqual("MickeyTesting", GenericHelper.GetElement(By.CssSelector("[name='firstname']")).GetAttribute("value"));
28 | AssertData(By.CssSelector("[name='firstname']"), "MickeyTesting");
29 |
30 | Dictionary data = new Dictionary();
31 | data.Add(By.CssSelector("[name='firstname']"), "MickeyTesting");
32 | data.Add(By.CssSelector("[name='firstname']"), "MickeyTesting");
33 | data.Add(By.CssSelector("[name='firstname']"), "MickeyTesting");
34 |
35 | AssertData(data);
36 | }
37 |
38 | private void AssertData(By locator,string expectedvalue)
39 | {
40 | Assert.AreEqual(expectedvalue, GenericHelper.GetElement(locator).GetAttribute("value"));
41 | }
42 |
43 | private void AssertData(Dictionary expectedDataSet)
44 | {
45 | foreach(By locator in expectedDataSet.Keys)
46 | {
47 | try
48 | {
49 | Assert.AreEqual(expectedDataSet[locator], GenericHelper.GetElement(locator).GetAttribute("value"));
50 | }
51 | catch(AssertFailedException)
52 | {
53 | //Can be replace by logger
54 | Console.Write(String.Format($"Data mismatch for locator {0} and value {1}"), locator, expectedDataSet[locator]);
55 | }
56 |
57 | }
58 | }
59 |
60 | private WebDriverWait GetWait()
61 | {
62 | WebDriverWait wait = new WebDriverWait(ObjectRepository.Driver, TimeSpan.FromSeconds(60))
63 | {
64 | PollingInterval = TimeSpan.FromMilliseconds(250)
65 | };
66 | return wait;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Grid/TestWebTable.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using SeleniumWebdriver.ComponentHelper;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace SeleniumWebdriver.TestScript.Grid
10 | {
11 | [TestClass]
12 | public class TestWebTable
13 | {
14 | [TestMethod]
15 | public void TestGrid()
16 | {
17 | NavigationHelper.NavigateToUrl("http://demos.telerik.com/kendo-ui/grid/custom-command");
18 |
19 | /* for (int row = 1; row <= 6; row++)
20 | {
21 | for (int col = 1; col <= 5; col++)
22 | {
23 | //string xpath = "//table[@id='wb-auto-1']//tbody//tr[" + row + "]//td[" + col + "]";
24 | //var xpath = string.Format("//table[@id='wb-auto-1']//tbody//tr[{0}]//td[{1}]", row, col);
25 | var xpath = $"//table[@id='wb-auto-1']//tbody//tr[{row}]//td[{col}]";
26 | //Console.WriteLine(xpath);
27 | Console.Write(ObjectRepository.Driver.FindElement(By.XPath(xpath)).Text);
28 | }
29 | Console.WriteLine();
30 | }*/
31 | /* Console.WriteLine(GridHelper.GetColumnValue("//table[@id='wb-auto-1']", 3, 3));
32 | IList data = GridHelper.GetAllValues("//table[@id='wb-auto-1']");
33 | foreach (var str in data)
34 | {
35 | Console.WriteLine(str);
36 | }*/
37 |
38 | GridHelper.ClickButtonInGrid("//div[@class='k-grid-content k-auto-scrollable']//table[@role='grid']", 2, 3);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/HandleDropDown/DropDownList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using OpenQA.Selenium.Support.UI;
9 | using SeleniumWebdriver.ComponentHelper;
10 | using SeleniumWebdriver.Settings;
11 |
12 | namespace SeleniumWebdriver.TestScript.HandleDropDown
13 | {
14 | [TestClass]
15 | public class DropDownList
16 | {
17 | [TestMethod]
18 | public void TestList()
19 | {
20 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
21 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
22 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
23 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
24 | ButtonHelper.ClickButton(By.Id("log_in"));
25 | LinkHelper.ClickLink(By.LinkText("Testng"));
26 | //IWebElement element = ObjectRepository.Driver.FindElement(By.Id("bug_severity"));
27 | //SelectElement select = new SelectElement(element);
28 | //select.SelectByIndex(2);
29 | //select.SelectByValue("normal");
30 | //select.SelectByText("blocker");
31 | //Console.WriteLine("Selected value : {0}",select.SelectedOption.Text);
32 | //IList list = select.Options;
33 | //foreach (IWebElement ele in list)
34 | //{
35 | // Console.WriteLine("Value : {0}, Text : {1}",ele.GetAttribute("value"),ele.Text);
36 | //}
37 | ComboBoxHelper.SelectElement(By.Id("bug_severity"),2);
38 | ComboBoxHelper.SelectElement(By.Id("bug_severity"), "blocker");
39 | foreach (string str in ComboBoxHelper.GetAllItem(By.Id("bug_severity")))
40 | {
41 | Console.WriteLine("Text : {0}",str);
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/HyperLink/TestHyperLink.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using SeleniumWebdriver.ComponentHelper;
10 | using SeleniumWebdriver.Settings;
11 |
12 | namespace SeleniumWebdriver.TestScript.HyperLink
13 | {
14 | [TestClass]
15 | public class TestHyperLink
16 | {
17 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof (TestHyperLink));
18 |
19 | [TestMethod,TestCategory("Smoke")]
20 | public void ClickLink()
21 | {
22 | try
23 | {
24 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
25 | //IWebElement element = ObjectRepository.Driver.FindElement(By.LinkText("File a Bug"));
26 | // element.Click();
27 |
28 | // IWebElement pelement = ObjectRepository.Driver.FindElement(By.PartialLinkText("File"));
29 | // pelement.Click();
30 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
31 | LinkHelper.ClickLink(By.PartialLinkText("File"));
32 | }
33 | catch (Exception exception)
34 | {
35 | Logger.Error(exception.StackTrace);
36 | GenericHelper.TakeScreenShot();
37 | throw;
38 | }
39 |
40 |
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/JavaScript/TestJavaScriptClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using SeleniumWebdriver.ComponentHelper;
9 | using SeleniumWebdriver.Settings;
10 |
11 | namespace SeleniumWebdriver.TestScript.JavaScript
12 | {
13 | [TestClass]
14 | public class TestJavaScriptClass
15 | {
16 | [TestMethod]
17 | public void TestJavaScript()
18 | {
19 | NavigationHelper.NavigateToUrl("https://www.udemy.com/bdd-with-selenium-webdriver-and-speckflow-using-c/");
20 | //LinkHelper.ClickLink(By.LinkText("File a Bug"));
21 | IJavaScriptExecutor executor = ((IJavaScriptExecutor) ObjectRepository.Driver);
22 | //executor.ExecuteScript("document.getElementById('Bugzilla_login').value='rahul@bugzila.com'");
23 | //executor.ExecuteScript("document.getElementById('Bugzilla_password').value='rathore'");
24 | //executor.ExecuteScript("document.getElementById('log_in').click()");
25 |
26 | IWebElement element = ObjectRepository.Driver.FindElement(By.XPath("//div[@id='related']/ul/li[1]/a"));
27 | executor.ExecuteScript("window.scrollTo(0," + element.Location.Y + ")");
28 | element.Click();
29 |
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Keyword/TestKeywordDriven.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using SeleniumWebdriver.Keyword;
8 |
9 | namespace SeleniumWebdriver.TestScript.Keyword
10 | {
11 | [TestClass]
12 | public class TestKeywordDriven
13 | {
14 | [TestMethod]
15 | public void TestKeyWord()
16 | {
17 | var keyDataEngine = new DataEngine();
18 | keyDataEngine.ExecuteScript(@"C:\Users\rahul.rathore\Desktop\Cucumber\Keyword2.xlsx", "TC01");
19 | }
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Log4Net/TestLogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using log4net;
7 | using log4net.Appender;
8 | using log4net.Config;
9 | using log4net.Core;
10 | using log4net.Layout;
11 | using Microsoft.VisualStudio.TestTools.UnitTesting;
12 | using SeleniumWebdriver.ComponentHelper;
13 |
14 | namespace SeleniumWebdriver.TestScript.Log4Net
15 | {
16 | [TestClass]
17 | public class TestLogger
18 | {
19 | [TestMethod]
20 | public void TestLog4Net()
21 | {
22 | // 1. To create the layout
23 | // 2. Use this lay out in the appender
24 | // 3. Initialize the configuration
25 | // 4. Get the instance of the logger
26 |
27 | // var patterLayout = new PatternLayout();
28 | // patterLayout.ConversionPattern = "%date{dd-MMM-yyyy-HH:mm:ss} [%class] [%level] [%method] - %message%newline";
29 | // patterLayout.ActivateOptions();
30 |
31 | // var consoleAppender = new ConsoleAppender()
32 | // {
33 | // Name = "ConsoleAppender",
34 | // Layout = patterLayout,
35 | // Threshold = Level.Error
36 | // };
37 | //// consoleAppender.ActivateOptions();
38 | // var fileAppender = new FileAppender()
39 | // {
40 | // Name = "fileAppender",
41 | // Layout = patterLayout,
42 | // Threshold = Level.All,
43 | // AppendToFile = true,
44 | // File = "FileLogger.log",
45 | // };
46 | // fileAppender.ActivateOptions();
47 |
48 | // var rollingAppender = new RollingFileAppender()
49 | // {
50 | // Name = "Rolling File Appender",
51 | // AppendToFile = true,
52 | // File = "RollingFile.log",
53 | // Layout = patterLayout,
54 | // Threshold = Level.All,
55 | // MaximumFileSize = "1MB",
56 | // MaxSizeRollBackups = 15 //file1.log,file2.log.....file15.log
57 | // };
58 | // rollingAppender.ActivateOptions();
59 |
60 |
61 | // BasicConfigurator.Configure(consoleAppender, fileAppender,rollingAppender);
62 |
63 | // ILog Logger = LogManager.GetLogger(typeof (TestLogger));
64 |
65 | ILog Logger = Log4NetHelper.GetLogger(typeof (TestLogger));
66 |
67 | for (var i = 0; i < 3000; i++)
68 | {
69 | Logger.Debug("This is Debug Information");
70 | Logger.Info("This is Info Information");
71 | Logger.Warn("This is Warn Information");
72 | Logger.Error("This is Error Information");
73 | Logger.Fatal("This is Fatal Information");
74 | }
75 |
76 |
77 | }
78 |
79 | [TestMethod]
80 | public void TestLog4NetSec()
81 | {
82 | //Log4NetHelper.Layout = "%message%newline";
83 | //ILog Logger = Log4NetHelper.GetLogger(typeof(TestLogger));
84 | ILog Logger = Log4NetHelper.GetXmlLogger(typeof (TestLogger));
85 |
86 | for (var i = 0; i < 3000; i++)
87 | {
88 | Logger.Debug("This is Debug Information");
89 | Logger.Info("This is Info Information");
90 | Logger.Warn("This is Warn Information");
91 | Logger.Error("This is Error Information");
92 | Logger.Fatal("This is Fatal Information");
93 | }
94 |
95 |
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/MouseAction/TestMouseAction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using OpenQA.Selenium.Interactions;
10 | using SeleniumWebdriver.ComponentHelper;
11 | using SeleniumWebdriver.Settings;
12 |
13 | namespace SeleniumWebdriver.TestScript.MouseAction
14 | {
15 | [TestClass]
16 | public class TestMouseAction
17 | {
18 | [TestMethod]
19 | public void TestContextClick()
20 | {
21 | NavigationHelper.NavigateToUrl("http://demos.telerik.com/kendo-ui/dragdrop/events");
22 | Actions act = new Actions(ObjectRepository.Driver);
23 | IWebElement ele = ObjectRepository.Driver.FindElement(By.Id("draggable"));
24 |
25 |
26 | act.ContextClick(ele)
27 | .Build()
28 | .Perform();
29 |
30 | Thread.Sleep(5000);
31 | }
32 |
33 | [TestMethod]
34 | public void DranNDrop()
35 | {
36 | NavigationHelper.NavigateToUrl("http://demos.telerik.com/kendo-ui/dragdrop/events");
37 | Actions act = new Actions(ObjectRepository.Driver);
38 | IWebElement src = ObjectRepository.Driver.FindElement(By.Id("draggable"));
39 | IWebElement tar = ObjectRepository.Driver.FindElement(By.Id("droptarget"));
40 |
41 | act.DragAndDrop(src,tar)
42 | .Build()
43 | .Perform();
44 |
45 | Thread.Sleep(4000);
46 | }
47 |
48 |
49 | [TestMethod]
50 | public void TestClicknHold()
51 | {
52 | NavigationHelper.NavigateToUrl("http://demos.telerik.com/kendo-ui/sortable/index");
53 | Actions act = new Actions(ObjectRepository.Driver);
54 | IWebElement ele = ObjectRepository.Driver.FindElement(By.XPath("//ul[@id='sortable-basic']/li[12]"));
55 | IWebElement tar = ObjectRepository.Driver.FindElement(By.XPath("//ul[@id='sortable-basic']/li[2]/span"));
56 | act.ClickAndHold(ele)
57 | .MoveToElement(tar,0,30)
58 | .Release()
59 | .Build()
60 | .Perform();
61 |
62 | Thread.Sleep(10000);
63 | }
64 |
65 | [TestMethod]
66 | public void TestKeyBoard()
67 | {
68 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
69 | Actions act = new Actions(ObjectRepository.Driver);
70 | // ctrl + t
71 | //act.KeyDown(Keys.LeftControl)
72 | // .SendKeys("t")
73 | // .KeyUp(Keys.LeftControl)
74 | // .Build()
75 | // .Perform();
76 |
77 | // ctrl + shift +a
78 |
79 | //act.KeyDown(Keys.LeftControl)
80 | // .KeyDown(Keys.LeftShift)
81 | // .SendKeys("a")
82 | // .KeyUp(Keys.LeftShift)
83 | // .KeyUp(Keys.LeftControl)
84 | // .Build()
85 | // .Perform();
86 |
87 | // alt + f + x
88 |
89 | //act.KeyDown(Keys.LeftAlt)
90 | // .SendKeys("f")
91 | // .SendKeys("x")
92 | // .Build()
93 | // .Perform();
94 |
95 | IWebElement ele1 = ObjectRepository.Driver.FindElement(By.Id("quicksearch_top"));
96 | IWebElement ele2 = ObjectRepository.Driver.FindElement(By.Id("quicksearch_main"));
97 | ele1.SendKeys("fx");
98 |
99 | act.KeyDown(ele2,Keys.LeftShift)
100 | .SendKeys(ele2,"f")
101 | .SendKeys(ele2,"x")
102 | .KeyUp(ele2,Keys.LeftShift)
103 | .Build()
104 | .Perform();
105 | Thread.Sleep(5000);
106 |
107 | }
108 |
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/MultipleBrowser/TestMultipleBrowserWindow.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using SeleniumWebdriver.ComponentHelper;
10 | using SeleniumWebdriver.Settings;
11 |
12 | namespace SeleniumWebdriver.TestScript.MultipleBrowser
13 | {
14 | [TestClass]
15 | public class TestMultipleBrowserWindow
16 | {
17 | [TestMethod]
18 | public void TestMutipleBrowserWindow()
19 | {
20 | NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/js_popup.asp");
21 | GenericHelper.TakeScreenShot();
22 | ButtonHelper.ClickButton(By.XPath("//div[@id='main']/descendant::a[position()=3]"));
23 | GenericHelper.TakeScreenShot();
24 | BrowserHelper.SwitchToWindow(1);
25 | NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/js_popup.asp");
26 | GenericHelper.TakeScreenShot();
27 | ButtonHelper.ClickButton(By.XPath("//div[@id='main']/descendant::a[position()=3]"));
28 | BrowserHelper.SwitchToWindow(2);
29 | GenericHelper.TakeScreenShot();
30 | ButtonHelper.ClickButton(By.XPath("//div[@class='textarea']/descendant::button"));
31 | GenericHelper.TakeScreenShot();
32 | BrowserHelper.SwitchToParent();
33 | }
34 |
35 | [TestMethod]
36 | public void TestFrame()
37 | {
38 | NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/js_popup.asp");
39 | ButtonHelper.ClickButton(By.XPath("//div[@id='main']/descendant::a[position()=3]"));
40 | BrowserHelper.SwitchToWindow(1);
41 | ButtonHelper.ClickButton(By.XPath("//div[@class='textarea']/descendant::button"));
42 | BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
43 | ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
44 | var a = ObjectRepository.Driver.SwitchTo().Alert().Text;
45 | ObjectRepository.Driver.SwitchTo().Alert().Accept();
46 | ObjectRepository.Driver.SwitchTo().DefaultContent();
47 | TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
48 | TextBoxHelper.TypeInTextBox(By.Id("textareaCode"), a);
49 |
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/NLogScript/NLogExample.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 |
4 | namespace SeleniumWebdriver.TestScript.NLogScript
5 | {
6 | [TestClass]
7 | public class NLogExample
8 | {
9 | private NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
10 |
11 | [TestMethod]
12 | public void TestNLogMethod()
13 | {
14 | for (int i = 0; i < 1000; i++)
15 | {
16 | Logger.Trace("Sample trace message");
17 | Logger.Debug("Sample debug message");
18 | Logger.Info("Sample informational message");
19 | Logger.Warn("Sample warning message");
20 | Logger.Error("Sample error message");
21 | Logger.Fatal("Sample fatal error message");
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/NgWebDriverTest/TestAngularApp.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Protractor;
3 | using SeleniumWebdriver.Settings;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace SeleniumWebdriver.TestScript.NgWebDriverTest
11 | {
12 | [TestClass]
13 | public class TestAngularApp
14 | {
15 | private NgWebDriver ngWebDriver;
16 |
17 | [TestInitialize]
18 | public void SetUp()
19 | {
20 | ngWebDriver = new NgWebDriver(ObjectRepository.Driver);
21 | }
22 |
23 | [TestCleanup]
24 | public void TearDown()
25 | {
26 | if(null != ngWebDriver)
27 | {
28 | ngWebDriver.Close();
29 | ngWebDriver.Quit();
30 | }
31 | }
32 |
33 | [TestMethod]
34 | public void TestAjApps()
35 | {
36 | ngWebDriver.Navigate().GoToUrl("https://hello-angularjs.appspot.com/sorttablecolumn");
37 | NgWebElement element = ngWebDriver.FindElement(NgBy.Model("searchKeyword"));
38 | element.SendKeys("Angular");
39 |
40 | }
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/PageNavigation/TestPageNavigation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using SeleniumWebdriver.ComponentHelper;
9 | using SeleniumWebdriver.Settings;
10 |
11 | namespace SeleniumWebdriver.TestScript.PageNavigation
12 | {
13 | [TestClass]
14 | public class TestPageNavigation
15 | {
16 | [TestMethod]
17 | public void OpenPage()
18 | {
19 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
20 | Console.WriteLine("Title of Page : {0}",WindowHelper.GetTitle());
21 |
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/PageObject/TestPageObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using OpenQA.Selenium.Support.UI;
10 | using SeleniumExtras.PageObjects;
11 | using SeleniumWebdriver.BaseClasses;
12 | using SeleniumWebdriver.ComponentHelper;
13 | using SeleniumWebdriver.PageObject;
14 | using SeleniumWebdriver.Settings;
15 |
16 | namespace SeleniumWebdriver.TestScript.PageObject
17 | {
18 | [TestClass]
19 | public class TestPageObject
20 | {
21 | [TestMethod]
22 | public void TestPage()
23 | {
24 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
25 | HomePage homePage = new HomePage(ObjectRepository.Driver);
26 | Console.WriteLine(DisplayElementName(homePage, "homePage.QuickSearchTextBox"));
27 | LoginPage loginPage = homePage.NavigateToLogin();
28 | EnterBug enterBug = loginPage.Login(ObjectRepository.Config.GetUsername(), ObjectRepository.Config.GetPassword());
29 | BugDetail bugDetail = enterBug.NavigateToDetail();
30 | bugDetail.SelectFromSeverity("trivial");
31 | ButtonHelper.ClickButton(By.XPath("//div[@id='header']/ul[1]/li[11]/a"));
32 | }
33 |
34 | public string DisplayElementName(PageBase aPageInstance,string element)
35 | {
36 | var fieldInfo = GetFieldInfo(aPageInstance, element);
37 | var memeberInfo = fieldInfo.GetCustomAttributes(true);
38 | var attribute = memeberInfo[0] as FindsByAttribute;
39 | return string.Format("How : {0} using : {1}", attribute.How, attribute.Using);
40 | }
41 |
42 | public FieldInfo GetFieldInfo(PageBase aPageInstance, string element)
43 | {
44 | var elementName = element.Split('.');
45 | Type aPageType = aPageInstance.GetType();
46 | var fieldInofs = aPageType.GetFields();
47 | return fieldInofs.FirstOrDefault((x) => x.Name.Equals(elementName[1], StringComparison.OrdinalIgnoreCase));
48 | }
49 |
50 |
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/PhantomJS/TestPhantomJS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using SeleniumWebdriver.ComponentHelper;
9 | using SeleniumWebdriver.Settings;
10 |
11 | namespace SeleniumWebdriver.TestScript.PhantomJS
12 | {
13 | [TestClass]
14 | public class TestPhantomJS
15 | {
16 | [TestMethod]
17 | public void TestPhantomJDriver()
18 | {
19 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
20 | GenericHelper.TakeScreenShot();
21 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
22 | GenericHelper.TakeScreenShot();
23 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
24 | GenericHelper.TakeScreenShot();
25 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
26 | GenericHelper.TakeScreenShot();
27 | ButtonHelper.ClickButton(By.Id("log_in"));
28 | GenericHelper.TakeScreenShot();
29 | LinkHelper.ClickLink(By.LinkText("Testng"));
30 | GenericHelper.TakeScreenShot();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Popups/TestPopups.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using SeleniumWebdriver.ComponentHelper;
9 | using SeleniumWebdriver.Settings;
10 | using log4net;
11 | using OpenQA.Selenium.Support.UI;
12 | using ExpectedConditions = SeleniumExtras.WaitHelpers.ExpectedConditions;
13 |
14 | namespace SeleniumWebdriver.TestScript.Popups
15 | {
16 | [TestClass]
17 | [DeploymentItem(@"Resources")]
18 | public class TestPopups
19 | {
20 | private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof(TestPopups));
21 | public TestContext TestContext { get; set; }
22 |
23 |
24 | [TestMethod]
25 | public void TestAlert()
26 | {
27 | NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/js_popup.asp");
28 | ButtonHelper.ClickButton(By.XPath("//div[@id='main']/descendant::a[position()=3]"));
29 | BrowserHelper.SwitchToWindow(1);
30 | IWebElement textarea = ObjectRepository.Driver.FindElement(By.Id("textareaCode"));
31 | JavaScriptExecutor.ExecuteScript("document.getElementById('textareaCode').setAttribute('style','display: inline;')");
32 | TextBoxHelper.ClearTextBox(By.CssSelector("#textareawrapper"));
33 | BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
34 | // ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
35 | var text = JavaScriptPopHelper.GetPopUpText();
36 | JavaScriptPopHelper.ClickOkOnPopup();
37 | //IAlert alert = ObjectRepository.Driver.SwitchTo().Alert();
38 | //var text = alert.Text;
39 | //alert.Accept();
40 | ObjectRepository.Driver.SwitchTo().DefaultContent();
41 | GenericHelper.WaitForWebElement(By.Id("textareaCode"), TimeSpan.FromSeconds(60));
42 | //TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
43 | //TextBoxHelper.TypeInTextBox(By.Id("textareaCode"),text);
44 | Logger.Info("Test Alert Complete");
45 | GenericHelper.Wait(ExpectedConditions.ElementIsVisible(By.Id("id")), TimeSpan.FromSeconds(60));
46 |
47 | }
48 |
49 |
50 | [TestMethod]
51 | public void TestConfimPopup()
52 | {
53 | NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm");
54 | BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
55 | ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
56 | var text = JavaScriptPopHelper.GetPopUpText();
57 | JavaScriptPopHelper.ClickOkOnPopup();
58 | //IAlert confirm = ObjectRepository.Driver.SwitchTo().Alert();
59 | //confirm.Accept();
60 | ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
61 | JavaScriptPopHelper.ClickCancelOnPopup();
62 | ObjectRepository.Driver.SwitchTo().DefaultContent();
63 | GenericHelper.WaitForWebElement(By.Id("textareaCode"), TimeSpan.FromSeconds(60));
64 | //TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
65 | //TextBoxHelper.TypeInTextBox(By.Id("textareaCode"), text);
66 | //confirm = ObjectRepository.Driver.SwitchTo().Alert();
67 | //confirm.Dismiss();
68 | Logger.Info("Test Confirm Popup Complete");
69 | }
70 |
71 | [TestMethod]
72 | public void TestPrompt()
73 | {
74 | NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt");
75 | BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
76 | ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
77 | var text = JavaScriptPopHelper.GetPopUpText();
78 | JavaScriptPopHelper.SendKeys(text);
79 | JavaScriptPopHelper.ClickOkOnPopup();
80 | BrowserHelper.RefreshPage();
81 | BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
82 | ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
83 | text = JavaScriptPopHelper.GetPopUpText();
84 | JavaScriptPopHelper.SendKeys(text + "abc");
85 | JavaScriptPopHelper.ClickCancelOnPopup();
86 | ObjectRepository.Driver.SwitchTo().DefaultContent();
87 | GenericHelper.WaitForWebElement(By.Id("textareaCode"), TimeSpan.FromSeconds(60));
88 | //TextBoxHelper.ClearTextBox(By.Id("textareaCode"));
89 | //TextBoxHelper.TypeInTextBox(By.Id("textareaCode"), text);
90 | //IAlert prompt = ObjectRepository.Driver.SwitchTo().Alert();
91 | //prompt.SendKeys("This is automation");
92 | //prompt.Accept();
93 |
94 | // ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
95 | //prompt = ObjectRepository.Driver.SwitchTo().Alert();
96 | //prompt.SendKeys("This is automation");
97 | //prompt.Dismiss();
98 | Logger.Info("Test Prompt Complete");
99 | }
100 |
101 | [TestCleanup]
102 | public void TearDown()
103 | {
104 | Logger.Info($"Test Method Name - {TestContext.TestName}, Status - {TestContext.CurrentTestOutcome}");
105 | }
106 |
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/Frameset/TestFrameSet.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using SeleniumWebdriver.ComponentHelper;
8 | using OpenQA.Selenium;
9 | using SeleniumWebdriver.Settings;
10 | using System.Collections.ObjectModel;
11 |
12 | namespace SeleniumWebdriver.TestScript.Question.Frameset
13 | {
14 | [TestClass]
15 | public class TestFrameSet
16 | {
17 | [TestMethod]
18 | public void TestFrameInFrameSet()
19 | {
20 | NavigationHelper.NavigateToUrl("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols");
21 | GenericHelper.WaitForWebElementVisisble(By.Id("tryhome"), TimeSpan.FromSeconds(60));
22 | ObjectRepository.Driver.SwitchTo().Frame(ObjectRepository.Driver.FindElement(By.Id("iframeResult")));
23 | ReadOnlyCollection list = ObjectRepository.Driver.FindElements(By.XPath("//frame"));
24 | foreach(IWebElement webElement in list)
25 | {
26 | Console.WriteLine(webElement.ToString());
27 | }
28 |
29 |
30 | }
31 |
32 |
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/GetExecutionPath/TestGetExecutionPath.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Reflection;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace SeleniumWebdriver.TestScript.Question.GetExecutionPath
11 | {
12 | [TestClass]
13 | public class TestGetExecutionPath
14 | {
15 | [TestMethod]
16 | public void TestGetPath()
17 | {
18 | // Also Refer to Lecture 132. TC - Deployment Item
19 |
20 | var assembly = Assembly.GetExecutingAssembly();
21 | var location = Path.GetDirectoryName(assembly.Location) + @"\Resources\SampleFile.txt";
22 | Console.WriteLine(location);
23 | Assert.IsTrue(File.Exists(location),"The File Should Exist");
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/MinMax.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace SeleniumWebdriver.TestScript.Question
10 | {
11 | [TestClass]
12 | public class MinMax
13 | {
14 | [TestMethod]
15 | public void TestArrayList()
16 | {
17 |
18 | ArrayList arrayList = new ArrayList();
19 | arrayList.Add(double.Parse("181255.00"));
20 | arrayList.Add(double.Parse("181255.00"));
21 | arrayList.Add(double.Parse("181255.21"));
22 | Console.WriteLine(arrayList[0]);
23 | Console.WriteLine(arrayList[arrayList.Count - 1]);
24 |
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/SubString.cs:
--------------------------------------------------------------------------------
1 | using OpenQA.Selenium;
2 | using OpenQA.Selenium.Support.UI;
3 | using SeleniumWebdriver.ComponentHelper;
4 | using SeleniumWebdriver.Settings;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace SeleniumWebdriver.TestScript.Question
12 | {
13 | public class SubString
14 | {
15 | public object Webdriverwait { get; private set; }
16 |
17 | public static String GetSubString(String sentance,int begIndex,int endIndex)
18 | {
19 | if (endIndex > sentance.Length || begIndex < 0)
20 | throw new Exception(string.Format("Index value is not proper {0},{1}", begIndex, endIndex));
21 | return sentance.Substring(begIndex, (endIndex - begIndex));
22 | }
23 |
24 |
25 | private static Func GetAllElements(By locator)
26 | {
27 | return ((x) =>
28 | {
29 | var list = x.FindElements(locator);
30 | return list[list.Count - 1];
31 |
32 |
33 |
34 |
35 | });
36 | }
37 |
38 | public void Click()
39 | {
40 | WebDriverWait wait = new WebDriverWait(ObjectRepository.Driver, TimeSpan.FromSeconds(60))
41 | {
42 | PollingInterval = TimeSpan.FromMilliseconds(250),
43 | };
44 | wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
45 | IWebElement element = wait.Until(GetAllElements(By.ClassName("")));
46 |
47 | JavaScriptExecutor.ExecuteScript("arguments[0].scrollIntoView(true);", element);
48 | element.Click();
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/TestAppConfig.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace SeleniumWebdriver.TestScript.Question
9 | {
10 | [TestClass]
11 | class TestAppConfig
12 | {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/TestFileDownload.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using OpenQA.Selenium;
3 | using OpenQA.Selenium.Chrome;
4 | using OpenQA.Selenium.Firefox;
5 | using OpenQA.Selenium.Support.UI;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.IO;
9 | using System.Linq;
10 | using System.Text;
11 | using System.Threading;
12 | using System.Threading.Tasks;
13 |
14 | namespace SeleniumWebdriver.TestScript.Question
15 | {
16 | [TestClass]
17 | public class TestFileDownload
18 | {
19 | private IWebDriver driver;
20 | private const string Download_Dir = @"D:\DownloadFile\";
21 |
22 |
23 | private FirefoxOptions GetFirefoxptions()
24 | {
25 | FirefoxOptions options = new FirefoxOptions();
26 |
27 | FirefoxProfile firefoxProfile = new FirefoxProfile();
28 | firefoxProfile.SetPreference("browser.download.folderList", 2);
29 | //firefoxProfile.SetPreference("browser.download.manager.showWhenStarting", false);
30 | firefoxProfile.SetPreference("browser.download.dir", Download_Dir);
31 | firefoxProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk",
32 | "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
33 | options.Profile = firefoxProfile;
34 | return options;
35 |
36 | }
37 |
38 | [TestInitialize]
39 | public void Setup()
40 | {
41 | driver = new FirefoxDriver(@"C:\Users\rathr1\Downloads\geckodriver-v0.20.1-win64\", GetFirefoxptions());
42 | driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(60);
43 | driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
44 | driver.Navigate().GoToUrl(@"https://www.sample-videos.com/download-sample-xls.php");
45 | driver.Manage().Window.Maximize();
46 |
47 | }
48 |
49 | [TestCleanup]
50 | public void TearDown()
51 | {
52 | if (driver != null)
53 | {
54 | driver.Close();
55 | driver.Quit();
56 | }
57 | }
58 |
59 | [TestMethod]
60 | public void TestDownload()
61 | {
62 | WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60))
63 | {
64 | PollingInterval = TimeSpan.FromMilliseconds(250)
65 | };
66 |
67 | IWebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[@download='SampleXLSFile_19kb.xls']")));
68 | element.Click();
69 | int count = 0;
70 |
71 | while (count < 10)
72 | {
73 | string[] files = Directory.GetFiles(Download_Dir);
74 | if(files.Length != 0)
75 | {
76 | if (files.Contains(Download_Dir + "SampleXLSFile_19kb.xls"))
77 | {
78 | Console.Write(files[0]);
79 | break;
80 | }
81 | Thread.Sleep(1000);
82 | count++;
83 | }
84 | }
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/TestGetDataFromPage.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using OpenQA.Selenium;
3 | using SeleniumWebdriver.ComponentHelper;
4 | using SeleniumWebdriver.Settings;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace SeleniumWebdriver.TestScript.Question
12 | {
13 | [TestClass]
14 | public class TestGetDataFromPage
15 | {
16 | //Base xpath for the grid
17 | private const string BaseXpathOfGrid = "//div[@id='approved']//div[@class='durandal-wrapper']//ol[@class='contentList medium ui-sortable']";
18 |
19 | [TestInitialize]
20 | public void TestSetup()
21 | {
22 | NavigationHelper.NavigateToUrl("https://internal.mem.com/sso/v2/internal");
23 | GenericHelper.WaitForWebElementVisisble(By.Id("UserName"), TimeSpan.FromSeconds(60));
24 | TextBoxHelper.TypeInTextBox(By.Id("UserName"), "AutoTester");
25 | TextBoxHelper.TypeInTextBox(By.Id("Password"), "AutoTester123");
26 | ButtonHelper.ClickButton(By.XPath("//span[text()='LOGIN']"));
27 | GenericHelper.WaitForWebElementVisisble(By.XPath("//label[text()='MeM Internal']"), TimeSpan.FromSeconds(70));
28 | ButtonHelper.ClickButton(By.XPath("//label[text()='MeM Internal']"));
29 | }
30 |
31 | [TestMethod]
32 | public void TestGetData()
33 | {
34 | NavigationHelper.NavigateToUrl("https://admin.mem.com/sso/newde/7851114#contententry/condolences");
35 | GenericHelper.WaitForWebElementVisisble(By.XPath(BaseXpathOfGrid), TimeSpan.FromSeconds(70));
36 | var index = 2; // index for the item in un-ordered list
37 | while(GenericHelper.IsElemetPresent(By.XPath(BaseXpathOfGrid + "//li[" + index + "]"))) // To check if there are more item present
38 | {
39 | IWebElement heading = ObjectRepository.Driver.FindElement(By.XPath(BaseXpathOfGrid + "//li[" + index + "]//section//div[@class='thumbview']//div[@class='heading']")); // xpath of heading using index 2 -for 1st li , 3 - 2nd li...
40 | Console.WriteLine(heading.Text);
41 | heading = ObjectRepository.Driver.FindElement(By.XPath(BaseXpathOfGrid + "//li[" + index + "]//section//div[@class='thumbview']//div[@class='text']")); // xpath of description using index 2 -for 1st li , 3 - 2nd li...
42 | Console.WriteLine(heading.Text);
43 | index = index + 1;
44 | }
45 | }
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/TestKendoUI.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using OpenQA.Selenium;
3 | using SeleniumWebdriver.ComponentHelper;
4 | using SeleniumWebdriver.Settings;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading;
10 | using System.Threading.Tasks;
11 |
12 | namespace SeleniumWebdriver.TestScript.Question
13 | {
14 | [TestClass]
15 | public class TestKendoUI
16 | {
17 | private readonly string UserSetting = "//button[@role='menu']";
18 | [TestMethod]
19 | public void TestUi()
20 | {
21 | // Navigate to the Url
22 | NavigationHelper.NavigateToUrl("https://www.telerik.com/kendo-angular-ui/components/buttons/dropdownbutton/");
23 | // Wait for the Iframe
24 | GenericHelper.WaitForWebElement(By.Id("example-basic-usage"), TimeSpan.FromSeconds(30));
25 | // Switch to the frame
26 | ObjectRepository.Driver.SwitchTo().Frame(ObjectRepository.Driver.FindElement(By.Id("example-basic-usage")));
27 | // Wait for User Setting button
28 | GenericHelper.WaitForWebElement(By.XPath(UserSetting),TimeSpan.FromSeconds(60));
29 | // Click on User Setting
30 | ButtonHelper.ClickButton(By.XPath(UserSetting));
31 | Thread.Sleep(3000);
32 | // Wait for Menu item
33 | GenericHelper.WaitForWebElementInPage(By.CssSelector(".k-list.k-reset > [role='menuItem']:nth-child(2)"), TimeSpan.FromSeconds(60));
34 | // Click on the item based index
35 | ButtonHelper.ClickButton(By.CssSelector(".k-list.k-reset > [role='menuItem']:nth-child(2)"));
36 | Thread.Sleep(3000);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/Question/TestReadExcelFile.cs:
--------------------------------------------------------------------------------
1 | using ExcelDataReader;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Data;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace SeleniumWebdriver.TestScript.Question
12 | {
13 | [TestClass]
14 | public class TestReadExcelFile
15 | {
16 | [TestMethod]
17 | public void TestReadExcel()
18 | {
19 | FileStream stream = new FileStream(@"C:\Users\rathr1\Desktop\KDD.xlsx", FileMode.Open, FileAccess.Read);
20 | IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
21 | DataTable table = reader.AsDataSet().Tables["TC01"];
22 |
23 | for(int i = 0; i < table.Rows.Count; i++)
24 | {
25 | var col = table.Rows[i];
26 | for(int j = 0; j < col.ItemArray.Length; j++)
27 | {
28 | Console.WriteLine(col.ItemArray[j]);
29 | }
30 | }
31 |
32 | reader.Close();
33 | stream.Close();
34 |
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/RadAutoCompleteBox/TC-AutoSuggestComboBox.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using OpenQA.Selenium;
3 | using SeleniumWebdriver.ComponentHelper;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading;
9 | using System.Threading.Tasks;
10 |
11 | namespace SeleniumWebdriver.TestScript.RadAutoCompleteBox
12 | {
13 | [TestClass]
14 | public class TC_AutoSuggestComboBox
15 | {
16 | private readonly string url = "https://demos.telerik.com/aspnet-ajax/autocompletebox/examples/default/defaultcs.aspx";
17 |
18 | public object WaitHelper { get; private set; }
19 |
20 | [TestMethod]
21 | public void TestAutSuggestComboBox()
22 | {
23 | NavigationHelper.NavigateToUrl(url);
24 | GenericHelper.WaitForWebElement(By.Id("ctl00_ContentPlaceholder1_RadAutoCompleteBox2_Input"), TimeSpan.FromSeconds(60));
25 | Dictionary data = new Dictionary
26 | {
27 | { "a", "Nancy" },
28 | { "b", "Robert" }
29 | };
30 | EnterAndSelect(data);
31 |
32 | }
33 |
34 | private void EnterAndSelect(Dictionary data)
35 | {
36 | foreach(string key in data.Keys)
37 | {
38 | TextBoxHelper.TypeInTextBox(By.Id("ctl00_ContentPlaceholder1_RadAutoCompleteBox2_Input"), key);
39 | GenericHelper.WaitForWebElementVisisble(getName(data[key]),TimeSpan.FromSeconds(60));
40 | ButtonHelper.ClickButton(getName(data[key]));
41 | Thread.Sleep(2000);
42 | }
43 |
44 |
45 | }
46 |
47 | private By getName(string name)
48 | {
49 | return By.XPath(string.Format("//li[text()='{0}']", name));
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/RadioButton/HandleRadioButton.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using OpenQA.Selenium.Support.Extensions;
9 | using OpenQA.Selenium.Support.UI;
10 | using SeleniumWebdriver.ComponentHelper;
11 | using SeleniumWebdriver.Settings;
12 |
13 | namespace SeleniumWebdriver.TestScript.RadioButton
14 | {
15 | [TestClass]
16 | public class HandleRadioButton
17 | {
18 | [TestMethod]
19 | public void TestRadio()
20 | {
21 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
22 | IWebElement webelemt = ObjectRepository.Driver.FindElement(By.XPath("//a[@id='enter_bug']/span"));
23 | Console.WriteLine("Text : {0}",webelemt.Text);
24 |
25 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
26 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
27 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
28 | ButtonHelper.ClickButton(By.Id("log_in"));
29 | LinkHelper.ClickLink(By.XPath("//div[@id='header']/ul[1]/li[9]/a"));
30 | LinkHelper.ClickLink(By.XPath("//dt[@id='parameters']/a"));
31 | //IWebElement element = ObjectRepository.Driver.FindElement(By.Id("ssl_redirect-on"));
32 | //element.Click();
33 | Console.WriteLine("Selected : {0}",RadioButtonHelper.IsRadioButtonSelected(By.Id("ssl_redirect-off")));
34 | RadioButtonHelper.ClickRadioButton(By.Id("ssl_redirect-on"));
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/ScreenShot/TakeScreenShots.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing.Imaging;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using OpenQA.Selenium.Support.Extensions;
10 | using SeleniumWebdriver.ComponentHelper;
11 | using SeleniumWebdriver.Settings;
12 |
13 | namespace SeleniumWebdriver.TestScript.ScreenShot
14 | {
15 | [TestClass]
16 | public class TakeScreenShots
17 | {
18 | [TestMethod,TestCategory("Smoke")]
19 | public void ScreenShot()
20 | {
21 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
22 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
23 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
24 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
25 | GenericHelper.TakeScreenShot();
26 | GenericHelper.TakeScreenShot("Test.jpeg");
27 |
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/SikuliScript/TestSikuliScript.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using SikuliSharp;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace SeleniumWebdriver.TestScript.SikuliScript
10 | {
11 | [TestClass]
12 | public class TestSikuliScript
13 | {
14 |
15 | private ISikuliSession session;
16 | private IPattern patterns;
17 |
18 | [TestMethod]
19 | public void TestSikuliIntegration()
20 | {
21 | try
22 | {
23 | session = Sikuli.CreateSession();
24 | patterns = Patterns.FromFile(@"C:\Data\win.PNG");
25 | if (session.Exists(patterns))
26 | {
27 | Console.WriteLine("Patteren Exist " + patterns.ToString());
28 | session.Wait(patterns, 60);
29 | session.Click(patterns);
30 | }
31 | }
32 | finally
33 | {
34 | session?.Dispose();
35 | }
36 | }
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/StringToByClass/TestPage.cs:
--------------------------------------------------------------------------------
1 | using OpenQA.Selenium;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace SeleniumWebdriver.TestScript.StringToByClass
9 | {
10 | public class TestPage
11 | {
12 | private IWebDriver webDriver;
13 |
14 | protected static string FileABug = "(By.Id(\"enter_bug\")), fileabug";
15 | protected static string aFileABug = "By.Id,enter_bug,fileabug";
16 |
17 | public static List GetElementAndValue(string ele)
18 | {
19 | return ele.Split(',').ToList();
20 | }
21 |
22 | public static void ClickButton(string locator)
23 | {
24 | List LocatorAndValue = GetElementAndValue(locator);
25 | By aLocator = GetLocator(LocatorAndValue);
26 | }
27 |
28 | private static By GetLocator(List aLocatorAndValue)
29 | {
30 | if (aLocatorAndValue[0].Equals("By.Id"))
31 | return By.Id(aLocatorAndValue[1]);
32 | else
33 | throw new Exception("Invalid Locator");
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/TestClassContext/TestClassContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 |
8 | namespace SeleniumWebdriver.TestScript.TestClassContext
9 | {
10 | [TestClass]
11 | public class TestClassContext
12 | {
13 | private TestContext _testContext;
14 |
15 | public TestContext TestContext
16 | {
17 | get { return _testContext; }
18 | set { _testContext = value; }
19 | }
20 |
21 | [TestMethod]
22 | public void TestCase1()
23 | {
24 | Console.WriteLine("Test Name :{0}",TestContext.TestName);
25 | }
26 |
27 | [TestMethod]
28 | public void TestCase2()
29 | {
30 | Console.WriteLine("Test Name :{0}", TestContext.TestName);
31 | }
32 |
33 | [TestCleanup]
34 | public void AfterTest()
35 | {
36 | Console.WriteLine("Result :{0}", TestContext.CurrentTestOutcome);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/TextBox/TestTextBox.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using SeleniumWebdriver.ComponentHelper;
9 | using SeleniumWebdriver.Settings;
10 |
11 | namespace SeleniumWebdriver.TestScript.TextBox
12 | {
13 | [TestClass]
14 | public class TestTextBox
15 | {
16 | [TestMethod]
17 | public void TextBox()
18 | {
19 | NavigationHelper.NavigateToUrl(ObjectRepository.Config.GetWebsite());
20 | LinkHelper.ClickLink(By.LinkText("File a Bug"));
21 | //IWebElement ele = ObjectRepository.Driver.FindElement(By.Id("Bugzilla_login"));
22 | //ele.SendKeys(ObjectRepository.Config.GetUsername());
23 | //ele = ObjectRepository.Driver.FindElement(By.Id("Bugzilla_password"));
24 | //ele.SendKeys(ObjectRepository.Config.GetPassword());
25 | //ele = ObjectRepository.Driver.FindElement(By.Id("Bugzilla_login"));
26 | //ele.Clear();
27 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_login"), ObjectRepository.Config.GetUsername());
28 | TextBoxHelper.TypeInTextBox(By.Id("Bugzilla_password"), ObjectRepository.Config.GetPassword());
29 | TextBoxHelper.ClearTextBox(By.Id("Bugzilla_login"));
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/WebDriverWaiter/TestWebDeriverWait.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
7 | using OpenQA.Selenium;
8 | using OpenQA.Selenium.Support.UI;
9 | using SeleniumWebdriver.ComponentHelper;
10 | using SeleniumWebdriver.Settings;
11 | using ExpectedConditions = SeleniumExtras.WaitHelpers.ExpectedConditions;
12 |
13 | namespace SeleniumWebdriver.TestScript.WebDriverWaiter
14 | {
15 | [TestClass]
16 | public class TestWebDeriverWait
17 | {
18 |
19 |
20 | [TestMethod]
21 | public void TestWait()
22 | {
23 |
24 | NavigationHelper.NavigateToUrl("https://www.udemy.com/courses/");
25 | TextBoxHelper.TypeInTextBox(By.XPath("//input[@class='search-input ui-autocomplete-input quick-search']"),
26 | "C#");
27 |
28 | }
29 |
30 | [TestMethod]
31 | public void TestDynamciWait()
32 | {
33 | NavigationHelper.NavigateToUrl("https://www.udemy.com/");
34 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(1));
35 | WebDriverWait wait = new WebDriverWait(ObjectRepository.Driver,TimeSpan.FromSeconds(50));
36 | wait.PollingInterval = TimeSpan.FromMilliseconds(250);
37 | wait.IgnoreExceptionTypes(typeof(NoSuchElementException),typeof(ElementNotVisibleException));
38 | // Console.WriteLine(wait.Until(waitforTitle()));
39 | //IWebElement element = wait.Until(waitforElement());
40 | //element.SendKeys("java");
41 | wait.Until(waitforElement()).SendKeys("health");
42 | ButtonHelper.ClickButton(By.CssSelector(".home-search-btn"));
43 | wait.Until(waitforLastElemet()).Click();
44 | Console.WriteLine("Title : {0}",wait.Until(waitforpageTitle()));
45 | }
46 |
47 |
48 | [TestMethod]
49 | public void TestExpCondition()
50 | {
51 | NavigationHelper.NavigateToUrl("https://www.udemy.com/");
52 | ObjectRepository.Driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(1));
53 | WebDriverWait wait = new WebDriverWait(ObjectRepository.Driver, TimeSpan.FromSeconds(50));
54 | wait.PollingInterval = TimeSpan.FromMilliseconds(250);
55 | wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(ElementNotVisibleException));
56 | wait.Until(ExpectedConditions.ElementExists(By.XPath("//input[@type='search']"))).SendKeys("HTML");
57 | ButtonHelper.ClickButton(By.CssSelector(".home-search-btn"));
58 | wait.Until(ExpectedConditions.ElementExists(By.XPath("//*[@id='courses']/li[12]/a/div[2]/div[1]/div/span"))).Click();
59 | Console.WriteLine("Title : {0}",wait.Until(ExpectedConditions.TitleContains("u")));
60 | wait.Until(ExpectedConditions.ElementExists(By.XPath("//a[contains(text(),'Login')]"))).Click();
61 | wait.Until(ExpectedConditions.ElementExists(By.XPath("//div[@class='loginbox-v4 js-signin-box']")));
62 | }
63 |
64 | //acc -spe fun { () => {}}
65 |
66 | private Func waitforSearchbox()
67 | {
68 | return ((x) =>
69 | {
70 | Console.WriteLine("Waiting for Search Box");
71 | return x.FindElements(By.XPath("//input[@type='search']")).Count == 1;
72 | });
73 | }
74 |
75 | private Func waitforTitle()
76 | {
77 | return ((x) =>
78 | {
79 | if (x.Title.Contains("Main"))
80 | return x.Title;
81 | return null;
82 | });
83 | }
84 |
85 | private Func waitforElement()
86 | {
87 | return ((x) =>
88 | {
89 | Console.WriteLine("Waiting for Search Text box");
90 | Console.WriteLine("Waiting for element");
91 | if (x.FindElements(By.XPath("//input[@type='search']")).Count == 1)
92 | return x.FindElement(By.XPath("//input[@type='search']"));
93 | return null;
94 | });
95 | }
96 |
97 | private Func waitforLastElemet()
98 | {
99 | return ((x) =>
100 | {
101 | Console.WriteLine("Waiting for Last Element");
102 | if (
103 | x.FindElements(
104 | By.XPath("//span[contains(text(),'These 5 Habits Will Help You Improve Your Health')]")).Count ==
105 | 1)
106 | return
107 | x.FindElement(
108 | By.XPath("//span[contains(text(),'These 5 Habits Will Help You Improve Your Health')]"));
109 | return null;
110 | });
111 | }
112 |
113 | private Func waitforpageTitle()
114 | {
115 | return ((x) =>
116 | {
117 | Console.WriteLine("Waiting for Title");
118 | if (
119 | x.FindElements(By.CssSelector(".course-title")).Count == 1)
120 | return x.FindElement(By.CssSelector(".course-title")).Text;
121 | return null;
122 | });
123 | }
124 | }
125 | }
126 |
127 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/TestScript/WebElement/TestWebElement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using SeleniumWebdriver.ComponentHelper;
10 | using SeleniumWebdriver.Settings;
11 |
12 | namespace SeleniumWebdriver.TestScript.WebElement
13 | {
14 | [TestClass]
15 | public class TestWebElement
16 | {
17 | [TestMethod]
18 | public void GetElement()
19 | {
20 | NavigationHelper.NavigateToUrl(@"http://localhost:5001/editparams.cgi");
21 | try
22 | {
23 | ReadOnlyCollection col = ObjectRepository.Driver.FindElements(By.TagName("input"));
24 | Console.WriteLine("Size : {0}", col.Count);
25 | Console.WriteLine("Size : {0}", col.ElementAt(0));
26 | //ObjectRepository.Driver.FindElement(By.LinkText("File a Bug")).Click();
27 | var a = ObjectRepository.Driver.FindElement(By.Name("showmybugslink")).GetAttribute("checked");
28 |
29 |
30 | //ObjectRepository.Driver.FindElement(By.TagName("input"));
31 | //ObjectRepository.Driver.FindElement(By.ClassName("btn"));
32 | //ObjectRepository.Driver.FindElement(By.CssSelector("#find"));
33 | //ObjectRepository.Driver.FindElement(By.LinkText("File a Bug"));
34 | //ObjectRepository.Driver.FindElement(By.PartialLinkText("File"));
35 | //ObjectRepository.Driver.FindElement(By.Name("quicksearch"));
36 | //ObjectRepository.Driver.FindElement(By.Id("find_bottom"));
37 | //ObjectRepository.Driver.FindElement(By.XPath("//input[@id='find']"));
38 | ////ObjectRepository.Driver.FindElement(By.XPath("//input[@id='find1']"));
39 | //IList list = new List();
40 | //list.Add("Task 1");
41 | //list.Add("Task 2");
42 | //list.Add("Task 3");
43 | //Console.WriteLine("Size : {0}",list.Count);
44 | //list.Remove("Task 2");
45 | //Console.WriteLine("Size : {0}", list.Count);
46 | //Console.WriteLine("Value : {0}",list[0]);
47 | //list.Clear();
48 | //Console.WriteLine("Size : {0}", list.Count);
49 | }
50 | catch (NoSuchElementException e)
51 | {
52 | Console.WriteLine(e);
53 | }
54 |
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/UnitTest1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Configuration;
5 | using System.Linq;
6 | using System.Threading;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using OpenQA.Selenium;
9 | using OpenQA.Selenium.Chrome;
10 | using OpenQA.Selenium.Firefox;
11 | using OpenQA.Selenium.IE;
12 | using OpenQA.Selenium.Interactions;
13 | using OpenQA.Selenium.Support.PageObjects;
14 | using SeleniumWebdriver.ComponentHelper;
15 | using SeleniumWebdriver.Configuration;
16 | using SeleniumWebdriver.Interfaces;
17 | using SeleniumWebdriver.Keyword;
18 | using SeleniumWebdriver.PageObject;
19 | using SeleniumWebdriver.Settings;
20 |
21 |
22 | namespace SeleniumWebdriver
23 | {
24 |
25 | [TestClass]
26 | public class UnitTest1
27 | {
28 | [TestMethod]
29 | public void TestKeyword()
30 | {
31 | DataEngine engine = new DataEngine();
32 | engine.ExecuteScript(@"C:\Users\rahul.rathore\Desktop\Cucumber\Keyword.xlsx", "TC01");
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/extent-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | standard
7 |
8 |
9 |
10 | UTF-8
11 |
12 |
13 |
14 | https
15 |
16 |
17 | Extent
18 |
19 | true
20 |
21 |
22 | Automation Report
23 |
24 |
25 |
26 | bottom
27 |
28 |
29 |
30 |
35 |
36 |
37 |
38 |
39 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/license:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CourseRepository/SeleniumWebDriverWithCSharp/23c42c65e3b1bcb4899341e085984e4dd7ff08d1/SeleniumWebdriver/license
--------------------------------------------------------------------------------
/SeleniumWebdriver/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/SeleniumWebdriver/phantomjs-license.txt:
--------------------------------------------------------------------------------
1 | Redistribution and use in source and binary forms, with or without
2 | modification, are permitted provided that the following conditions are met:
3 |
4 | * Redistributions of source code must retain the above copyright
5 | notice, this list of conditions and the following disclaimer.
6 | * Redistributions in binary form must reproduce the above copyright
7 | notice, this list of conditions and the following disclaimer in the
8 | documentation and/or other materials provided with the distribution.
9 | * Neither the name of the nor the
10 | names of its contributors may be used to endorse or promote products
11 | derived from this software without specific prior written permission.
12 |
13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 | ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
17 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 |
--------------------------------------------------------------------------------