Webdriver disable enhanced protected mode - webdriver

I am using webdriver on IE11. And per selenium there are a set of required setting to run in IE11 one of them is to disabled "enhanced protected mode" in Internet Option > Advanced > Security (not the same as the enabled protected mode in Internet Option > Security)
The problem is, my group policy's has those field disabled, meaning I cannot turn them off without requesting for a group policy change. I was wondering if there is a IE capability or option out there that can work around this issue like the caps['ignoreProtectedModeSettings'] = True for the Internet Option > Security Enable Protection Mode setting
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

Please try to use the InternetExplorerOptions object and set the IntroduceInstabilityByIgnoringProtectedModeSettings property to true in C# application, code as below:
private const string URL = #"https://www.bing.com/";
private const string IE_DRIVER_PATH = #"E:\webdriver\IEDriverServer_x64_3.14.0"; // where the Selenium IE webdriver EXE is.
static void Main(string[] args)
{
InternetExplorerOptions opts = new InternetExplorerOptions() {
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
IgnoreZoomLevel = true,
};
using (var driver = new InternetExplorerDriver(IE_DRIVER_PATH, opts))
{
driver.Navigate().GoToUrl("https://www.bing.com/");
//someTextbox.SendKeys("abc123");
var element = driver.FindElementById("sb_form_q");
var script = "document.getElementById('sb_form_q').value = 'webdriver';";
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript(script, element);
//element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
}
}
If you application is a Java application, try to use the following code:
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("nativeEvents", false);
cap.setCapability("unexpectedAlertBehaviour", "accept");
cap.setCapability("ignoreProtectedModeSettings", true);
cap.setCapability("disable-popup-blocking", true);
cap.setCapability("enablePersistentHover", true);
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
InternetExplorerOptions options = new InternetExplorerOptions();
options.merge(cap);
WebDriver driver = new InternetExplorerDriver(options);
Code from this link.

Related

How to disable image loading on ChromiumWebBrowser?

I'm using ChromiumWebBrowser in my project, but I don't need the browser load images. I tried to find in CefSettings but don't found anything. so how to disable load images?
You can use disable-image-loading in CefCommandLineArgs. It works for me.
public BrowserForm() {
InitializeComponent();
var settings = new CefSettings();
settings.CefCommandLineArgs.Add("disable-image-loading", "1");
CefSharp.Cef.Initialize(settings);
browser = new ChromiumWebBrowser("") {
Dock = DockStyle.Fill,
};
Controls.Add(browser);
}

Application insights working without config

I'm building a small library that use Application Insights.
Is there a possibility Application Insights working without ApplicationInsights.config file?
I tried remove and add the modules manually at constructor, but it didn't work.
Edited
I did something like that:
dependencies = new DependencyTrackingTelemetryModule();
dependencies.Initialize(configuration);
exceptionTelemetryModule = new UnhandledExceptionTelemetryModule();
exceptionTelemetryModule.Initialize(configuration);
unobservedExceptionTelemetry = new UnobservedExceptionTelemetryModule();
unobservedExceptionTelemetry.Initialize(configuration);
serverTelemetryChannel = new ServerTelemetryChannel();
serverTelemetryChannel.DeveloperMode = true;
serverTelemetryChannel.Initialize(configuration);
azureInstanceMetadataTelemetry = new AzureInstanceMetadataTelemetryModule();
azureInstanceMetadataTelemetry.Initialize(configuration);
var developer = new DeveloperModeWithDebuggerAttachedTelemetryModule();
developer.Initialize(configuration);
configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
client = new TelemetryClient(configuration);
A minimalistic setup can be done like this.
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DependencyCollector;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
..
..
..
private static void setupApplicationInsights()
{
// Setup Channel, Initializers, and Sampling
// Nugets Required: "Microsoft.ApplicationInsights", "Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel"
var channel = new ServerTelemetryChannel();
var config = TelemetryConfiguration.Active;
config.InstrumentationKey = "putikey";
channel.Initialize(config);
TelemetryConfiguration.Active.TelemetryChannel = channel;
//Setup TelemetryInitializers...
config.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
//Setup Sampling
config.TelemetryProcessorChainBuilder.UseAdaptiveSampling();
// Setup modules...
// Nugets : Microsoft.ApplicationInsights.DependencyCollector
DependencyTrackingTelemetryModule dep = new DependencyTrackingTelemetryModule();
dep.Initialize(config);
}

