Start Blazor server app to use it in End-to-End tests (Selenium) - c#

I am new with Blazor and have to test the Blazor server app (.Net7).
Address: http://localhost:5000
My test (NUnit / Specflow) is working if I start the app in the background.
Now I want to start the Blazor app in the BeforeScenario.
I tried to get it working with WebApplicationFactory<> but failed.
I assume I just need to start a server because Selenium is starting the client by itself.
Can me someone explain the concept and provide a minimal solution. I think it will be easier to extend it later them start with all options.
Thanks
Nico

Related

Difference between a console application and Web application in asp.net core

I am trying to run a background service which just writes to a file on a specified interval.
There are two methods that I tried
1) Created the project with the Console application template
2) Created the project with Web Application as template
When I run the app from visual Studio, both of them run fine. But when I deploy them to IIS, only the web application version works. It must be noted that there is absolutely no difference between the code of the two projects. I have used the WebHost as a hosting strategy in both the projects as well as well as installed all the dependencies in case of Console application as there are in the Web Application version.
I must also inform that I have used the preloadEnabled="true" option in IIS as IIS needs a web request to start the application.
I am wondering what is the difference between both the project types as the code is the same? I don't want the Web Application template.
Edit 1: I forgot to mention that the service will also need to expose an api endpoint for healthcheck purposes. Will the windows service approach listen for http requests?
I used the following article for implementing my background service.
https://learn.microsoft.com/en-us/dotnet/architecture/microservices/multi-container-microservice-net-applications/background-tasks-with-ihostedservice
After years of building background services, I learned that Windows services are the best tools to implement these applications. While there are different techniques to keep an IIS application up and running in the background and prevent it from getting recycled, in practice, the applications on IIS are not meant to be executed forever.
If you had an intention to build your app in the cloud, I would have suggested using something like Azure WebJobs or Azure Functions Timer-Triggered functions, but for on-premise, even using something like Hangfire in the web is not sustainable. The worst happens when you need backward compatibility on Windows servers that don't have the "Application Initialization" module.
My suggestion is to move your application to a simple Windows Service if you control your environment. Windows services consume less memory, are easier to manage, and can run forever without getting recycled.
WebApplications are plain the wrong tools for this.
Being always on and always reachable, WebServers are primary targets for hacking. To compensate for that, they are usually run under the most restrictive user rights you can imagine: Read rights to their programm and this instances content directory. While I do not know why it worked at all, it propably will stop working in Production.
What you wanted to write was eitehr a Service or something executed by the Windows Task Sheduler. Personally I advise for the Task Sheduler as Services have their own set of restrictions. Unless of coruse there is some detail of the requirements that you did not told us.
This article could be helpful. It's a step by step tutorial on how to convert a console application to a web application.

How to trigger selenium tests from Jira

I have a requirement in which I have to trigger selenium tests from Jira. Selenium tests are written in C#.
The complete work flow should be like:
Start test execution from Jira using any 3rd party plugin.
The test will be running in aws using jenkins build pipeline.
After the test is completed the results should be updated in Jira
I had read about Xray plugin for Jira but there the build has to be triggered from jenkins which i don't need as i want the test execution to be triggered from Jira.
Is there any way to achieve this ?
Any help will be appreciated.
You have to put a CI server in between your test execution environment and JIRA. Otherwise there will be no configuration control over your test jobs. JIRA is for project management and monitoring. At present , It cannot be used for controlling slave nodes and executable targets.
The technical side of things is still managed on a CI server. If you don't want to have a static hosted Jenkins server , you can go with following two options.
CircleCI
JenkinsX in kubernetes.
Also you are using AWS.
You can spin up ec2 instance and configure your selenium job to run on that specific instance .
If you like complexity and dynamic coding , then you can also use AWS Lambda. This blog can give some inspiration to begin with. JIRA has apps to directly connect with AWS lambda.

Do you need to run a Selenium Server with RemoteWebDriver in order to perfrm the step "Run Functional Tests" in TFS 2017 vnext build?

I have been able to run Selenium test locally on my test machine using a simple webdriver setup such as IWebDriver driver = new FirefoxDriver(); driver.Url = "http://www.testedApp.com"; and running the tests through Microsoft.VisualStudio.TestTools.UnitTesting;, but when I deploy the test through Team Foundation Server vnext Build step "Test: Run Functional Tests" https://www.visualstudio.com/en-gb/docs/build/steps/test/run-functional-tests I get various errors that all seem to relate back to not being able to create a driver in the first place.
I am deploying the selenium tests onto remote machines (either windows Server 2008 R2 or 2012) that have the application to be tested already installed. It doesn't seem to matter if I put the url to driver.Url = "http://www.testedApp.com"; or driver.Url = "http://www.localhost/testedApp.com"; the machine (which looks to still be running from the TFS server machine, not the machine I have deployed the tests onto) appears to be failing at timeouts which led me to this answer on Stack Overflow
Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds
After trying all the options there, looking further, I discovered the Selenium Server and RemoteWebdriver (the RemoteWebdriver actually being in my error very deep down)
I am also running the test agent on the remote machine under an Administrator account, so would assume the UI access wouldn't be a problem, but the error also persists if I am using Phantomjs as a browser.
So, I guess my real question is, in order to run a test successfully on a remote machine from the TFS machine, will I need to install and run a Selemium Server (and therefore create my drivers through a RemoteWebdriver)?
If so, would this Selenium Server go on the TFS machine, or the remote machine I am attempting to run the tests on?
I just wanted to update this with my solution.
I managed to get the vnext Build step "Test: Run Functional Tests" working without using remoteWebDriver or running a Selenium Server with nodes.
I had all the correct trust levels and ports opened, my problem was that I didn't realise that I needed to have the agent running the tests being Authenticated with a PAT Token (in other words, it requires ssl to operate successfully) (DOH!)
I also ran into a problem where the domain policy kept resetting the Group Policy for autologon to 0, which I have got around by running a script to reset before I kick the tests off.
Hope this helps somebody else.
And I apologise in advance if my question initially led to some false assumptions.
But, needless to say, I am grateful that I am not required to maintain the selenium servers (or Octopus deploy), and that Vnext build is adaptable enough to handle this all in house.
Vnext still has a way to go to become completely adaptable to my needs, but it is a great start (imo)
You will need a selenium server or node on every machine running a browser.

Asp.net web API 2 separation Of Web client and web server development

Our web application is developed by 2 teams. One team works on the client side, with it's own Branch for development, and the other works on the server side, also with it's own development branch. The client and the server are running separately, each one as a website on a different port. The websites are hosted over IIS Express during development, and in production they will run over IIS.
Our ideal situation is that each team can develop completely separately and whenever a develop session is over, both teams merge their change-set to a common Branch in order to integrate, than each team merges back to their development branch, and continues.
In order for a full separation, We have x2 SERVER projects, one to handle the real HTTP requests and another one, a "Stub server" Which responses to all the clients HTTP requests with default values, just in order so that the Client side team can test their code without being dependent on the functionality of the server.
The problem is that both the "Stub server" and the real server and using the same Port which the Client side project is directed to.
This causes many annoying mistakes (mostly for the Server side team) of running the application with the "Stub server" instead of the real one, during reviews, tests etc. The only solution for us is to manually create a virtual directory for the real web server project every time before running / or after finding out we were running the wrong server.
Is there a smarter solution to overcome this annoying problem? That would improve our lives!
If anything I said was foolish / not clear please correct me (I'm new to this), or ask for more details, I'll be glad!
Thanks for helpers!
I believe your problem is more related to build automation then server configuration. You should really keep the stub server and the real server into separate ports, and change that port during some kind of build process of your client.
If you are using AngularJS, then I suggest you to create steps into the build process of your client application using common tools like gulp or grunt. You could create build processes that will set a global variable or modify a constant (e.g. the API endpoint) and name them local testing (pointing your client to the stub server) and integration (for the real server).
Please note that you can easily integrate those build processes into Visual Studio, making them part of your global debug/build process.
Here it is a simple gulp task useful for replacing text inside any file: https://www.npmjs.com/package/gulp-replace

Local Testing and Debugging Facebook iframe app (Windows Azure)

I wonder what the best way to test and debug facebook iframe applications locally (using the facebook c# toolkit and the azure toolkit)?
When i try to debug it's always starting the Compute Emulator on a different port.
Basically i want to have a special facebook iframe app pointing to a specific port on localhost (e.g. http://localhost:81) and after pushing the debug button that my app url (e.g. http://apps.facebook.com/myspecificappdev) is being started in my browser (with debug functionality).
I found this thread but unfortunatly this didn't help me a lot: http://azuretoolkit.codeplex.com/discussions/207487
What's the best way to debug such applications? Is their maybe a sample project which already has that part set up correctly?
Ok, here is what we do (at Thuzi). We set up an dedicated IIS web site for our code. We create a bogus domain like fbapp.mycompanysdomain.com and then we edit your machine's (or other machine's) Hosts file to point to the proper IP address. When we set up the site in IIS we use a host header which means that we don't need to worry about port numbers. When we debug we simply attach to the process.
So you point your web browser to the FB URL and it should always land on your web server (whether you are debugging locally or not). I know this sounds like a little more work, but it ends up being so much easier in the long run and better reflects what will ultimately happen. I realize if you are using any kind of storage then you will need to start that up, but it's still a lot easier this way..
If your app is simply a website, then you don't need to run the compute emulator to run it. I would setup the site so that it runs on IIS on a specific port, then debug the website project, not the cloud project.
There is a bit more to it than just that however. If you're using development storage then you'll need to start that yourself as it won't automatically be started when you debug the website. If you have a RoleEntryPoint class then you need to be aware that none of that code will be called. Also if you make use of anything in RoleEnvironment (like settings) you'll need to put a wrapper around those items so that they'll still work when not running under the emulation environment (RoleEnvironment.IsAvailable is very useful for detecting this). A setup like this is very useful during development because when you make small changes to CSS of JavaScript you don't need to restart the compute emulator to see your changes.
You're on the right track. You need to create a new facebook app and point the iframe / canvas / tab url to localhost with the specific port cassini chose for the project.
What I did to ensure the the windows azure app stays on the same port:
I placed this as a pre-build event:
"C:\Program Files\Windows Azure SDK\v1.4\bin\csrun.exe" /devfabric:shutdown
This makes it better but it's still switching port sometimes

Categories

Resources