Best Ocaramba code snippet using Ocaramba.Tests.PageObjects.PageObjects.TheInternet.DownloadPage
DownloadPage.cs
Source: DownloadPage.cs
1// <copyright file="DownloadPage.cs" company="Objectivity Bespoke Software Specialists">2// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved.3// </copyright>4// <license>5// The MIT License (MIT)6// Permission is hereby granted, free of charge, to any person obtaining a copy7// of this software and associated documentation files (the "Software"), to deal8// in the Software without restriction, including without limitation the rights9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10// copies of the Software, and to permit persons to whom the Software is11// furnished to do so, subject to the following conditions:12// The above copyright notice and this permission notice shall be included in all13// copies or substantial portions of the Software.14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20// SOFTWARE.21// </license>22namespace Ocaramba.Tests.PageObjects.PageObjects.TheInternet23{24 using System;25 using System.Globalization;26 using System.IO;27 using NLog;28 using Ocaramba;29 using Ocaramba.Extensions;30 using Ocaramba.Helpers;31 using Ocaramba.Types;32 public class DownloadPage : ProjectPageBase33 {34#if net4735 private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();36#endif37#if netcoreapp3_138 private static readonly NLog.Logger Logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();39#endif40 /// <summary>41 /// Locators for elements42 /// </summary>43 private readonly ElementLocator downloadPageHeader = new ElementLocator(Locator.XPath, "//h3[.='File Downloader']"),44 fileLink = new ElementLocator(Locator.CssSelector, "a[href='download/{0}']");45 public DownloadPage(DriverContext driverContext)46 : base(driverContext)47 {48 Logger.Info("Waiting for File Download page to open");49 this.Driver.IsElementPresent(this.downloadPageHeader, BaseConfiguration.ShortTimeout);50 }51 public DownloadPage SaveFile(string fileName, string newName)52 {53 if (BaseConfiguration.TestBrowser == BrowserType.Firefox54 || BaseConfiguration.TestBrowser == BrowserType.Chrome55 || BaseConfiguration.TestBrowser == BrowserType.RemoteWebDriver)56 {57 this.Driver.GetElement(this.fileLink.Format(fileName), "Click on file").Click();58 FilesHelper.WaitForFileOfGivenName(fileName, this.DriverContext.DownloadFolder, false);59 FilesHelper.RenameFile(fileName, newName, this.DriverContext.DownloadFolder, FileType.Csv);60 }61 else62 {63 Logger.Info(CultureInfo.CurrentCulture, "Downloading files in browser {0} is not supported", BaseConfiguration.TestBrowser);64 }65 return this;66 }67 public DownloadPage SaveFile(string newName)68 {69 if (BaseConfiguration.TestBrowser == BrowserType.Firefox70 || BaseConfiguration.TestBrowser == BrowserType.Chrome71 || BaseConfiguration.TestBrowser == BrowserType.RemoteWebDriver)72 {73 var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder, FileType.Txt);74 this.Driver.GetElement(this.fileLink.Format("ObjectivityTestAutomationCSHarpFramework.txt")).Click();75 FilesHelper.WaitForFileOfGivenType(FileType.Txt, filesNumber, this.DriverContext.DownloadFolder);76 FileInfo file = FilesHelper.GetLastFile(this.DriverContext.DownloadFolder, FileType.Txt);77 FilesHelper.RenameFile(file.Name, newName, this.DriverContext.DownloadFolder, FileType.Txt);78 }79 else80 {81 Logger.Info(CultureInfo.CurrentCulture, "Downloading files in browser {0} is not supported", BaseConfiguration.TestBrowser);82 }83 return this;84 }85 public DownloadPage SaveAnyFile()86 {87 if (BaseConfiguration.TestBrowser == BrowserType.Firefox88 || BaseConfiguration.TestBrowser == BrowserType.Chrome89 || BaseConfiguration.TestBrowser == BrowserType.RemoteWebDriver)90 {91 var filesNumber = FilesHelper.CountFiles(this.DriverContext.DownloadFolder);92 this.Driver.GetElement(this.fileLink.Format("ObjectivityTestAutomationCSHarpFramework.txt")).Click();93 FilesHelper.WaitForFile(filesNumber, this.DriverContext.DownloadFolder);94 FileInfo file = FilesHelper.GetLastFile(this.DriverContext.DownloadFolder);95 FilesHelper.RenameFile(BaseConfiguration.ShortTimeout, file.Name, "name_of_file_branch.txt", this.DriverContext.DownloadFolder);96 }97 else98 {99 Logger.Info(CultureInfo.CurrentCulture, "Downloading files in browser {0} is not supported", BaseConfiguration.TestBrowser);...
SaveScreenShotsPageSourceTestsNUnit.cs
1// <copyright file="SaveScreenShotsPageSourceTestsNUnit.cs" company="Objectivity Bespoke Software Specialists">2// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved.3// </copyright>4// <license>5// The MIT License (MIT)6// Permission is hereby granted, free of charge, to any person obtaining a copy7// of this software and associated documentation files (the "Software"), to deal8// in the Software without restriction, including without limitation the rights9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10// copies of the Software, and to permit persons to whom the Software is11// furnished to do so, subject to the following conditions:12// The above copyright notice and this permission notice shall be included in all13// copies or substantial portions of the Software.14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20// SOFTWARE.21// </license>22namespace Ocaramba.Tests.NUnit.Tests23{24 using System.Drawing.Imaging;25 using System.Globalization;26 using global::NUnit.Framework;27 using Ocaramba.Helpers;28 using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;29 [TestFixture]30 public class SaveScreenShotsPageSourceTestsNUnit : ProjectTestBase31 {32 [Test]33 [Category("TakingScreehShots")]34 [Category("NotImplementedInCoreOrUploadDownload")]35 public void SaveFullScreenShotTest()36 {37 var downloadPage = new InternetPage(this.DriverContext).OpenHomePage().GoToFileDownloader();38 var screenShotNumber = FilesHelper.CountFiles(this.DriverContext.ScreenShotFolder, FileType.Png);39#if net4740 Assert.IsNotNull(TakeScreenShot.Save(TakeScreenShot.DoIt(), ImageFormat.Png, this.DriverContext.ScreenShotFolder, string.Format(CultureInfo.CurrentCulture, this.DriverContext.TestTitle + "_first")));41#endif42 var nameOfScreenShot = downloadPage.CheckIfScreenShotIsSaved(screenShotNumber);43 TestContext.AddTestAttachment(nameOfScreenShot);44 Assert.IsTrue(nameOfScreenShot.Contains(this.DriverContext.TestTitle), "Name of screenshot doesn't contain Test Title");45 Assert.IsNotNull(this.DriverContext.TakeAndSaveScreenshot());46 }47 [Test]48 public void SaveWebDriverScreenShotTest()49 {50 var downloadPage = new InternetPage(this.DriverContext).OpenHomePage().GoToFileDownloader();51 var screenShotNumber = FilesHelper.CountFiles(this.DriverContext.ScreenShotFolder, FileType.Png);52 Assert.IsNotNull(downloadPage.SaveWebDriverScreenShot());53 var nameOfScreenShot = downloadPage.CheckIfScreenShotIsSaved(screenShotNumber);54 TestContext.AddTestAttachment(nameOfScreenShot);55 Assert.IsTrue(nameOfScreenShot.Contains(this.DriverContext.TestTitle), "Name of screenshot doesn't contain Test Title");56 }57 [Test]58 [Category("NotImplementedInCoreOrUploadDownload")]59 public void SaveSourcePageTest()60 {61 var basicAuthPage = new InternetPage(this.DriverContext).OpenHomePageWithUserCredentials().GoToBasicAuthPage();62 var name = this.DriverContext.TestTitle + FilesHelper.ReturnFileExtension(FileType.Html);63 FilesHelper.DeleteFile(name, this.DriverContext.PageSourceFolder);64 var pageSourceNumber = FilesHelper.CountFiles(this.DriverContext.PageSourceFolder, FileType.Html);65 Assert.IsNotNull(basicAuthPage.SaveSourcePage());66 basicAuthPage.CheckIfPageSourceSaved();67 Assert.IsTrue(pageSourceNumber < FilesHelper.CountFiles(this.DriverContext.PageSourceFolder, FileType.Html), "Number of html files did not increase");68 }69 }70}...
DownloadPage
Using AI Code Generation
1using Ocaramba;2using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;3using NUnit.Framework;4{5 {6 public void DownloadPageTest()7 {8 var downloadPage = new DownloadPage(this.DriverContext);9 downloadPage.OpenHomePage();10 downloadPage.GoToDownloadPage();11 downloadPage.DownloadFile();12 Assert.IsTrue(downloadPage.IsDownloadFileExist());13 }14 }15}16using Ocaramba;17using Ocaramba.Tests.PageObjects.TheInternet;18using NUnit.Framework;19{20 {21 public void DownloadPageTest()22 {23 var downloadPage = new DownloadPage(this.DriverContext);24 downloadPage.OpenHomePage();25 downloadPage.GoToDownloadPage();26 downloadPage.DownloadFile();27 Assert.IsTrue(downloadPage.IsDownloadFileExist());28 }29 }30}31using Ocaramba;32using Ocaramba.Tests.PageObjects.TheInternet;33using NUnit.Framework;34{35 {36 public void DownloadPageTest()37 {38 var downloadPage = new DownloadPage(this.DriverContext);39 downloadPage.OpenHomePage();40 downloadPage.GoToDownloadPage();41 downloadPage.DownloadFile();42 Assert.IsTrue(downloadPage.IsDownloadFileExist());43 }44 }45}46using Ocaramba;47using Ocaramba.Tests.PageObjects.TheInternet;48using NUnit.Framework;49{50 {51 public void DownloadPageTest()52 {53 var downloadPage = new DownloadPage(this.DriverContext);54 downloadPage.OpenHomePage();55 downloadPage.GoToDownloadPage();56 downloadPage.DownloadFile();57 Assert.IsTrue(downloadPage.IsDownloadFileExist());58 }59 }60}
DownloadPage
Using AI Code Generation
1using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;2using Ocaramba;3using Ocaramba.Types;4using NUnit.Framework;5{6 {7 public void DownloadFile()8 {9 var downloadPage = new DownloadPage(this.DriverContext);10 downloadPage.OpenHomePage();11 downloadPage.DownloadFile();12 }13 }14}
DownloadPage
Using AI Code Generation
1using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;2using Ocaramba;3using NUnit.Framework;4using System;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9{10 {11 private readonly DownloadPage downloadPage;12 public DownloadPageTests(ParallelConfig parallelConfig) : base(parallelConfig)13 {14 downloadPage = new DownloadPage(DriverContext);15 }16 public void DownloadPageTest()17 {18 downloadPage.OpenHomePage();19 downloadPage.GoToDownloadPage();20 downloadPage.DownloadFile();21 }22 }23}24using System;25using System.IO;26using System.Linq;27using System.Reflection;28{29 {30 public static string GetFileName(string filePath)31 {32 return Path.GetFileName(filePath);33 }34 public static string GetFileNameWithoutExtension(string filePath)35 {36 return Path.GetFileNameWithoutExtension(filePath);37 }38 public static string GetFileExtension(string filePath)39 {40 return Path.GetExtension(filePath);41 }42 public static double GetFileSize(string filePath)43 {44 double size = 0;45 if (File.Exists(filePath))46 {47 FileInfo fileInfo = new FileInfo(filePath);48 size = fileInfo.Length;49 }50 return size;51 }52 public static bool IsFileDownloaded(string filePath)53 {54 return File.Exists(filePath);55 }56 public static void DeleteFile(string filePath)57 {58 if (File.Exists(filePath))59 {60 File.Delete(filePath);61 }62 }63 public static string GetDownloadPath()64 {65 var downloadPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Downloads");66 if (!Directory.Exists(downloadPath))67 {68 Directory.CreateDirectory(downloadPath);
DownloadPage
Using AI Code Generation
1using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;2using Ocaramba;3using Ocaramba.Types;4using NUnit.Framework;5using System;6using System.IO;7using System.Reflection;8{9 [Parallelizable(ParallelScope.Fixtures)]10 {11 private readonly DownloadPage _downloadPage;12 public DownloadTest(ParallelConfig parallelConfig) : base(parallelConfig)13 {14 _downloadPage = new DownloadPage(DriverContext);15 }16 [Category(Categories.CI)]17 public void DownloadFileTest()18 {19 _downloadPage.OpenBaseUrl();20 _downloadPage.ClickOnDownloadLink();21 _downloadPage.WaitUntilFileIsDownloaded();22 var fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "some-file.txt");23 Assert.True(File.Exists(fileName));24 File.Delete(fileName);25 }26 }27}28using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;29using Ocaramba;30using Ocaramba.Types;31using NUnit.Framework;32using System;33using System.IO;34using System.Reflection;35{36 [Parallelizable(ParallelScope.Fixtures)]37 {38 private readonly DownloadPage _downloadPage;39 public DownloadTest(ParallelConfig parallelConfig) : base(parallelConfig)40 {41 _downloadPage = new DownloadPage(DriverContext);42 }43 [Category(Categories.CI)]44 public void DownloadFileTest()45 {46 _downloadPage.OpenBaseUrl();47 _downloadPage.ClickOnDownloadLink();48 _downloadPage.WaitUntilFileIsDownloaded();49 var fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "some-file.txt");50 Assert.True(File.Exists(fileName));51 File.Delete(fileName);52 }53 }54}55using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;56using Ocaramba;57using Ocaramba.Types;58using NUnit.Framework;59using System;60using System.IO;61using System.Reflection;
DownloadPage
Using AI Code Generation
1using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;2var downloadPage = new DownloadPage(this.DriverContext);3downloadPage.DownloadFile();4downloadPage.DownloadFileWithProgress();5using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;6var downloadPage = new DownloadPage(this.DriverContext);7downloadPage.DownloadFile();8downloadPage.DownloadFileWithProgress();9using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;10var downloadPage = new DownloadPage(this.DriverContext);11downloadPage.DownloadFile();12downloadPage.DownloadFileWithProgress();13using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;14var downloadPage = new DownloadPage(this.DriverContext);15downloadPage.DownloadFile();16downloadPage.DownloadFileWithProgress();17using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;18var downloadPage = new DownloadPage(this.DriverContext);19downloadPage.DownloadFile();20downloadPage.DownloadFileWithProgress();21using Ocaramba.Tests.PageObjects.PageObjects.TheInternet;22var downloadPage = new DownloadPage(this.Driver
Check out the latest blogs from LambdaTest on this topic:
Recently, I was going through some of the design patterns in Java by reading the book Head First Design Patterns by Eric Freeman, Elisabeth Robson, Bert Bates, and Kathy Sierra.
Even though several frameworks are available in the market for automation testing, Selenium is one of the most renowned open-source frameworks used by experts due to its numerous features and benefits.
Web applications continue to evolve at an unbelievable pace, and the architecture surrounding web apps get more complicated all of the time. With the growth in complexity of the web application and the development process, web application testing also needs to keep pace with the ever-changing demands.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
Traditional software testers must step up if they want to remain relevant in the Agile environment. Agile will most probably continue to be the leading form of the software development process in the coming years.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!