Setting up of Selenium Web driver for SpecBind - c#

I have been asked to create a remote selenium web driver using browserstack to test the functionality across all browsers. I have checked the repository to which I have received some of the felds needed:
RemoteUrl: http://hub.browserstack.com:80/wd/hub/
browserstack.user = username
browserstack.key = password
browserstack.debug = true/false
browserstack.tunnel = true/false
os
OS_version
Version = the browser version
I have got the code to create the driver below:
DesiredCapabilities capability = DesiredCapabilities.Firefox();
capability.SetCapability("browserstack.user", "username");
capability.SetCapability("browserstack.key", "password");
driver = new RemoteWebDriver(
new Uri("http://hub.browserstack.com/wd/hub/"), capability
);
this creates the remote webdriver. However as i am using this with specbind I need to create this driver within the app.config. which will be stored under a <browserfactory> however I am unsure on how to do this, please help!

I have now resolved this issue. From the start URL you need to then put in this browser factory setting:
<browserFactory
provider="SpecBind.Selenium.SeleniumBrowserFactory, SpecBind.Selenium">
<settings>
<add name="RemoteUrl" value="http://hub.browserstack.com:80/wd/hub/"/>
<add name="browser" value="IE" />
<add name="browser_version" value="8.0"/>
<add name="os" value ="Windows"/>
<add name="os_version" value="7" />
<add name="browserstack.user" value="username" />
<add name="browserstack.key" value="key" />
</settings>
The various settings configure this to Windows 7 and IE 8. This can be changed accordingly and the Username and Key is given to you by browser stack.

Related

ASP.NET Core - How to read EnvironmentVariableTarget after hosting in IIS

I have set MyConnString in System's environment variable in Windows 10 manually. I am trying to read it from code. In Visual Studio I can get the value of MyConnString using EnvironmentVariableTarget.User.
But after publishing and hosted in IIS, the value of MyConnString is returned as empty/null. My log is not printing the 'MyConnString' value.
My connection string is sensitive and can't be part of any config file. I appreciate your help.
I am using ASP.NET Core 3.1 and my app pool identity is ApplicationPoolIdentity. I have also set Load User Profile true in app pool.
var content = Environment.GetEnvironmentVariable("MyConnString", EnvironmentVariableTarget.User);
if (string.IsNullOrWhiteSpace(content))
{
content = Environment.GetEnvironmentVariable("MyConnString", EnvironmentVariableTarget.Machine);
}
if (string.IsNullOrWhiteSpace(content))
{
content = Environment.GetEnvironmentVariable("MyConnString", EnvironmentVariableTarget.Process);
}
if (string.IsNullOrWhiteSpace(content))
{
content = Environment.GetEnvironmentVariable("MyConnString");
}
The User of IIS is not your user.
FIRST OPTION
You need to set the variable for the user owner of the process of your IIS.
SECOND OPTION
Use Environment variables inside your web.<environment>.config in order to be compatible in every server you deploy.
web.Staging.config
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<aspNetCore>
<environmentVariables xdt:Transform="InsertIfMissing">
<environmentVariable name="MyConnString"
value="my db conn string"
xdt:Locator="Match(name)"
xdt:Transform="InsertIfMissing" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
you have other possibilities to set the environment variables for your target server, search on G for more infos.

Exception: No RegionEndpoint or ServiceURL configured

I'm trying to connect to AWS DynamoDb by creating an AmazonDynamoDBClient.
I'm getting the following exception:
Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured
at Amazon.Runtime.ClientConfig.Validate()
at Amazon.Runtime.AmazonServiceClient..ctor(AWSCredentials credentials, ClientConfig config)
I have the following lines in my App.Config file (the actual keys are in my code):
<appSettings>
<add key="AWSProfileName" value="development" />
<add key="AWSAccessKey" value="XXXXXXXXXX" />
<add key="AWSSecretKey" value="YYYYYYYYYY" />
<add key="AWSRegion" value="us-east-2" />
</appSettings>
I also have a credentials file under the AWS folder. Includes the following:
[development]
aws_access_key_id = XXXXXXXX
aws_secret_access_key = YYYYYYYYYY
In my code, I'm simply calling to:
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
I'm working in visual-studio 2019. This used to work when I was working in a simple console application environment. Now I am working under Azure-Functions template project.
Why am I getting error?
Not sure why it is not working since you have added AWSRegion to the config. I suggest to add the below to your credentials file
[development]
aws_access_key_id = XXXXXXXX
aws_secret_access_key = YYYYYYYYYY
region = us-east-2

Update/Refresh config file

I have a small programm in which i copy paste stuff from A to B on the PC. The directory paths are written in the config, and when i (in the application) change the directory in the textbox it is updating the config file. I checked it, the value is immediatlely rewritten at the appropriate key. When i close the app and reopen it, it is updatet to the previously changed directory path, but i dont want to have to close the application and reopen is. I have a combobox and i want it to update as soon as the combobox reselect event triggers. But during the runtime (altough it is already changed in the config) it will not update the directory path shown in the app.
I read through and tried everything i found online and sadly nothing helped. Not every every kind of
ConfigurationManager.RefreshSection("appSettings");
THis is my config:
<appSettings file="">
<clear />
<add key="SourcepathClient" value="D:\xxx" />
<add key="SourcepathWin32" value="D:\xxx" />
<add key="DestinationpathUpdatePackages" value="D:\xxx" />
<add key="DestinationpathClient" value="D:\xxx" />
<add key="5_9_0-DestinationpathClient" value="D:\xxxt" />
<add key="5_9_0-DestinationpathUpdatePackages" value="D:\xxx" />
<add key="5_9_1-DestinationpathClient" value="D:\xxx" />
<add key="5_9_1-DestinationpathUpdatePackages" value="D:xxx" />
<add key="5_9_2-DestinationpathClient" value="D:\xxx" />
<add key="5_9_2-DestinationpathUpdatePackages" value="D:\xxx" />
</appSettings>
and this the code:
Configuration config = ConfigurationManager.OpenExeConfiguration(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "UpdatePackager.exe"));
config.AppSettings.Settings[ComboBoxVersion.Text + "-DestinationpathClient"].Value = TextBoxDestinationpathClient.Text;
config.AppSettings.Settings[ComboBoxVersion.Text + "-DestinationpathUpdatePackages"].Value = TextBoxDestinationpathUpdatePackage.Text;
config.AppSettings.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection("appSettings");
I hope someone can help me.
Regards
i think there is no issue with code it issue related your access, it makes a difference if you run your application in IIS and run your test sample from Visual Studio. The ASP.NET process identity is the IIS account, ASPNET or NETWORK SERVICES (depending on IIS version).
Might need to grant ASPNET or NETWORK SERVICES Modify access on the folder where web.config resides.

IIS: Access Microsoft CRM 2013 with AppPool Identity

My IIS MVC web site connects to Microsoft CRM 2013. User/Domain/Password are set in web.config, this works fine.
Now I want to remove hard coded credentials in web.config. To Access CRM I want to use credentials of AppPool Identity. This user has enough rights on server and administrator role in MS CRM. I tried this way:
Uri organizationUri = new Uri(WebConfigurationManager.AppSettings["CrmUrl"]);
var credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
var orgProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
This does not work. DefaultNetworkCredentials are empty.
I need help to manage this problem. Thanks!
Instead of creating the credentials and the organization service proxy yourself, rather let CrmConfiguration handle this:
Your Web.config will look something like this:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="microsoft.xrm.client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
</configSections>
<connectionStrings>
<!-- On-Premise with integrated Authentication -->
<add name="MyOnPremiseConnection" connectionString="Url=http://SERVER-NAME/ORG-NAME/XRMServices/2011/Organization.svc;" />
</connectionStrings>
<microsoft.xrm.client>
<contexts default="MyOnPremiseContext">
<!-- On Premise CRM-->
<add name="MyOnPremiseContext" connectionStringName="MyOnPremiseConnection" serviceName="MyService" />
</contexts>
<services default="MyService">
<add name="MyService" serviceCacheName="Xrm" />
</services>
<serviceCache default="Xrm">
<add name="Xrm" type="Microsoft.Xrm.Client.Services.OrganizationServiceCache, Microsoft.Xrm.Client" cacheMode="Disabled" />
</serviceCache>
</microsoft.xrm.client>
</configuration>
Your code will connect to CRM like this:
using (var servicecontext = CrmConfigurationManager.CreateContext("MyOnPremiseConnection", true) as CrmOrganizationServiceContext)
{
var query = new QueryExpression
{
EntityName = "account",
ColumnSet = new ColumnSet("name"),
TopCount = 10,
};
var top10accounts = servicecontext.RetrieveMultiple(query).Entities;
}
Reference: Simplified connection to Microsoft Dynamics CRM

