Config TeamCity to run UI Test on NUnit Framework

For Agent machine

  1. Install Firefox
  2. Install NUnit Adapter on Visual Studio
  3. Add Firefox path to PATH

For coding

8

For Teamcity

1. Specific agent machine for compatibility2

2. In Artifact paths of General Settings: Copy everything from Release folder to another folder (optional)3

3. Define steps

3.1 Restore packages4

3.2 Build and Package Test solution5.PNG

/p:Configuration=Release /p:Platform=”Any CPU” /p:FrameworkPathOverride=”C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1″ /p:DeployOnBuild=true;PublishProfile=PackageToZip

3.3 Update Test parameters6.PNG

echo Username::%Test.Username% > %system.teamcity.build.checkoutDir%\Test\UnitTest.CodeBase\bin\Release\Parameters.txt
echo Password::%Test.Password% >> %system.teamcity.build.checkoutDir%\Test\UnitTest.CodeBase\bin\Release\Parameters.txt
echo SiteUrl::%Test.SiteUrl% >> %system.teamcity.build.checkoutDir%\Test\UnitTest.CodeBase\bin\Release\Parameters.txt

3.4 Run UI Test in command line

Old

%system.teamcity.build.checkoutDir%\OmniaTest\UnitTest.CodeBase\bin\Release\TestWindow\vsTest.console.exe “%system.teamcity.build.checkoutDir%\OmniaTest\UnitTest.CodeBase\bin\Release\UnitTest.CodeBase.dll” /UseVsixExtensions:true

New

Turn on read/write  permission for current user on: E:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow

vsTest.console.exe %~dp0/UnitTest.CodeBase.dll /TestAdapterPath:”your packages path\Test\Dev\packages”

 

4. Define Parameters7

5. Turn on console mode in the build agent

cs stop TCBuildAgent
ping 192.0.2.2 -n 1 -w 10000 > nul

C:\BuildAgent\bin\agent.bat start

 

Use selenium IDE to write UI Test for console log in C#

As always, your UI Test is just focus on what happen on the UI, such as find the element and act on that element. Sometime, all of the steps passed, and you think that this testcase pass? For me, I am not really sure for that.

Nowadays, most of web applications are using Javascript (or some libraries base on Javascript) for everything. So, how can we know that our web application don’t have any console error? Is it possible to write the UI Test to test console log?

The answer is “yes”. Here I will show you step by step to setup a UI Test method in Firefox.

1. Install Selenium IDE and Selenium IDE Button extension on Firefox, when you done that, your browser will look like this:

1

Now, you can record your steps for your testcase. The recorded steps will looks like this:

2.PNG

Now, what we need is export that testcase as C# code:

3.PNG

Now, it is the time for us to hijack the UI to actually override its console error.

The idea is: before the page actually loaded, we try to inject our javascript on the page, so I wrote an extension for driver to make it happen.

4.PNG

In here, we have a loop, trying to add your script to the page until it loaded. Since my page is so slow, my loop is base on second, but you can do the loop base on millisecond without any problem.

Now, in the login method, you just need to call to that method directly after you clicked on sign in button

5

Now, execute your steps and at the end, just read the errors for the final assert.

6.PNG

Ok, but what is “ReadErrors”? Ah, it is also an extension method to help us get all of console errors.

7.PNG

Yeah, everything seem finished. Now, you just need to run the test to see how it works.

To run the test, open command prompt and type:

8.PNG

Woa, for my testcase, I see this result:

9

He he, now you can see the Javascript error on your test. The test failed, but you successed :).

 

Add O365 account as a member of Visual Studio Online project

For testing purpose, follow this article to create a free 30-day trial of Office 365 Developer account.

When everything are ready, you should have an account and all the related apps like this:

7

In my case, my account is: admin@testingtableau.onmicrosoft.com

And, if you want to add this account to your Visual Studio Online project. Go to “Members” and add new user:

8.PNG

In the popup, type the account there, but unlucky, you see something like “No identities found”:

9

Don’t worries, just go ahead and click on “Save changes”.

Then, use another browser (or another user on same browser) and access to your project link, my case: https://mysub.visualstudio.com/myproject

The login form will display for you to enter your account, but ops! What the hell is this?

10

Most of us will give-up at this time, but why? Why don’t you just go ahead and create a Microsoft account similar with O365 account and use it for both?

11

Then, go with some other steps and you are ready to use that account for your Visual Studio Online project.

Annoying, because they are still 2 difference users. So you still need to select a correct type when you want to access to any of them.