Http Passthrough Pluggable Protocol for Firefox

How can I make an http passthrough pluggable protocol for IE work in Firefox?
Alternatively, how to develop one for Firefox? Any examples would be appreciated.
Thanks.
On Firefox, if you would like to bypass a default behavior in a "pluggable" manner, you could write an NPAPI based plugin. Let's say that the documentation is thin on this subject... but to get you started, you could consult this.
With an NPAPI plugin, you have access to the whole OS and thus are free to expose any other resources to Firefox.
Write an XPCOM object that implements nsIObserver. Then create listener for http-on-modify-request and http-on-examine-response.
var myObj = new MyObserver(); //implements nsIObserver
var observerService = Components.classes["#mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(myObj "http-on-modify-request", false);
observerService.addObserver(myObj, "http-on-examine-response", false);
Write an XPCOM object that implements nsIProtocolHandler. For example, you can access local images from web pages:
const Cu = Components.utils;
const Ci = Components.interfaces;
const Cm = Components.manager;
const Cc = Components.classes;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");+
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
/***********************************************************
class definition
***********************************************************/
function sampleProtocol() {
// If you only need to access your component from JavaScript,
//uncomment the following line:
this.wrappedJSObject = this;
}
sampleProtocol.prototype = {
classDescription: "LocalFile sample protocol",
classID: Components.ID("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"),
contractID: "#mozilla.org/network/protocol;1?name=x-localfile",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
//interface nsIProtocolHandler
allowPort :function(port, scheme)
{
if ((port == 80)&&(scheme == x-localfile)) {
return true;
}
else
{
return false;
}
},
newChannel: function(aURI)
{
// Just example. Implementation must parse aURI
var file = new FileUtils.File("D:\\temp\\getImage.jpg");
var uri = NetUtil.ioService.newFileURI(file);
var channel = NetUtil.ioService.newChannelFromURI(uri);
return channel;
},
newURI(aSpec, aOriginCharset, aBaseURI)
{
//URI looks like x-localfile://example.com/image1.jpg
var uri = Cc["#mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
uri.spec = aSpec;
return uri;
},
scheme: "x-localfile",
defaultPort: 80,
protocolFlags: 76
};
var components = [sampleProtocol];
if ("generateNSGetFactory" in XPCOMUtils)
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components); // Firefox 4.0 and higher
else
var NSGetModule = XPCOMUtils.generateNSGetModule(components); // Firefox 3.x
Be carefull! This approach can create vulnerability

Pause and resume download in flex?

Is it possible in an air application to start a download, pause it and after that resume it?
I want to download very big files (1-3Gb) and I need to be sure if the connection is interrupted, then the next time the user tries to download the file it's start from the last position.
Any ideas and source code samples would be appreciated.
Yes, you would want to use the URLStream class (URLLoader doesn't support partial downloads) and the HTTP Range header. Note that there are some onerous security restrictions on the Range header, but it should be fine in an AIR application. Here's some untested code that should give you the general idea.
private var _us:URLStream;
private var _buf:ByteArray;
private var _offs:uint;
private var _paused:Boolean;
private var _intervalId:uint;
...
private function init():void {
_buf = new ByteArray();
_offs = 0;
var ur:URLRequest = new URLRequest( ... uri ... );
_us = new URLStream();
_paused = false;
_intervalId = setInterval(500, partialLoad);
}
...
private function partialLoad():void {
var len:uint = _us.bytesAvailable;
_us.readBytes(_buf, _offs, len);
_offs += len;
if (_paused) {
_us.close();
clearInterval(_intervalId);
}
}
...
private function pause():void {
_paused = true;
}
...
private function resume():void {
var ur:URLRequest = new URLRequest(... uri ...);
ur.requestHeaders = [new URLRequestHeader("Range", "bytes=" + _offs + "-")];
_us.load(ur);
_paused = false;
_intervalId = setInterval(500, partialLoad);
}
if you are targeting mobile devices, maybe you should take a look at this native extension: http://myappsnippet.com/download-manager-air-native-extension/ it supports simultaneous resumable downloads with multi-section chunks to download files as fast as possible.

How do I get an already (basic) authenticated context to call a web service behind the same authentication?

I have a site behind basic authentication (IIS6).
Part of this site calls a web service that is also part of the site and thus behind basic authentication as well.
However, when this happens the calling code receives a 401 Authentication Error.
I've tried a couple of things, with the general recommendation being code like this:
Service.ServiceName s = new Service.ServiceName();
s.PreAuthenticate = true;
s.Credentials = System.Net.CredentialCache.DefaultCredentials;
s.Method("Test");
However, this does not seem to resolve my problem.
Any advice?
Edit
This seems to be a not uncommon issue but so far I have found no solutions.
Here is one thread on the topic.
Solution: (I am almost certain this will help someone)
See this link for the source of this solution in VB (thanks jshardy!), all I did was convert to C#.
NB: You must be using ONLY basic authentication on IIS for this to work, but it can probably be adapted. You also need to pass a Page instance in, or at least the Request.ServerVariables property (or use 'this' if called from a Page code-behind directly). I'd tidy this up and probably remove the use of references but this is a faithful translation of the original solution and you can make any amendments necessary.
public static void ServiceCall(Page p)
{
LocalServices.ServiceName s = new LocalServices.ServiceName();
s.PreAuthenticate = true; /* Not sure if required */
string username = "";
string password = "";
string domain = "";
GetBasicCredentials(p, ref username, ref password, ref domain);
s.Credentials = new NetworkCredential(username, password, domain);
s.ServiceMethod();
}
/* Converted from: http://forums.asp.net/t/1172902.aspx */
private static void GetBasicCredentials(Page p, ref string rstrUser, ref string rstrPassword, ref string rstrDomain)
{
if (p == null)
{
return;
}
rstrUser = "";
rstrPassword = "";
rstrDomain = "";
rstrUser = p.Request.ServerVariables["AUTH_USER"];
rstrPassword = p.Request.ServerVariables["AUTH_PASSWORD"];
SplitDomainUserName(rstrUser, ref rstrDomain, ref rstrUser);
/* MSDN KB article 835388
BUG: The Request.ServerVariables("AUTH_PASSWORD") object does not display certain characters from an ASPX page */
string lstrHeader = p.Request.ServerVariables["HTTP_AUTHORIZATION"];
if (!string.IsNullOrEmpty(lstrHeader) && lstrHeader.StartsWith("Basic"))
{
string lstrTicket = lstrHeader.Substring(6);
lstrTicket = System.Text.Encoding.Default.GetString(Convert.FromBase64String(lstrTicket));
rstrPassword = lstrTicket.Substring((lstrTicket.IndexOf(":") + 1));
}
/* At least on my XP Pro machine AUTH_USER is not set (probably because we're using Forms authentication
But if the password is set (either by AUTH_PASSWORD or HTTP_AUTHORIZATION)
then we can use LOGON_USER*/
if (string.IsNullOrEmpty(rstrUser) && !string.IsNullOrEmpty(rstrPassword))
{
rstrUser = p.Request.ServerVariables["LOGON_USER"];
SplitDomainUserName(rstrUser, ref rstrDomain, ref rstrUser);
}
}
/* Converted from: http://forums.asp.net/t/1172902.aspx */
private static void SplitDomainUserName(string pstrDomainUserName, ref string rstrDomainName, ref string rstrUserName)
{
rstrDomainName = "";
rstrUserName = pstrDomainUserName;
int lnSlashPos = pstrDomainUserName.IndexOf("\\");
if (lnSlashPos > 0)
{
rstrDomainName = pstrDomainUserName.Substring(0, lnSlashPos);
rstrUserName = pstrDomainUserName.Substring(lnSlashPos + 1);
}
}
The Line:
s.Credentials = System.Net.CredentialCache.DefaultCredentials();
Maybe you should try :
s.Credentials = HttpContext.Current.User.Identity;

Resources