MySqlProfileProvider can't connect to my DB

I'm working on a website in ASP.NET and unfortunately I have to use MySql to store the site's data.
I'm really struggling to get MySql work with the CreateUserWizard functionality, and I'm just losing it.
Until I defined custom properties in the Web.Config, everything was fine, and I actually managed to register some fake users. Then I wanted to add some other properties, like address, gender, and so on. I added those properties in the Web.Config like this:
Web.Config
<profile enabled="true" defaultProvider="MySqlProfileProvider">
<providers>
<clear/>
<add name="MySqlProfileProvider" autogenerateschema="True" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.8.3.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D" conectionStringName="connMySql" applicationName="/"/>
</providers>
<properties>
<add name="Nome" type="string"/>
<add name="Cognome" type="string"/>
<add name="Sesso" type="string"/>
<add name="DataNascita" type="datetime"/>
<add name="Indirizzo" type="string"/>
<add name="Citta" type="string"/>
<add name="Provincia" type="string"/>
<add name="CAP" type="int"/>
</properties>
</profile>
Please note that my Connection String is correct, since I used it in other parts of my Web.Config and runs just fine.
Later on, in my sign up page, I wrote this code (after validating the input, of course), to update the created user.
register.aspx.cs
protected void wizard1_CreatedUser(object sender, EventArgs e)
{
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(wizard1.UserName, true);
p.Nome = ((TextBox)wizard1.CreateUserStep.ContentTemplateContainer.FindControl("Nome")).Text;
p.Cognome = ((TextBox)wizard1.CreateUserStep.ContentTemplateContainer.FindControl("Cognome")).Text;
p.Sesso = ((DropDownList)wizard1.CreateUserStep.ContentTemplateContainer.FindControl("Sesso")).SelectedValue;
p.DataNascita = System.Convert.ToDateTime(((TextBox)wizard1.CreateUserStep.ContentTemplateContainer.FindControl("DataNascita")).Text);
p.Indirizzo = ((TextBox)wizard1.CreateUserStep.ContentTemplateContainer.FindControl("Indirizzo")).Text;
p.Citta = ((TextBox)wizard1.CreateUserStep.ContentTemplateContainer.FindControl("Citta")).Text;
p.Provincia = ((TextBox)wizard1.CreateUserStep.ContentTemplateContainer.FindControl("Provincia")).Text;
p.CAP = System.Convert.ToInt32(((TextBox)wizard1.CreateUserStep.ContentTemplateContainer.FindControl("CAP")).Text);
p.Save();
}
All the controls are well positioned into the .aspx page.
So, when I run the page, I can see the form and type the data in. Then my code validates the input, and if it's all correct, it creates the user and gets into the wizard1_CreatedUser function, where it stops at the p.Nome = ... part, which actually is the first instruction that makes use of the MySqlProfileProvider.
It just says Host 'Hostname' is not allowed to connect to this MySQL server BUT MySqlRoleProvider and MySqlMembershipProvider work just fine. In fact, the user is created, but my custom profile data aren't, since the code stops there.
I'm using a DB User with all the privileges.
I'm probably missing something, but I don't really know what.
Thank you.
Turns out that I needed to enable Full Trust.
Also, some files were mispositioned (they were not in the very root of the website).

Categories

Resources