Running parallel test with PNunit, can't read from config file - visual-studio-2013

I wanna run pararell tests in Browserstack. This is my test project
RTest (Unit test project in VS 2013)
-UnitTest1.cs
-RTest.config
I open Nunit and browse to my dll bin/debug/RTest.dll and Nunit finds my test case
Problem
My RTest.config file looks like this:
<TestGroup>
<ParallelTests>
<ParallelTest>
<Name>Testing</Name>
<Tests>
<TestConf>
<Name>TestFF-20-Win8</Name>
<Assembly>RTest.dll</Assembly>
<TestToRun>RTest.UnitTest1.TestCase</TestToRun>
<Machine>localhost:8080</Machine>
<TestParams>
<string>firefox</string> <!--browserName -->
<string>20.0</string> <!-- version -->
<string>Windows</string><!-- os -->
<string>8</string><!-- os_version -->
</TestParams>
</TestConf>
<TestConf>
<Name>TestFF-21-win7</Name>
<Assembly>RTest.dll</Assembly>
<TestToRun>Test.UnitTest1.TestCase</TestToRun>
<Machine>localhost:8080</Machine>
<TestParams>
<string>firefox</string>
<!--browserName -->
<string>21.0</string>
<!-- version -->
<string>Windows</string>
<!-- os -->
<string>7</string>
<!-- os_version -->
</TestParams>
</TestConf>
</Tests>
</ParallelTest>
</ParallelTests>
</TestGroup>
My UnitTest1.cs looks like this:
using NUnit.Framework;
using PNUnit.Framework;
using System;
using System.Web;
using System.Text;
using System.Net;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
namespace RTest
{
[TestFixture()]
public class UnitTest1
{
private IWebDriver driver;
private string[] testParams;
[SetUp]
public void Init()
{
testParams = PNUnitServices.Get().GetTestParams();
String params1 = String.Join(",", testParams);
Console.WriteLine(params1);
String browser = testParams[0];
String version = testParams[1];
String os = testParams[2];
String os_version = testParams[3];
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browserName", browser);
capability.SetCapability(CapabilityType.Version, version);
capability.SetCapability("os", os);
capability.SetCapability("os_version", os_version);
capability.SetCapability("browserstack.user", "testUser");
capability.SetCapability("browserstack.key", "testPW");
Console.WriteLine("Capabilities" + capability.ToString());
driver = new RemoteWebDriver(new Uri("http://hub.browserstack.com:80/wd/hub/"), capability);
}
[Test]
public void TestCase()
{
driver.Navigate().GoToUrl("http://www.google.com");
StringAssert.Contains("Google", driver.Title);
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Browserstack");
query.Submit();
}
[TearDown]
public void Cleanup()
{
driver.Quit();
}
}
}
When I run my test I recieve mInstance is null......
What am I doing wrong here?

Try renaming RTest.config to test.conf.

PNunit is from long time not maintained. I found a new open-source distributed runner that can run NUnit tests in distributed and in-parallel, you can check the projects documentation.
In general you have test controller and test agents. The test agents run your tests.
First start the server
meissa.exe initServer
Start the test agent on the same or multiple machines:
meissa.exe testAgent --testAgentTag="APIAgent"
--testServerUrl="http://IPServerMachine:5000"
Run your tests pointing the server URL
meissa.exe runner --resultsFilePath="pathToResults\result.trx"
--outputFilesLocation="pathToBuildedFiles"
--agentTag="NUnit" --testTechnology="MSTestCore"
--testLibraryPath="pathToBuildedFiles\SampleTestProj.dll"
It is great since you don't need any configuration files or changing your code at all. It can work with both .NET Framework and .NET Core projects.

Related

Using Calabash with something else than Ruby

