Note that there are some explanatory texts on larger screens.

plurals
  1. POIntegration testing with Selenium Webdrive on a project with Continous Integration
    text
    copied!<p>I have a question. When I run a selenium webdrive integration test on my webb app, the web app must be running, because selenium browses to a debug version of my app (which is launched in IIS Express from Visual Studios). The problem is that if I want to achive this using CI development practice, on a dedicated CI machine, that machine have to be running a version of my webb app that's based on the current mainline code from subversion directory. </p> <p>The code base constantly changes, and so theoretically you could run and restart the web app on the CI machine with code from the subversion dir, so that the tests always cover the latests commit. </p> <p>Each individual developer on the project doesn't have any problems running the integration tests on the pre-commit build/test. And the unit tests can be handled with Cruise Control, MsBuild, subversion and NUnit working together. But running the integration tests (selenium webdrive test) on the integration server automatically with dynamic codebase is what I'm wondering about. Does anyone have experience of this, perhaps examples?</p> <p><em><strong>EDIT</em>:</strong> Arran has suggested that you can utilize a dedicated test enviroment to solve this problem. I don't quite practically understand how dedicated test enviroments works, and how practically it would works to solve this problem. The answers received doesn't seems to be automatable to the point where it can be implemented with the concurrent integration flow of Continous Integration. Does anyone else have any experience or thoughts on the matter?</p> <p>This is the Selenium Webdrive code for reference:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using OpenQA.Selenium; using OpenQA.Selenium.Support; using OpenQA.Selenium.Support.UI; using NUnit.Framework; using OpenQA.Selenium.Firefox; using System.Threading.Tasks; using System.Threading; namespace ChatProj.Tests { [TestFixture] class WebDriverTestClass { private IWebDriver _driver; private StringBuilder verificationErrors; private string baseURL; private bool acceptNextAlert = true; [SetUp] public void SetUp() { _driver = new FirefoxDriver(); baseURL = "http://localhost:59932/"; verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { _driver.Quit(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Repeat(2)] [Test] public void TestFirefox() { _driver.Navigate().GoToUrl(baseURL + ""); IWebElement userNameInput = _driver.FindElement(By.Name("UserName")); userNameInput.SendKeys("Svenneglenne"); IWebElement passwordInput = _driver.FindElement(By.Name("Password")); passwordInput.SendKeys("password"); _driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click(); WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(10)); IWebElement messageBox = wait.Until&lt;IWebElement&gt;((d) =&gt; { return d.FindElement(By.Id("message")); }); IWebElement adminMessageWaiter = wait.Until&lt;IWebElement&gt;((d) =&gt; { return d.FindElement(By.XPath("//ul[@id='discussion']/li[1]")); }); System.Console.Out.WriteLine("STUFF"); //IWebElement query = driver.FindElement(By.Id("message")); String textSnippet = "This is a selenium test"; adminMessageWaiter.SendKeys(""); messageBox.SendKeys("This is a selenium test"); IWebElement waitForJava = wait.Until&lt;IWebElement&gt;((d) =&gt; { return d.FindElement(By.XPath("//ul[@id='discussion']/li[1]")); }); //Thread.Sleep(2000); WaitForPageLoad(10); _driver.FindElement(By.Id("sendmessage")).Click(); //Thread.Sleep(2000); _driver.FindElement(By.LinkText("Logg")).Click(); IWebElement loggWaiter = wait.Until&lt;IWebElement&gt;((d) =&gt; { return d.FindElement(By.XPath("//div[@id='body']/section/table/tbody/tr/td[2]")); }); Assert.AreEqual(textSnippet, loggWaiter.Text); _driver.FindElement(By.LinkText("MPM Graph")).Click(); Thread.Sleep(2000); } public void WaitForPageLoad(int maxWaitTimeInSeconds) { string state = string.Empty; try { WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(maxWaitTimeInSeconds)); //Checks every 500 ms whether predicate returns true if returns exit otherwise keep trying till it returns ture wait.Until(d =&gt; { try { state = ((IJavaScriptExecutor)_driver).ExecuteScript(@"return document.readyState").ToString(); } catch (InvalidOperationException) { //Ignore } catch (NoSuchWindowException) { //when popup is closed, switch to last windows _driver.SwitchTo().Window(_driver.WindowHandles.Last()); } //In IE7 there are chances we may get state as loaded instead of complete return (state.Equals("complete", StringComparison.InvariantCultureIgnoreCase) || state.Equals("loaded", StringComparison.InvariantCultureIgnoreCase)); }); } catch (TimeoutException) { //sometimes Page remains in Interactive mode and never becomes Complete, then we can still try to access the controls if (!state.Equals("interactive", StringComparison.InvariantCultureIgnoreCase)) throw; } catch (NullReferenceException) { //sometimes Page remains in Interactive mode and never becomes Complete, then we can still try to access the controls if (!state.Equals("interactive", StringComparison.InvariantCultureIgnoreCase)) throw; } catch (WebDriverException) { if (_driver.WindowHandles.Count == 1) { _driver.SwitchTo().Window(_driver.WindowHandles[0]); } state = ((IJavaScriptExecutor)_driver).ExecuteScript(@"return document.readyState").ToString(); if (!(state.Equals("complete", StringComparison.InvariantCultureIgnoreCase) || state.Equals("loaded", StringComparison.InvariantCultureIgnoreCase))) throw; } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload