Goal:
To use Microsofts IIS express when using Selenium. In othe words, execute unit testing in debug mode.
Problem:
i don't know how to make it working in order to use IIS express by using C# code. in other word, I can't initiate the IIS express with c# code. What am I missing in order to execute the IIS so I can enter the webpage "localhost:52844" and then enable to use the sourcecode of selenium?
Info:
*Im using ASP.net mvc.
*The sourcode is
ASP.NET MVC + Selenium + IISExpress | Stephen Walther[
^]
*I have seen some youtube clip that you an use Aspnet mvc in relation to Selenium.
*Im using the regular webpage that is created by Microsoft. Please take a look at the picture below.
*I have added the code "" in html page.
*Im using VS2013
*Im only interrested in Firefox
Thank you!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MvcApplication11;
using MvcApplication11.Controllers;
using OpenQA.Selenium;
namespace MvcApplication11.Tests.Controllers
{
[TestClass]
public class HomeControllerTests : SeleniumTest
{
public HomeControllerTests() : base("MvcApplication11") { }
[TestMethod]
public void IndexFirefoxTest()
{
this.FirefoxDriver.Navigate().GoToUrl(this.GetAbsoluteUrl("/home/index"));
this.FirefoxDriver.FindElement(By.Id("btn")).Click();
Assert.IsTrue(this.FirefoxDriver.FindElement(By.Id("testd")).Displayed);
}
}
}
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using System.IO;
namespace MvcApplication11.Tests.Controllers
{
[TestClass]
public abstract class SeleniumTest {
const int iisPort = 52844;
private string _applicationName;
private Process _iisProcess;
protected SeleniumTest(string applicationName) {
_applicationName = applicationName;
}
public FirefoxDriver FirefoxDriver { get; set; }
[TestInitialize]
public void TestInitialize() {
StartIIS();
this.FirefoxDriver = new FirefoxDriver();
}
[TestCleanup]
public void TestCleanup() {
if (_iisProcess.HasExited == false) {
_iisProcess.Kill();
}
this.FirefoxDriver.Quit();
}
private void StartIIS() {
var applicationPath = GetApplicationPath(_applicationName);
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
_iisProcess = new Process();
_iisProcess.StartInfo.FileName = programFiles + "\\IIS Express\\iisexpress.exe";
_iisProcess.StartInfo.Arguments = string.Format("//path:" + applicationPath + " //port:" + iisPort);
_iisProcess.Start();
}
protected virtual string GetApplicationPath(string applicationName) {
var solutionFolder = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)));
return Path.Combine(solutionFolder, applicationName);
}
public string GetAbsoluteUrl(string relativeUrl) {
if (!relativeUrl.StartsWith("/")) {
relativeUrl = "/" + relativeUrl;
}
return String.Format("http://localhost:{0}{1}", iisPort, relativeUrl);
}
}
}
What I have tried:
Well i have tried a lot and made lots of test and google around but I still cannot find a solution in order to execute unit testing in debug mode.