Is it possible to use the Xamarin Calabash with a programming language something other than Ruby, for example C#?
I want to automate tests for mobile devices.
If you want Ghekin as a language to describe your tests, you can use Specflow on top of Xamarin.UITest.
http://specflow.org/getting-started/
You can see an example here: https://github.com/smstuebe/xamarin-testing-demo/tree/master/Todo.Tests.UI.Specflow
A test would then look like this.
Feature: Todo
In order to remember what I have to do
As a user
I want to maintain tasks in a list
Scenario: Add a task
When I enter "Added Task"
And I press add
Then the task "Added Task" should be added to the list
The step definitions then use Xamarin.UITest
[Binding]
public sealed class TodoPageSteps
{
private TodoPage _page;
private IApp _app;
public TodoPageSteps()
{
_page = new TodoPage();
_app = FeatureContext.Current.Get<IApp>("App");
}
[When(#"I enter ""(.*)""")]
public void WhenIEnter(string task)
{
_app.Tap(_page.AddEntry);
_app.EnterText(_page.AddEntry, task);
}
[When(#"I press add")]
public void WhenIPressAdd()
{
_app.Tap(_page.AddButton);
}
[Then(#"the task ""(.*)"" should be added to the list")]
public void ThenTheTaskShouldBeAddedToTheList(string task)
{
_app.WaitForElement(_page.LabelOfTask(task));
}
}
Xamarin.UITest is C#-based Calabash
Xamarin.UITest, an Automated UI Acceptance Testing framework based on Calabash that allows programmers to write and execute tests in C# and NUnit that validate the functionality of iOS and Android Apps.
Ref: https://developer.xamarin.com/guides/testcloud/uitest/

Error in executing the Xamarin.UITest for some reason

I am trying to do UI Testing using the Xamarin.UITest framework. I am trying to follow the procedure using the links that is given on their website.The application is named 'CreditCardValidator'. I downloaded the app and then did stuffs like upgrading the UITest package and not the NUnit package. As the tutorial mentions that the code that is to be mentioned is
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.iOS;
using Xamarin.UITest.Queries;
namespace CreditCardValidator.iOS.UITests
{
[TestFixture]
public class Tests
{
iOSApp app;
[SetUp]
public void BeforeEachTest()
{
Console.WriteLine ("Starting the function");
app = ConfigureApp.iOS.StartApp();
// app = ConfigureApp.iOS.AppBundle("/Users/admin/Library/Developer/CoreSimulator/Devices/57DBB268-714A-473F-A7D3-C3B4BB2BB138/data/Containers/Bundle/Application/A9151B5D-7B9C-4F9A-9EF2-F153AC994170").StartApp();
Console.WriteLine ("ending the function ");
}
[Test]
public void CreditCardNumber_TooShort_DisplayErrorMessage()
{
Console.WriteLine ("Starting the function");
app.WaitForElement(c=>c.Class("UINavigationBar").Marked("Simple Credit Card Validator"));
app.EnterText(c=>c.Class("UITextField"), new string('9', 15));
Console.WriteLine ("ending the function ");
}
}
}
MY PROBLEM :
The simulator is not opening and the tests are failing for no reason. The StartApp() functions documentation says that it LAUNCHES the app on the simulator. The error I am getting in the Test Results pad is
SetUp : System.NullReferenceException : Object reference not set to an instance of an object
They are failing at the line : app = ConfigureApp.iOS.StartApp();
I tried to replace this line with the compiled version of the app which is commented out in the code. But for that still the simulator is not opening and the error I am getting is
SetUp : System.Exception : App bundle directory doesn't contain a valid app bundle. Still the error is at the Startup function line
MORE INFO : In the second attempt I found that my .app file has a 'STOP' image on it. Could this be the reason ?
Please ask if more information is required.

Test missing when using AutoFixture with NSubstitute auto data attribute

A test class with the following test is discovered as expected:
[Theory]
[AutoData]
public void MyDiscoveredTest() { }
However, the following test is missing:
[Theory]
[AutoNSubstituteData]
public void MyMissingTest() { }
Interestingly, if I put MyDiscoveredTest after MyMissingTest, then MyDiscoveredTest is also now missing. I have tried both the xUnit visual studio runner and xUnit console runner with the same results.
My AutoNSubstituteData attribute is defined here:
internal class AutoNSubstituteDataAttribute : AutoDataAttribute
{
internal AutoNSubstituteDataAttribute()
: base(new Fixture().Customize(new AutoNSubstituteCustomization()))
{
}
}
A related question: since the AutoNSubstituteDataAttribute above seems like a fairly common attribute, I'm wondering why it's not included with AutoFixture.AutoNSubstitute. Similarly useful would be an InlineAutoNSubstituteDataAttribute. Should I submit a pull request for these?
Nuget package versions used:
AutoFixture 3.30.8
AutoFixture.Xunit2 3.30.8
AutoFixture.AutoNSubstitute 3.30.8
xunit 2.0.0
xunit.runner.visualstudio 2.0.0
xunit.runner.console 2.0.0
NSubstitute 1.8.2.0
I am using Visual Studio 2013 Update 4 and targeting the .NET 4.5.1 Framework
Update: As recommended I tried TestDriven.NET-3.9.2897 Beta 2. The missing test now runs, however it still seems there is some bug. New example:
[Theory]
[AutoData]
public void MyWorkingTest(string s)
{
Assert.NotNull(s); // Pass
}
[Theory]
[AutoNSubstituteData]
public void MyBrokenTest(string s)
{
Assert.NotNull(s); // Fail
}
[Theory]
[AutoData]
public void MyWorkingTestThatIsNowBroken(string s)
{
Assert.NotNull(s); // Fail even though identical to MyWorkingTest above!
}
Both MyBrokenTest and MyWorkingTestThatIsNowBroken fail at Assert.NotNull, while MyWorkingTest passes even though it is identical to MyWorkingTestThatIsNowBroken. So not only does the AutoNSubstituteData attribute not work properly, but it is causing the downstream test to misbehave!
Update2: Changing the definition of AutoNSubstituteDataAttribute to public instead of internal fixes everything. xunit runner now discovers and passes all the tests as does TestDriven.Net. Any idea about this behavior? Is it expected?
Both xUnit visual studio runner and TestDriven.Net runner are causing these weird issues because the AutoNSubstituteDataAttribute class and constructor are internal. Changing these to public resolves all the issues. If the attribute is being ignored I would expect an error like this: System.InvalidOperationException : No data found for ...
This doesn't explain why the downstream tests are affected by the offending AutoNSubstituteData attribute from a totally different test. It seems like the unit test runners should be more robust in this case.
For completeness here is the working implementation of AutoNSubstituteDataAttribute:
public class AutoNSubstituteDataAttribute : AutoDataAttribute
{
public AutoNSubstituteDataAttribute()
: base(new Fixture().Customize(new AutoNSubstituteCustomization()))
{
}
}

Visual studio 2010 compilation issue

I have a project in Visual Studio 2010 with target to framework 3.5 with some code like this:
public class Test {
private object _field;
private Action defaultAction = null;
public Test(Action a)
{
defaultAction = a;
}
public Test()
: this(() => { _field = new object(); })
{
}
}
When I compile the project from the VS reports a compile error at line 11.
When I compile the project from the command line with "C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe Test.sln" compiles successfully.
In fact this code compiles in VS2008 but in VS2010 with target to framework 3.5, doesn't.
Any idea about what is happend?
Update
To fix the code in V2010 I changed as follows (this is equivalent to origian code):
public class Test {
private object _field;
private Action defaultAction = null;
public Test(Action a)
{
defaultAction = a;
}
public Test()
{
defaultAction = () => {_field = new object();}
}
}
But what worries me is that Visual Studio is compiling my code with framework 4.0 and this may cause other errors when deploying my application in the customer's environment (framework 3.5).
I don't have access to VS2008 or .NET 3.5 at the moment so I can't investigate why it's compiling for you. There might be an explanation linked from What's New in the .NET Framework 4
What I can offer however is a fix to get it compiling in VS2010. By declaring _field as static, an instance of it will be available in the constructor of the Test class.
Replace the second line of your posted code with this and the code should compile:
private static object _field;

Renaming config files with Visual Studio setup project

My applications have a handful of config files, each one particular to the machine it's being deployed to (dev, production, etc.) I'm wanting to add them to the setup project, use radio buttons to select one and then have a script (or maybe custom action?) rename the selected files to connectionStrings.config, settings.config, etc.
Is this feasible/possible with a setup project?
To give you an idea, my configs might look like this:
DEV connectionStrings.config
PROD connectionStrings.config
After the user chooses DEV or PROD in the installer radiobutton UI, I would like the chosen config to be renamed to
connectionStrings.config
Considering it's a VS setup project, I have a feeling I'm asking for way too much and that I will get an interesting response as most setup project questions do :)
I created a setup project to set connection strings and i used the following which works perfectly for me.
Create a installer.cs file for the setup.
using System;
using System.Data.SqlClient;
using System.Xml;
using System.Configuration;
using System.Reflection;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
using System.Configuration.Install;
namespace YOURNAMESPACE
{
[RunInstaller(true)]
public partial class installer : System.Configuration.Install.Installer
{
public installer()
{
InitializeComponent();
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
}
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
try
{
string DatabaseString1 = "FULL NAME OF CONNECTION STRING";
ConnectionConfigure(DatabaseString1);
}
catch (Exception e)
{
base.Rollback(savedState);
}
}
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
private void ConnectionConfigure(string DatabaseString)
{
string dataSource = "";
dataSource = "Provider="+ Context.Parameters["InitialCatalog"]+ ";" + "Data Source=" + Context.Parameters["DataSource"];
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
string configFile = string.Concat(Assembly.GetExecutingAssembly().Location, ".config");
map.ExeConfigFilename = configFile;
System.Configuration.Configuration config = System.Configuration.ConfigurationManager.
OpenMappedExeConfiguration(map, System.Configuration.ConfigurationUserLevel.None);
string connectionsection = config.ConnectionStrings.ConnectionStrings
[DatabaseString].ConnectionString;
ConnectionStringSettings connectionstring = null;
if (connectionsection != null)
{
config.ConnectionStrings.ConnectionStrings.Remove(DatabaseString);
}
connectionstring = new ConnectionStringSettings(DatabaseString, dataSource);
config.ConnectionStrings.ConnectionStrings.Add(connectionstring);
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("connectionStrings");
}
}
}
Add project output to your setup project then begin to setup this setup project.
Right click setup project
Add text boxes and create the UI
Set custom actions
Create project output actions
Custom action properties
That is how i setup mine (I have attached screenshots to help explain my process but in short. Create setup project and installer.cs file. Add project output to setup project, add a UI so that the user can input a connection string and or provider for connection string, add custom actions so that the inputs can be read by the installer.cs file and then congratulations it should change the connection string.
Hope this helps.
I've come to the conclusion that this is impossible due to VS severely lacking on setup project configuration options. Instead I added a radio button control during the setup process and assigned the choices a variable name. In the file system I added all of my config files and then set conditions to each one. They referenced values to my radio button choices in order to copy during deployment.
I've done this many times, and basically I just install both files with different names. The application can ask the user which file to use, and change it anytime they want because many users don't know enough about the application to make this choice at install time.
You get interesting answers to setup questions like this because many people want to configure the application during the installation. Why not just let the setup install the files and have the app do its own configuration?

Resources