简体   繁体   中英

Run a Selenium test from a aspx

I want to start a Selenium test from within my aspx page. I've installed Selenium with NuGet in my solution.

In the code behind for my webpage I have this:

protected void Page_Load(object sender, EventArgs e)
{
    _driver = new FireFoxDriver();
    _driver.Manage().Window.Maximize();
    _driver.SwitchTo().Window(_driver.CurrentWindowHandle);
    _driver.Manage().Cookies.DeleteAllCookies();
    _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));

    _driver.Navigate().GoToUrl("http://www.google.com/");
    _driver.FindElement(By.Id("lst-ib")).SendKeys("ModelTrains");
    _driver.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);

    _driver.Quit();

}

The code runs, I can step through it, but I don't see the new window or browser instance, I also don't get any error. What I'm I doing wrong?

What you are currently doing is starting up a FireFoxDriver on a web server.

So on the actual server where you are hosting the web site (Server running IIS) you will see selenium in action.

Why don't you use console or winform? if you run on the console app or winform, you can see that.

but if you run on the webform, you can't see it,

because it is running on the IIS express. like a mmc snapshot.

(if you run app that made by console app(.exe), and Jenkins run that app(not you) you can't see browser too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM