AWS EC2 Windows schedule job fails while offline - windows

I created a Windows instance on AWS EC2 with T2 Micro, where I set up a schedule job that calls a .bat file at 6 every morning.
The .bat job invokes a few other scripts that mainly carry out some Internet-related transactions, including launching browsers, call services and perform I/O operations.
The issue is in most of the time the .bat file is not able to complete its job (Sometimes it does, but pretty rare). Later on, if I connect to the EC2 instance via remote desktop with the same username and manually call that .bat file, everything works fine.
Anyone has ever experienced this kind of problem and what is the resolution?
Thank you.

It's a common problem with automation. Some of the things you're doing such as "launching browsers" may not work for unattended execution.
A good example is Selenium, if you want to run web tests unattended then you need the headless version of Selenium, here's how to set it up for Headless:
Running Selenium with Headless Chrome Webdriver

Related

Reporting status back to TeamCity when a test is ran locally

We have a testing framework made in AutoIt for our Windows apps (older legacy apps that we will continue supporting). These have never been run on a schedule or part of CI (always been run manually). I tried to get some kind of auto run (or even just status reporting) out of the tests, with minimal luck.
I have a VM where the tests can run. I experimented with my own web app, which works okay locally for running and status reporting. But when set up on the server, AutoIt reports it cannot open the application. Same thing happens if I try to run the tests from a .bat file.
My current solution is to have AutoIt call my web app to report status (working okay locally, untested on the server), or to see if I can get AutoIt to report results back to TeamCity. I have the agent installed but when I run the build from TeamCity, AutoIt reports it can't launch the application. I tried this while logged into the VM, logged out, with RDS open; no luck.
Is it possible to run the tests manually from the VM and send results back to TeamCity? When I run them from TeamCity it reads the AutoIt output (which is in the expected format), but I need to let TeamCity know to update the results (so we can use TeamCity rather than my web app to show the results).
I may need to find a way to let TeamCity know a build has been started, which might then let it know to keep an eye on the process' output, but I'm not positive. Any ideas?
I solved this so it could be done more traditionally.
If anyone is confused by what "running the agent from the console" meant, it just means installing the agent without selecting the "as a service" checkbox, and then manually starting the agent by cd'ing to the BuildAgent/bin directory and running the command agent start. I also created a batch file that will do this automatically (but you must run it as admin).
Further, I found AutoIt couldn't do anything if the test doesn't run from the right directory, so I had to devise a solution to this.
The only issue now is that I have to have an old laptop always connected to the virtual machine the tests and app run on (since the AutoIt tests won't work without the VM desktop being interactive).

How to run Windows service outside Session 0

I have a Selenium Grid configured with its hub and nodes(VMs) started automatically as Windows services. Sometimes I would like to visually inspect how a test runs within a browser on a specific node but nothing actually appears on the screen. After some research the reason seem to be that Windows services run in Session 0 which is a special session where Windows services run in isolation.
My question is whether there any way to start Windows service outside Session 0 so I will be able to see the actual test?
P.S. I am using Windows 7 on all machines.
Session 0 is the problem when you want to run your selenium grid using task-scheduler and services.
I handle this by first creating .bat file for hub,node and then running that .bat using .vbs in background.
.Vbs will help you run the setup in background in same user session but running the .vbs in startup is challenge.
Batch script.
hub.bat
java -jar selenium-server-standalone-3.14.0.jar -role hub
hub.vbs
createobject("WScript.Shell").run "hub.bat",false
Create same setup .vbs and batch for your nodes.
for Session-0 Insight refer my ans

Selenium with Windows Release Mangement

In Microsoft Release Management 2013, in the Powershell Executor step we have configured a step to trigger a Windows batch file. This batch file will be executed on a different server, which also happens be our App Server. As an experiment, we have a simple test case to open IE, access the Google homepage URL and close the browser, a screenshot will also be captured. When we run the job from RM, the Selenium logs say that the browser is launched and the test was successful. But when we check the screenshot it is just a black screen. All this runs as the Windows service account user which is the same user that is running RM. This user has no log on privilege.
If I log into the App server with my own ID and execute the batch file manually, the screen shot is captured correctly.
I have read several online posts regarding the black screen. People have said that the screenshot is black because the screen is locked. Does this mean the RM Powershell executor step must be executed with some other credentials instead of service account? If yes, how do we do this? In some suggestions it was mentioned to install VNC. Is that relevant in this situation?
I'm fairly new to Windows. I've mostly been working in Linux systems and I've been requested to debug this issue here. Any pointers/guidance will be appreciated. Thank you!
The deployment agent does not run as an interactive service. You're going to have a lot of trouble getting it to directly invoke Selenium tests. I wrote a blog post a few years ago showing how I accomplished it. Basically, you use Selenium hub to execute the tests interactively from agent machines.
We finally got this to work.
We were invoking the testNG selenium tests within a batch script. This script was specified in RM within the Powershell Executor task. The main point to note is that, in the Powershell executor task, we must first have a cd (change directory) command to change into the directory where the Selenium scripts are. Then specify the complete path to the batch script to be executed in the same Powershell executor task. This cd command is very important. Without this, the batch script would be executed but the selenium step within that wouldn't work. You would just get a vague "configuration errors:1" in the final output.
We took care of website authentication using AutoIT for IE browser.

Starting webDriver endpoint in current users's desktop from linux through powershell

I have a test cluster that contains a linux machine, an iMac and a windows 7 PC.
The linux machine hosts junit tests that I wrote and the other two machine serve as endpoints for browser automation tests using webDriver.
The script that executes the junit tests loops through different browsers and executes the junit tests against each browser using selenium webDriver. So far, the browsers include iphone, ipad, safari (mac), firefox (mac), chrome (mac), IE10 (win7), firefox (win7), chrome (win7).
While developing this test cluster, I encountered random crashes of webDriver on each of the two endpoints and found it necessary to write a kill/restart of the webDriver jar file. Now, this was a relatively simple matter on the iMac, but on the Windows 7 PC this is proving to be extremely difficult.
The linux machine has a script that checks to see that the webDriver endpoint is available by checking http://windows.Host:4444/wd/hub/status and if it isn't, it shells into powershell on the Windows 7 PC (I have freesshd setup to point to powershell instead of cmd.exe) and runs these commands:
Stop-Process -name java
Start-Process -FilePath C:\webDriver.bat
webDriver.bat contains:
java -jar C:\selenium-server.standalone-2.33.0.jar
Here is the problem I am having:
when powershell restarts webDriver using the above comands, the wedDriver endpoint is reachable but not visible. My tests proceed but fail because the browser is not running in the current desktop but instead some virtual one or another users Desktop. When I run webDriver.bat manually, webDriver runs in a cmd.exe window and the tests execute against all win7 browsers fine, providing webDriver doesn't crash.
Here is my question:
How do I make webDriver execute in such a way that my tests proceed and run correctly, rather than in the background/another user's desktop? These tests are part of Build Verification and need to be run on demand, so having someone manually run webDriver.bat is not an option.
I previously tried to have webDriver's jar running as a service and using samba to restart that service as needed, but ran into the same problem. Powershell seemed to be a better alternative with better control and the ability to verify that the jar file is running, but I don't know if I am heading in the wrong direction here.
I don't relish having to learn powershell to accomplish something that was relatively easy on another OS, but understand that this may be my only option. I also know that the commands I'm using do not constitute a good script and welcome suggestions on how to better achieve my goal here.
Thanks.
Sounds like you just need to pass the host option like so:
java -jar selenium-server-standalone-2.37.0.jar -host 0.0.0.0
Powershell might have permission restrictions on binding to all ports that can be overcome by setting the correct policy. See my blog post here for ideas.
You question is pretty long winded...can you shorten it?

Powershell script running more slowly in a runspace than in the shell

I've a PS script which I use to keep track of my VMWare ESX servers. I need to run it as a service so that I'm not permanently logged on. Unfortunately, the script runs more slowly if I use a runspace inside a service rather than just running the script through the powershell console. It's taking 2-5 minutes to make calls to the VMWare web service instead of a second or so.
Is there some sort of magic I should be using when I invoke the runspace?
You can run the script as a scheduled task.
Without seeing what you're doing, I can't think of many things that would make that big of a difference:
Do you have profile customization that might be helping it out when it runs in PowerShell (test with PowerShell -noprofile)
Are you counting the time it takes to initially import a module or snapin in your service, but not in PowerShell.
Are you re-creating the whole runspace each time in your service?
Have you tried using the 2.0 API of PowerShell with PowerShell.Create() to run it?
Finally, you could also take a look at some of the open source PowerShell hosts like PoshConsole or bgHost on CodePlex ... if they don't run it slowly, then you could follow the process they use for creating their runspace.
Does the service authenticate as a user with the same rights you do? I suspect something is timing out when it runs as the service, which you don't see when you run the script yourself.
The script in question runs equally slowly whether it runs in a service using its
usual service account, or if I run as myself in a very basic console app (create
runspace, add script, execute).
Apart from the usual suspects (account rights, Set-ExecutionPolicy RemoteSigned, and firewall configuration) I can't think of a good reason why PowerShell shouldn't work exactly the same in a Windows Services as it does in a console application, which makes me think it might be something environmental. It's not something silly like poor DNS resolution, is it? Assuming you're running this on a server, does it also perform slowly on your development machine too?
PS: I wonder if this question might be more appropriate for ServerFault?

Resources