Reputation: 60882
I would like to be able to run this app without using NUNIT, specifically because I need to run it every hour. I am a beginner at NUNIT and selenium, and was wondering what I can do to convert this into a console app instead of having to run it through NUNIT?
The code is below. Thank you so much for your help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Selenium;
using System.Threading;
using System.Data;
using System.IO;
namespace LogIn
{
[TestFixture]
public class LogIn
{
public static ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "https://.............aspx");
selenium.Start();
selenium.SetSpeed("900");
selenium.WindowMaximize();
selenium.WindowFocus();
verificationErrors = new StringBuilder();
}
[Test]
public void Login()
{
selenium.SetSpeed("900");
selenium.Open("/Login.aspx");
Assert.AreEqual("stuff", selenium.GetTitle());
selenium.Type("id=ctl00_cphBody_objLogin_UserName", "username");
selenium.Type("id=ctl00_cphBody_objLogin_Password", "Pass");
selenium.Click("id=ctl00_cphBody_objLogin_LoginImageButton");
selenium.WaitForPageToLoad("30000");
Assert.AreEqual("labs", selenium.GetTitle());
//i dont understand why do we need this?
/*
try
{
Assert.AreEqual("Orders - Drug Testing ", selenium.GetText("link=Orders - Drug Testing "));
}
catch (AssertionException e)
{
Console.WriteLine(e.Message + " " + DateTime.Now);
}
*/
Console.WriteLine("Congrats, you are logined successfully. " + DateTime.Now);
selenium.Click("link=Specimen Volume Report - Drugs");
selenium.WaitForPageToLoad("30000");
selenium.Click("id=ctl00_cphBody_dtpFrom");
selenium.Type("id=ctl00_cphBody_dtpFrom", DateTime.Now.ToString("MM/dd/yyyy"));
selenium.Type("id=ctl00_cphBody_dtpTo", DateTime.Now.ToString("MM/dd/yyyy"));
selenium.Click("id=ctl00_cphBody_btnExport");
selenium.SetSpeed("6000");
Console.WriteLine("Waiting for result complete");
selenium.IsTextPresent("Specimen Volume Report");
selenium.IsTextPresent("Display Specimen Detail");
}
[TearDown]
public void FullTearDown()
{
selenium.Stop();
}
}
}
Upvotes: 0
Views: 1634
Reputation: 92
make a new console app. import the selenium driver (the nuget pkg should load appium as a prereq). start writing static voids without the [Test] banner atop. run them and handle your exceptions, log errors.
I actually find NUnit to be more of a hindrance than a help, whether or not I use it I have issues getting long-term functional/stress tests to run.
Calabash, appium, anything more than good old ADB is very prone to memory leaks and I suspect designed only for quicker unit tests.
UItest cloud even puts a limit, 6 hours per device, 30 minutes per test, 10 minutes per calabash step. In my opinion they set the bar ridiculously low and encourage stress testing to be done in house
Upvotes: 1
Reputation: 21
This works for me with selenium webdriver not selenium rc:
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
public static IWebDriver WebDriver;
void Main()
{
var url = "...";
var capabilitiesInternet = new OpenQA.Selenium.Remote.DesiredCapabilities();
capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
IWebDriver driver = new InternetExplorerDriver(Path.GetDirectoryName (Util.CurrentQueryPath));
// Navigate to url
driver.Navigate().GoToUrl(url);
// Login
driver.FindElement(By.Name("login")).SendKeys("...");
driver.FindElement(By.Name("password")).SendKeys("...");
driver.FindElement(By.ClassName("button")).Click();
Upvotes: 1
Reputation: 8069
Why not simply have your console app (or scheduled task or whatever) simply execute the NUnit tests via the command line? (ie, call nunit-console passing your selenium tests as an argument..)
Upvotes: 1