I've been trying to get my Grid working with IE, but at some point I need to specify the full path to my driver's exe.
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
DesiredCapabilities ieCapability = DesiredCapabilities.InternetExplorer();
ieCapability.SetCapability(ieOptions.EnsureCleanSession.ToString(), true);
ieCapability.SetCapability(ieOptions.BrowserCommandLineArguments.ToString(), "-private");
I need to know if this can be done via InternetExplorerOptions or DesiredCapabilities or if I just should create an environment variable holding the path to my IE driver.
Thanks!
One of the most common practices i've seen in my Selenium experience, is testers will put their statement in their super class.
Consider the following (I'm a Java programmer, so this will be java code, you can convert to C#):
public class SuperTest {
public SuperTest() {
System.setProperty("webdriver.ie.driver", "C:\\Path\\To\\IEDriver.exe");
}
}
public class Test extends SuperTest {}
You can see how you can do it in the Getting started with Selenium framework (again, Java).
Related
I have an application that exposes some c# objects to an embedded IronPython interpreter like this:
using IronPython.Hosting;
namespace ironpy
{
public class Foo
{
public void bar(string message)
{
System.Console.WriteLine(message);
}
}
class Program
{
static void Main(string[] args)
{
var engine = Python.CreateEngine();
var scope = engine.CreateScope();
var test = new Foo();
scope.SetVariable("foo", test);
string code = "foo.bar('Hello')";
engine.Execute(code, scope);
}
}
}
In practice the python source code comes from an textfile loaded at runtime.
When editing such a source file in VSCode or other editors the language server that provides code completion obviously doesn't have any idea about whats going to be available. So you have no code completion and annoying error squiggles everywhere.
Is it somehow possible to write some sort of plugin/hint/linting file for one of the commonly used language servers to tell them about the exported C# API to get working code completion when editing the python source files?
I found the solution to my problem in the meantime: IronPython Stubs files
https://github.com/gtalarico/ironpython-stubs
In my opinion, defining .py file and implementing codes inside on it is the best way. Then you can execute your .py file like below;
https://stackoverflow.com/a/11779234/4582992
I'm making an app and need to be able to check if settings like : Bluetooth/Phone Rotation/Flashlight/Plane Mode/GPS/Phone Brightness/Silent Mode, are activated on an android phone.
I haven't found any way to do it within Unity, using C#. I found ways to do it using Xamarin but none of them work with Unity (or maybe I haven't done it right), the only way I found is using Java and making it into a plugin and call it in a C# script. But I can't find a clear way to make this work. If this is the only solution could you please explain how to do it, all the documentation I find is from old versions from 2014.
I think there is a simple solution for this but I simply can't find it. And the manifest part is not a problem, I'll add the permissions needed.
In Java the methods you want to call should be public or static, you must build your java source as a library (in build.gradle: apply plugin: 'com.android.library'), and add the .aar to Unity's Assets/Plugins/Android/ folder.
Then you can instantiate your plugin in Unity like so:
// this class string is the package at the top of your Java class extended with the class name, e.g.:
// package com.yourcompany.you.package;
string classString = "com.yourcompany.you.package.className";
// Get the class
var tempAjc = new AndroidJavaClass(classString);
// Here you can call a static method on the class that returns an instance of the class if you want to pass some parameters upon creation
_androidObject = tempAjc.CallStatic<AndroidJavaObject>("CreateInstance",
new object[] {arg1, arg2});
// non static call on your new instance
_androidObject.Call("PassingMoreStuff", initParam);
// if you want to return something from Java to Unity:
int javaVal = _androidObject.Call<int>(methodName, parameters);
I'm moving from a Java environment to .NET and need to write Webdriver tests using a page object model.
In Java I would use the following annotation:
#FindBy(linkText = "More details")
WebElement moreDetailsButton;
Please would someone be able to tell me how to define a WebElement using C#? Also, is the PageFactory.initElements used the same way?
Thanks
Steve
Yes, there is a direct translation.
You are looking for FindsBy:
[FindsBy(How = How.LinkText, Using = "More details")]
private IWebElement moreDetailsButton;
As for the PageFactory.initElements, yes, it's a very similar thing in .NET, usually called in the constructor of the Page Object:
public class LoginPage
{
private IWebDriver _driver;
public LoginPage(IWebDriver driver)
{
_driver = driver;
PageFactory.InitElements(_driver);
}
}
Note, that the Selenium project is entirely open source. You can easily see the source the Page Objects 'helper' classes here.
I'm working on Automation framework using WebDriver with C#. Its working fine with Firefox but not with IE.
I am getting the following error:
IEDriverServer.exe does not exist-The file c:\users\administrator\documents\visual studio 2010\projects\TestProject1\TestProject1\bin\Debug\IEDriverServer.exe does not exist. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list
I am using IE 9 and Windows 7.
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.co.uk");
IWebElement queryBox = driver.FindElement(By.Name("q"));
queryBox.SendKeys("The Automated Tester");
queryBox.SendKeys(Keys.ArrowDown);
queryBox.Submit();
See also .
The IEDriverServer.exe (as well as ChromeDriver.exe) can be downloaded from:
http://selenium-release.storage.googleapis.com/index.html.
To get these to work with your Selenium tests, include the .exe in your test project, and set its properties to 'Copy Always'.
NOTE: You'll have to adjust the Add File dialog to display .exe files.
Doing this will resolve the error.
Here's a simple C# example of how to call the InternetExplorerDriver using the IEDriverServer.exe.
Refactor according to your needs.
Note: the use of driver.Quit() which ensures that the IEDriverServer.exe process is closed, after the test has finished.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.IE;
namespace SeleniumTest
{
[TestClass]
public class IEDriverTest
{
private const string URL = "http://url";
private const string IE_DRIVER_PATH = #"C:\PathTo\IEDriverServer.exe";
[TestMethod]
public void Test()
{
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Navigate();
driver.Close(); // closes browser
driver.Quit(); // closes IEDriverServer process
}
}
}
Per Jim Evans (who works on IEDriverServer)
The .NET bindings don't scan the %PATH% environment variable for the
executable. That means for the .NET bindings only, the
IEDriverServer.exe is expected to either be found in the same
directory as the .NET bindings assembly, or you must specify the
directory where it can be found in the constructor to the
InternetExplorerDriver class.
Failure to do one of these things (or to
set the UseInternalServer property in the InternetExplorerOptions
class) will cause the .NET IE driver implementation to throw an
exception. This is strictly by design, as we want people to begin
using the standalone IEDriverServer.exe, and the ability to use an
"internal" or "legacy" version of the server will be removed in a
future release.
https://groups.google.com/forum/?fromgroups#!topic/webdriver/EvTyEPYchxE
If you're working with Visual Studio and C# I've updated my NareshScaler nuget package to install IEDriverServer, ChromeDriver etc automatically, meaning you can get up and running quicker.
http://nuget.org/packages/NareshScaler
Code for WebDriver using java to run with IE. I believe this concept might be helpful for you using C#:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
File file = new File("C:\\Program Files\\Internet Explorer\\iexplore.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver(capabilities);
If above code doesn't work use the following instead of "File file = new File("C:\Program Files\Internet Explorer\iexplore.exe");":
File file = new File("F:\\Ripon\\IEDriverServer_Win32_2.25.2\\IEDriverServer.exe");
[Note: The version of IEDriverServer and Windows (32 or 64 bit) may vary individual to individual]
Give path only till folder where Internetexplorer.exe is located.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.IO;
namespace Automation
{
class To_Run_IE
{
static void Main(string[] args)
{
//Keep Internetexplorer.exe in "D:\Automation\32\Internetexplorer.exe"
IWebDriver driver = new InternetExplorerDriver(#"D:\Automation\32\"); \\Give path till the exe folder
//IWebDriver driver = new Firefoxdriver()
driver.Navigate().GoToUrl("http://www.google.com/");
driver.Manage().Window.Maximize();
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
query.Submit();
System.Console.WriteLine("Page title is: " + driver.Title);
driver.Quit();
}
} }
public IWebDriver IEWebDriver()
{
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
webDriver = new InternetExplorerDriver(ConfigurationSettings.AppSettings["IDEServerPath"].ToString(), options);//Path of ur IE WebDriver,Here I stored it in a AppConfig File
return webDriver;
}
I'm just having a play with Roslyn but unsure on how to do the following.
To keep this simple, lets say I have a host program which has a method like so
public void DisplayMessage(string message)
{
MessageBox.Show(message);
}
Can I then have a script file called MyScript.csx and then somewhere in the script have something like
void Main()
{
Host.DisplayMessage("I am a script");
}
Then I have the host load the file and execute it.
If this sort of thing can't be done, is there a scripting system/engine based on c# that can do it?
These are the requirements
Host application can load script from a file.
Script file is written in c# and so can be written using VS2010 with syntax etc
Script file can access host public methods, properties etc
I wrote an Introduction to the Roslyn scripting API that covers most of what you're asking. The ScriptEngine type also has a ExecuteFile method that would be useful for what you're trying to do.
Disclaimer: I work for Microsoft on the Roslyn project.
Yes, you can do what you want using Roslyn.
First, create a public Host class that has a public DisplayMessage method (or use a existing class). Then create ScriptEngine, specifying the assembly that contains Host as a reference. After that, you can call ExecuteFile() on your file, with the Host object as another parameter:
var engine = new ScriptEngine(references: new[] { typeof(Host).Assembly });
engine.ExecuteFile("MyScript.csx", new Host());
The script files doesn't need any Main() method, and you call the method on the host object directly:
DisplayMessage("I am a script");