Skip to content

Commit 9851c7d

Browse files
rathr1rathr1
authored andcommitted
Test download of a file
1 parent 6d352ef commit 9851c7d

13 files changed

Lines changed: 306 additions & 6 deletions

File tree

SeleniumWebdriver/App2.config

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
-->
4+
<configuration>
5+
<configSections>
6+
<!--
7+
1. Specify the section name and class which will read the section
8+
-->
9+
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
10+
11+
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" /></configSections>
12+
<appSettings>
13+
<add key="Browser" value="Chrome" />
14+
<add key="Username" value="rahul@bugzila.com" />
15+
<add key="Password" value="welcome" />
16+
<add key="Website" value="http://192.168.1.11:5001/" />
17+
<add key="PageLoadTimeout" value="40" />
18+
<add key="ElementLoadTimeout" value="2" />
19+
</appSettings>
20+
<!--
21+
2. Create the section with configuration
22+
-->
23+
<log4net>
24+
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
25+
<layout name="PatternLayout" type="log4net.Layout.PatternLayout">
26+
<ConversionPattern value="%date{dd-MMM-yyyy-HH:mm:ss} [%class] [%level] [%method] - %message%newline" />
27+
</layout>
28+
<Threshold value="INFO" />
29+
</appender>
30+
<appender name="FileAppender" type="log4net.Appender.FileAppender">
31+
<layout name="PatternLayout" type="log4net.Layout.PatternLayout">
32+
<ConversionPattern value="%date{dd-MMM-yyyy-HH:mm:ss} [%class] [%level] [%method] - %message%newline" />
33+
</layout>
34+
<Threshold value="INFO" />
35+
<AppendToFile value="true" />
36+
<File value="SeleniumFileLogger.log" />
37+
</appender>
38+
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
39+
<layout name="PatternLayout" type="log4net.Layout.PatternLayout">
40+
<ConversionPattern value="%date{dd-MMM-yyyy-HH:mm:ss} [%class] [%level] [%method] - %message%newline" />
41+
</layout>
42+
<Threshold value="ALL" />
43+
<AppendToFile value="true" />
44+
<File value="SeleniumRollingFileLogger.log" />
45+
<MaximumFileSize value="1MB" />
46+
<MaxSizeRollBackups value="15" />
47+
</appender>
48+
49+
<!--
50+
3. using the <root> , specify the appender to use
51+
-->
52+
<root>
53+
<appender-ref ref="ConsoleAppender" />
54+
<appender-ref ref="FileAppender" />
55+
<appender-ref ref="RollingFileAppender" />
56+
</root>
57+
</log4net>
58+
<specFlow>
59+
<unitTestProvider name="MsTest" />
60+
61+
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --></specFlow>
62+
<runtime>
63+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
64+
<dependentAssembly>
65+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
66+
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
67+
</dependentAssembly>
68+
</assemblyBinding>
69+
</runtime>
70+
</configuration>

SeleniumWebdriver/BaseClasses/BaseClass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace SeleniumWebdriver.BaseClasses
2121
{
2222
[TestClass]
2323

24-
public class BaseClass
24+
public class BaseClass
2525
{
2626
private static readonly ILog Logger = Log4NetHelper.GetXmlLogger(typeof (BaseClass));
2727
private static FirefoxProfile GetFirefoxptions()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

SeleniumWebdriver/ComponentHelper/GenericHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Drawing.Imaging;
4+
using System.IO;
45
using System.Linq;
56
using System.Runtime.InteropServices;
67
using System.Text;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

SeleniumWebdriver/SeleniumWebdriver.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<Compile Include="ComponentHelper\ButtonHelper.cs" />
101101
<Compile Include="ComponentHelper\CheckBoxHelper.cs" />
102102
<Compile Include="ComponentHelper\ComboBoxHelper.cs" />
103+
<Compile Include="ComponentHelper\FileHelper.cs" />
103104
<Compile Include="ComponentHelper\GenericHelper.cs" />
104105
<Compile Include="ComponentHelper\JavaScriptExecutor.cs" />
105106
<Compile Include="ComponentHelper\JavaScriptPopHelper.cs" />
@@ -149,6 +150,7 @@
149150
<Compile Include="StepDefinition\Hooks.cs" />
150151
<Compile Include="StepDefinition\TestFeature.cs" />
151152
<Compile Include="StepDefinition\TestFeature2.cs" />
153+
<Compile Include="TestScript\AngularScript\TestProtractor.cs" />
152154
<Compile Include="TestScript\AutoSuggest\TestAutoSuggest.cs" />
153155
<Compile Include="TestScript\BrowserActions\TestBrowserActions.cs" />
154156
<Compile Include="TestScript\Button\HandleButton.cs" />
@@ -170,6 +172,7 @@
170172
<Compile Include="TestScript\PhantomJS\TestPhantomJS.cs" />
171173
<Compile Include="TestScript\Popups\TestPopups.cs" />
172174
<Compile Include="TestScript\Question\SubString.cs" />
175+
<Compile Include="TestScript\Question\TestFileDownload.cs" />
173176
<Compile Include="TestScript\RadAutoCompleteBox\TC-AutoSuggestComboBox.cs" />
174177
<Compile Include="TestScript\RadioButton\HandleRadioButton.cs" />
175178
<Compile Include="TestScript\ScreenShot\TakeScreenShots.cs" />
@@ -260,15 +263,15 @@
260263
</Choose>
261264
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
262265
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
263-
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.38.0.1\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.38.0.1\build\Selenium.WebDriver.ChromeDriver.targets')" />
264266
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
265267
<PropertyGroup>
266268
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
267269
</PropertyGroup>
268-
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.38.0.1\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.38.0.1\build\Selenium.WebDriver.ChromeDriver.targets'))" />
269270
<Error Condition="!Exists('..\packages\Selenium.WebDriver.IEDriver.3.11.1\build\Selenium.WebDriver.IEDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.IEDriver.3.11.1\build\Selenium.WebDriver.IEDriver.targets'))" />
271+
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.40.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.40.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
270272
</Target>
271273
<Import Project="..\packages\Selenium.WebDriver.IEDriver.3.11.1\build\Selenium.WebDriver.IEDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.IEDriver.3.11.1\build\Selenium.WebDriver.IEDriver.targets')" />
274+
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.40.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.40.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
272275
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
273276
Other similar extension points exist, see Microsoft.Common.targets.
274277
<Target Name="BeforeBuild">
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

SeleniumWebdriver/TestScript/PageObject/TestPageObject.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Microsoft.VisualStudio.TestTools.UnitTesting;
77
using OpenQA.Selenium;
8+
using OpenQA.Selenium.Support.UI;
89
using SeleniumWebdriver.ComponentHelper;
910
using SeleniumWebdriver.PageObject;
1011
using SeleniumWebdriver.Settings;
@@ -27,6 +28,8 @@ public void TestPage()
2728
}
2829

2930

30-
31+
32+
33+
3134
}
3235
}

SeleniumWebdriver/TestScript/Popups/TestPopups.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public void TestAlert()
2424
NavigationHelper.NavigateToUrl("http://www.w3schools.com/js/js_popup.asp");
2525
ButtonHelper.ClickButton(By.XPath("//div[@id='main']/descendant::a[position()=3]"));
2626
BrowserHelper.SwitchToWindow(1);
27+
IWebElement textarea = ObjectRepository.Driver.FindElement(By.Id("textareaCode"));
28+
JavaScriptExecutor.ExecuteScript("document.getElementById('textareaCode').setAttribute('style','display: inline;')");
29+
TextBoxHelper.ClearTextBox(By.CssSelector("#textareawrapper"));
2730
BrowserHelper.SwitchToFrame(By.Id("iframeResult"));
2831
// ButtonHelper.ClickButton(By.XPath("//button[text()='Try it']"));
2932
var text = JavaScriptPopHelper.GetPopUpText();

SeleniumWebdriver/TestScript/Question/SubString.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System;
1+
using OpenQA.Selenium;
2+
using OpenQA.Selenium.Support.UI;
3+
using SeleniumWebdriver.ComponentHelper;
4+
using SeleniumWebdriver.Settings;
5+
using System;
26
using System.Collections.Generic;
37
using System.Linq;
48
using System.Text;
@@ -8,12 +12,40 @@ namespace SeleniumWebdriver.TestScript.Question
812
{
913
public class SubString
1014
{
15+
public object Webdriverwait { get; private set; }
1116

1217
public static String GetSubString(String sentance,int begIndex,int endIndex)
1318
{
1419
if (endIndex > sentance.Length || begIndex < 0)
1520
throw new Exception(string.Format("Index value is not proper {0},{1}", begIndex, endIndex));
1621
return sentance.Substring(begIndex, (endIndex - begIndex));
1722
}
23+
24+
25+
private static Func<IWebDriver, IWebElement> 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+
}
1850
}
1951
}

0 commit comments

Comments
 (0)