Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Protractor for .NET

Info

This directory contains a fork of protractor-net project with slightly more complete and up-to-date Javascript code (PR pending) and significant number of tests exploring various typical scenaios.

Example

Screen Recording

IWebDriver driver = new FirefoxDriver();
NgWebDriver ngDriver = new NgWebDriver(driver);
String base_url = "http://juliemr.github.io/protractor-demo/";

ngDriver.Navigate().GoToUrl(base_url);

StringAssert.AreEqualIgnoringCase(ngDriver.Title, "Super Calculator");
var ng_first_operand = ngDriver.FindElement(NgBy.Model("first"));
ng_first_operand.SendKeys("8");

NgWebElement ng_second_operand = ngDriver.FindElement(NgBy.Input("second"));
ng_second_operand.SendKeys("5");

IWebElement math_operator_element = ngDriver.FindElement(NgBy.SelectedOption("operator"));
Assert.AreEqual(math_operator_element.Text, "+");

ReadOnlyCollection<NgWebElement> ng_math_operators = ngDriver.FindElements(NgBy.Options("value for (key, value) in operators"));
NgWebElement ng_substract_math_operator = ng_math_operators.First(op => op.Text.Equals("-", StringComparison.Ordinal));
Assert.IsNotNull(ng_substract_math_operator);
ng_substract_math_operator.Click();

NgWebElement result_element = ngDriver.FindElement(NgBy.Binding("latest"));
Assert.AreEqual("3", result_element.Text);
highlight(result_element.WrappedElement);

Note

Local Angular files may be placed under Samples directory and copied into output directory of the Test

base_url = new System.Uri(Path.Combine( Directory.GetCurrentDirectory(), testpage)).AbsoluteUri;
ngDriver.Navigate().GoToUrl(base_url);

However, local files work only with PhantomJSDriver - error varies with the browser:

| Firefox Driver | System.InvalidOperationException : Access to 'file:///...' from script | | Chrome Driver | System.Net.WebException Timeout exception | | InternetExplorer Driver | System.InvalidOperationException : Page reload detected |

For desktop browser-hosted tests, start a web server locally and point web root to the bin/Debug directory of the Test project: then update the code to use base_url = String.Format("http://localhost/{0}", testpage);

PhantomJS vs. Chrome or Firefox in Headless mode

The significant subset of Protractor.net test suite has been designed around static files accessed via file:/// with basically one Angular feature per page. This seemed reasonable: no server behavior was examined by any of the Protractor / Angular tests, all action took place in the browser.

This shortcut never worked with real browsers, regardless they are visible or headless.

Starting with version 3.14 Selenium asseblies for .net sease to have PhantomJS support, therefore the localfile tests are currently failing.

After a very noticeable delay every local file test fails with an exception

OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server
for URL http://localhost:65087/session/721da078cad526a4acfa0a762a7b45d9/execute_async timed out after 60 seconds.
  ----> System.Net.WebException : The request was aborted: The operation has timed out.

It was originally considered somewhat overhead to host the vanilla web server in .net application just to host those static pages, compared to Java where it is more than somewhat easier. To support Selenium assemblies moving forward, a simple one derived from quick web server (consdering if a more substantial investment like nosquare/embedio is worthwhile). is now hosted during test run for LocalTests. This requires running IDE as administratoruser on Windows.

The alternative approach considered for HTML parsing testing needs is to bundle into the project file a similar minimal server, but wrapped in Powershell script, and only run it elevated. e.g. simple web server in PowerShell or creating PowerShell Web Server. This is a work in progress.

Author

Serguei Kouzmine Screen Recording converted to gif via convert-to-gif