I am using Selenium RC using c# and need to take screenshot for the test case failed, I have to perform these test on IE 8.
I got lot of tutorials for Firefox but didn't find any for the IE8.
Thanks in advance.
You can use the Selenium Web Driver to take a screenshot of IE pretty easily. The code would look something like this:
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.com");
TakeScreenshot(driver, #"C:\screenshot.png");
You can download the Web Driver here: https://code.google.com/p/selenium/downloads/list
Add it to your project and you are off and running.
Related
Could anyone help me to elaborate procedure for integrating selenium C# script with neoload tool.i wanted to integrate selenium C# and Appium C# coding with neoload .So I went though some steps in documentation and unable to run the example code and didn't get the point how we can integrated with selenium/appium C# script with neoload for chrome or any browser and perform load testing for web or mobile application with same tool .Could you please have a look on shared screen shot and help me to share valuable document with any simple example for understanding the concept/getting some confidence.Thanks for giving valuable time
I modified the code found here for the chrome driver: https://www.neotys.com/documents/doc/neoload/latest/en/html/#24364.htm
DesiredCapabilities cap = new DesiredCapabilities();
NLWebDriverFactory.AddProxyCapabilitiesIfNecessary(cap);
object proxyCapability = cap.GetCapability(CapabilityType.Proxy);
ChromeProfile profile = new ChromeProfile();
if (proxyCapability != null) {
profile.SetProxyPreferences(proxyCapability as Proxy);
}
ChromeDriver webDriver = new ChromeDriver(profile);
Your problem is that you need to provide the ChromeDriver with a profile which has the DesiredCapabilities whereas you try to apply them directly to the driver.
I am using Selenium and Firefox for automated testing, and I need the files to download automatically. Here are two links that I've used to setup my code.
Auto download PDF in Firefox
Set Firefox profile to download files automatically using Selenium and Java
To summarize the articles, the code should look like this:
FirefoxOptions options = new FirefoxOptions();
options.setPreference("browser.download.folderList", 2);
options.setPreference("browser.download.dir", "C:\\Windows\\temp");
options.setPreference("browser.download.useDownloadDir", true);
options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
options.setPreference("pdfjs.disabled", true); // disable the built-in PDF viewer
WebDriver driver = new FirefoxDriver(options);
When I run my test, the auto-download fails. I checked in the about:config and the settings have been changed as intended by the code.
(about:config screenshot)
Also, within that driver instance, if I change any setting and then reapply the same setting, the auto-download works. Is there a setting or step with the webdriver that I'm missing that then applies the new settings?
Here are the Selenium, Firefox, and GeckoDriver versions I've tested with:
Selenium: v3.12.0
Firefox: 59.0.3, 60.0.1
GeckoDriver: v0.19.0-win64, v0.20.0-win64, v0.21.0-win64
As far as i know is pretty difficult download files with selenium because the browser open some dialogs that is not possible control from javascript. Watch this link, I hope will be useful
I am trying to upload a file in headless browser. For firefox driver sendkeys is working for me but for phantomjs sendkeys doesn't work for me.
// Works for FirefoxDriver
// Doesn't work for PhantomjsDriver
IWebElement UploadResourceBrowseButton = driver.FindElement(By.Id("files"));
UploadResourceBrowseButton.SendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg");
Tried another solution for Phantomjs but doesn't work
// Tried this as well but doesn't work
((PhantomJSDriver)driver).ExecutePhantomJS("var page = this; page.uploadFile('input[type=file]', 'C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg');");
Try changing input[type=file] to input[type=\"file\"]
I use Selenium WebDriver in my C# winforms application. When I run application and open Firefox, my addons are disabled. How to leave the addons enabled?
You can explicitly set the desired addons to ON. For example, if you want to enable firebug, find out the location of the zip or xpi of the addon and then use the following code:
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.AddExtension("C:\\firebug.xpi");
ffprofile.SetPreference("extensions.firebug.currentVersion", "1.11.4");
IWebDriver driver = new FirefoxDriver(ffprofile);
The only thing I did to resolve is just by adding following to the pom.xml and it worked fine for me. Currently I'm running tests on Firefox 43.0.3 with Selenium 2.48.2. and also by have a dependency for the Firefox browser in the pom.xml.
org.seleniumhq.selenium selenium-firefox-driver 2.48.2
org.seleniumhq.selenium selenium-java 2.48.2
After using this if you fail to use your add on than drop message I will provide you some more options but hope fully you will get result from this.
Could anyone suggest headless browser for .NET that supports cookies and authomatically javascript execution?
Selenium+HtmlUnitDriver/GhostDriver is exactly what you are looking for. Oversimplified, Selenium is library for using variety of browsers for automation purposes - testing, scraping, task automation.
There are different WebDriver classes with which you can operate an actual browser. HtmlUnitDriver is a headless one. GhostDriver is a WebDriver for PhantomJS, so you can write C# while actually PhantomJS will do the heavy lifting.
Code snippet from Selenium docs for Firefox, but code with GhostDriver (PhantomJS) or HtmlUnitDriver is almost identical.
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
class GoogleSuggest
{
static void Main(string[] args)
{
// driver initialization varies across different drivers
// but they all support parameter-less constructors
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
query.Submit();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
System.Console.WriteLine("Page title is: " + driver.Title);
driver.Quit();
}
}
If you run this on Windows machine you can use actual Firefox/Chrome driver because it will open an actual browser window which will operate as programmed in your C#. HtmlUnitDriver is the most lightweight and fast.
I have successfully ran Selenium for C# (FirefoxDriver) on Linux using Mono. I suppose HtmlUnitDriver will also work as fine as the others, so if you require speed - I suggest you go for Mono (you can develop, test and compile with Visual Studio on Windows, no problem) + Selenium HtmlUnitDriver running on Linux host without desktop.
I am not aware of a .NET based headless browser but there is always PhantomJS which is C/C++ and it works fairly well for assisting in unit testing of JS with QUnit.
There is also another relevant question here which might help you - Headless browser for C# (.NET)?