Did you know that Selenium already supports PhantomJS?
WebDriver is a specification for controlling the behavior of a web browser. PhantomJS is a headless WebKit scriptable with a JavaScript API. Ghost Driver is a WebDriver implementation that uses PhantomJS for its back-end. Selenium is a software testing framework for web applications. Selenium WebDriver is the successor to Selenium RC. The Selenium WebDriver NuGet Package is a .NET client for for Selenium WebDriver that includes support for PhantomJs via GhostDriver.
NuGet Packages
You need only install two NuGet packages in order to use PhantomJS with WebDriver. You will probably also want which ever Unit Testing framework you prefer. As always, I suggest xUnit.
PhantomJSDriver
After installing those, using the PhantomJSDriver is as easy as any other WebDriver!
const string PhantomDirectory =
@"..\..\..\packages\phantomjs.exe.1.8.1\tools\phantomjs";
[Fact]
public void GoogleTitle()
{
using (IWebDriver phantomDriver = new PhantomJSDriver(PhantomDirectory))
{
phantomDriver.Url = "http://www.google.com/";
Assert.Contains("Google", phantomDriver.Title);
}
}
Enjoy,
Tom
How do you post data to a form?
ReplyDeletePhantomJS is a complete browser like any other. There are several ways to post a form, the most simple being to click the submit button. :)
DeleteI assume he was asking for syntax in C# for filling a form and posting it.
Deletehi tom,
ReplyDeletedo you know how to run phantomjs.exe separately,
i try to figure out how to make this condition :
1. run phantomjs.exe (outside of our appication)
2. in our application the initialization will like this :
//no phantomjs path
- IWebDriver phantomDriver = new PhantomJSDriver()
// how to force the phantomDriver to use the exiting phantomjs.exe that already running on the system
anyway iam new in phantomjs
thanks,
Ifan
Tom, Can you point me in the right direction. When using PhantomJS and adding cookies, how does one do this via .NET
ReplyDeleteThe examples provided on the PhantomJS page are in another language. Is there a C# api or have you figured out a way to add cookies?
Great, a headless web driver implementation, what I was looking for. Thanks!
ReplyDeletenot getting anything how to instal PhantomJS etc
ReplyDelete