I am new to selenium and C sharp i somehow managed to write a code that does the unit testing of my application and creates a Extent Report with all my 7 test cases output Everything is working as expected The issue is i do not want every time to log into visual studio and run the selected test case Is there any way i can create a Windows application and make the test cases run with a click of a button
I have a total of 7 test cases and runs perfectly when running i select them all and run the selected tests, but i need not want to go there everytime , instead want to run it from some windows application.
If you have your tests in unit tests project, you can create a windows console app and add your test project as dependency to it.
Then you can create your test class objects in main function and call test methods.
using Test.Project.Namespace;
static void Main(string[] args)
{
TestClass testclass = new TestClass();
testclass.TestMethod1();
testclass.TestMethod2();
etc...
}
It can be improved in many ways but you got the idea.
I would suggest that you create a Windows batch file that triggers your automation. Since you are using NUnit, this should be pretty straightforward. You point it at your automation dlls, you can specify test categories, etc. Take a look at the docs and other resources on the web.
Related
I am writing a unit test script for a Windows Forms application and one of my methods pops up a message box, but I don't want to click OK in between my unit tests. If I do so, it will break the automated unit testing concept.
I searched several posts, but unfortunately I couldn't find a solution for this issue. How can I fix it?
The problem I am facing is a unique one.. I have set up a testing suite for a windows app using LeanFT and NUnit. At this point, I have around 100 stable UI tests that I have automatically running nightly on a VM I have configured.
The problem is, I do not think there is an out of the box solution for running tests in parallel across multiple machines. When the tests are kicked off of TFS, they run on a single machine. What I want is for tests to be passed out 1 at a time to any available machine.
I know I can "fake" this in a sense by having two different build definitions run at the same time with a different set of tests, but this is not what I want to do. I want it to work like an actual grid and pass out tests like the selenium grid does. Has anyone had any luck with something like this by not faking it?
Note: we do not use Jenkins, we do everything out of TFS.
Have you looked at https://blogs.msdn.microsoft.com/devops/2016/10/10/parallel-test-execution/ ?
Team Foundation Server does have 'build agents' like Jenkins does. While I'm not familiar with this, it appears to be close to what you are looking for.
I have been playing around with testing a simple webforms ASP.NET website application and have come across the UIMap tool in Visual Studio 2010. However I do not know how to use it correctly and it never seems to work.
Do I need to be running my application in debug mode while recording?
Once the test is generated is there any way of visually seeing the steps as they are being performed?
Should I have the browser open before I begin recording, or should I do that once I start and browse to the page that way?
Can I use Chrome for the browser, or does it have to be IE?
Does using Dual Screens affect the running of the test?
Thanks for your help!
Do I need to be running my application in debug mode while recording?
No. You can not use debug/release mode of Visual Studio and do an record at same time. Start the application separately. This has the big advantage that you can test different versions of our application with one set of tests.
Once the test is generated is there any way of visually seeing the
steps as they are being performed?
No. You can get a log from test-run and of course you see the test-run in self, but there is no static graphic ... to be honest I never miss such feature.
Should I have the browser open before I begin recording, or should I
do that once I start and browse to the page that way?
That you can do as you please. Of course you can record the browser start. We start browser before, because browser start is not really a part of the test.
Can I use Chrome for the browser, or does it have to be IE?
At the moment IE is the forced browser. But there are ways to use other browsers.
Does using Dual Screens affect the running of the test?
No. All fine with dual screen. But don't forget when test is running you can't use your mouse and keyboard - you will fight the CUIT ;). We use a separate PC for long CUIT.
Here are some links which may be helpful for you:
should the coded ui test project share a solution or not?
Unit Testing Frameworks for Visual Studio 2012 Cons/Pros
Which Unit Test framework to use for the projects that requires User Input
Can I run Coded-UI Tests from Windows Froms Applications? Looking for a sample.
Thanks.
Of course you can - you can use mstest.exe command line application for running Coded UI Tests. You just need to write simple algorithm ensuring that correct parameters will be passed while launching mstest. For reference go here
You should have a look at NUnitForms that is a extension to NUnit.
Your NUnit tests can open a window and interact with the controls.
Your tests will automatically manipulate and verify the properties of
the gui. NUnitForms takes care of cleaning up your forms between
tests, detecting and handling modal dialog boxes, and verifying that
your expectations for the test are fulfilled.
Reference here
see also
Unit testing Winforms UI
How to unit test winforms applications
Unit Test to verify that WinForms application doesn't load Assembly more than once
Basically you will better off separating your logic completely from the UI , making your UI as thin as possible, and testing the logic separately .
You can find solution here for console application. You have to add additional references in order to work test in windows forms application or other project(I had to add reference to Microsoft.VisualStudio.TestTools.UITest.WindowsStoreUtility other than the listed refrences in the article). But as explained in this so answer it would be nice if you can use it in a project that is meant to use these assemblies.
I've recently split our nebulously-defined unit testing project into two projects, one for unit testing and one for (what the bulk of our tests are) integration tests. This is with the hope of not-so-subtly prodding our dev team (myself included) to write better tests and code that is more easily tested. (And, by extension, more easily unit tested.)
In doing so, I've found using MSTest within Visual Studio to actually be kind of frustrating, as it is slow but more importantly it wants to run all tests in a given solution rather than all tests in a given project. I've crossed this first hurdle, as I eventually came across the Test List Editor, which allows you to create lists and then assign your tests to the list. I created a list for unit tests, checked all of the tests from the unit test project and dragged them over, and did the same for the integration tests. You can run each list independently of any others.
This gets us to the heart of the matter: Is it possible to simply have these lists grow on their own? IE., can I tie an entire project to a list, or at the very least have the lists update themselves? I want to make it as easy as possible on our developers (myself included) to keep these lists up to date and, most importantly, to actually run the tests.
In Test View (Test->Windows -> Test View) and Test Results (Test -> Windows -> Test Results) you can group the tests by a number of different criteria, one of which is Project. In Test View you can then select a project and click on the 'run selection' button.
Edit:
Note that if you want new tests to automatically update in the test view, you need to uncheck the "disable background discovery of test methods" option in "Tools -> Options -> Test Tools -> Test Project" (restart VS after making this change). If this option is checked, you need to click refresh before any new tests are added.
Edit 2
Some more info: You can assign a keyboard shortcut to "Run selection", (e.g. Ctrl R, S) so you can run all tests for the project that is currently selected in the test view even if the test view window doesn't have focus (It needs to be open somewhere though). So in Test View you can select the project you are currently working in, Open up a test class in that project, add a test, and immediately press your keyboard shortcut, and all tests in the project, including the new one, will be run.
I think you are looking for test categories.