Web UI Automation login and then submit form with Powershell/Curl equivalent - forms

This is for a Windows environment: Windows 7-10 / Server 2008/2012.
I want to create a script which will automate login at a URL, navigate to a another page, and then submit a form on that page.
Open Internet Explorer, if not already opened
Login to www.example.com/login (takes me to www.example.com/home)
Once logged in, go to www.example.com/submit-form-data
Enter values for fields and submit the form via button click
At first, I thought maybe I could use something like iMacro, a greasemonkey alternative, or even bookmarklets. But that'd all still require some user intervention. If there is a macro program which can replay all the steps, perhaps I'd be open to that. Otherwise, I think I may need to employ some kind of PowerShell or Curl-like program for Windows to handle UI automation.
At least with PowerShell, I don't think submitting a form should be too bad. If that's all I had to do, I wouldn't need any help. The problem is how do I log into a site, then navigate to a specific URL, on top of submitting a form, all in the same script?
I don't have to use PowerShell. I'd be open to alternatives to Curl on Windows, whatever those might be.
Thank you for your help in advance.

If your goal is to drive Internet Explorer, the most painless and robust way to accomplish this is probably to use Selenium WebDriver.
Many folks successfully use it on Windows via the Selenium C# bindings (although my favorite way to use Selenium on Windows is via the Selenium Python bindings).
If you're keen on using PowerShell, it should be possible to use Selenium from PS, although there are no official PS bindings from what I can tell.

Related

Powershell won't pass keystroke to cli window

I first need to offer the disclaimer that I am barely a novice when it comes to scripting or coding, so I might be doing this all wrong in the first place. I'm running into an issue with a script I had written in powershell a while ago that is used on several hundred computers in my company daily to automate starting a certain app that everyone uses. So far everyone else hasn't had an issue except one machine.
Normally when I run the script, it starts the services and cli for the program which opens in a new window. Then the script, still open behind that, sends all of the key commands to that cli window, pauses for a brief line of user input after which it closes that cli window, does a few other clean up tasks and closes out itself.
The only difference on this one machine that's not working is the script won't pass the keystrokes to the cli window. If I put them in manually including the normal user input, it finishes the rest of the script just fine, but the cli window is just not receiving the keystroke input from the main script.
The only part of the script that send the keystrokes to the cli window is a few lines of this:
[System.Windows.Forms.SendKeys]::SendWait("Text{Enter}")
I have tried using the sleep command before and in between the key commands to make sure it's not going through the keystrokes to early. I've checked and windows had gone through an Update two days ago, but we would've heard about this issue right then if that was it. I'm at a loss for what the issue could be and would apreciate and help, tips, or direction to help figure this one out.
Is the console window the active window when the keys are sent? The documentation for the class you are calling indicates that it sends the keys to the active window. Not only that, but the documentation also seems to indicate that there are some issues that developers have run into when using that class to sends keys. I would try using the autoit powershell module instead. Autoit is its own scripting language which specializes in automating windows processes and being capable of automating interactions with windows forms, but also comes bundled with its own powershell module that I think is exactly what you need, so I would download the portable "zip" package, extract the powershell module from "Autoitx", and that should help you accomplish what you need
PowerShell automation especially when using SendKeys can / is glitchy due to many varying reasons. Can you use SendKeys sure, but you have to know the environment it will be run in and the needed performance details. Hence your futzing/guessing with Sleep.
There are purpose-built tools to help.
Auto HotKey
'PowerShell auto hotkey'
or the UIAutomation tool
'PowerShell automating other applications'

Is it possible to automate windows application?

I have some test cases to validate whether the user details are appearing when applications like (SQL Server, Bitbucket, RDC, PuTTY etc. ) are launched. I want to understand if this scenario can be automated through PowerShell.
https://wasp.codeplex.com
 WASP is a PowerShell snapin for Windows Automation tasks like selecting windows and controls and sending mouse and keyboard events. We have automation cmdlets like Select-Window, Select-Control, Send-Keys, Send-Click, Get-WindowPosition, Set-WindowPosition, Set-WindowActive, Remove-Window ... etc.
Our goal is to enable you to accomplish most Windows GUI Automation scripting from inside PowerShell, without resorting to specialized (and expensive) scripting tools. 
Just to be clear, don't expect any "click to record" functionality ... but do expect to be able to automatically tile windows, send mouse clicks and keystrokes, and in general, automate those tasks that you would normally not be able to do from a console.

Want to execute single step in selenium web driver

I am using selenium webdriver to do automation of web application.(I am using eclipse)
In my test, I have written the code to login the page by credential, then click some links and go to a particular page.Now on that page i am filling fields through drop down and all and its not working.
So My question is if i changing my code to work with drop down,then to test this again i need to run test case from starting.Means again it it will login page will load and go through various links and then reach to that page.
So can not directly execute that steps only like we do in selenium IDE???
Again and again executing from starting is really screwing my time...??
Is there any way/shortcut?? Please suggest me.
Thanks
Selenium IDE is in-browser, it's then normal you can run at any step. But if your cookies have expired, you'll have to reauthent. It's not a Selenium problem, it's how websites work.
In your tests, you'll always have to start from scratch if your cases involve athent process, unless you manage to get a fine control over your cookies.
You can always make a quick http call to the website you want to connect to with HTTPClient for example, just to get the cookie back, then use it in webdriver with something like
driver.manage().addCookie(new Cookie("foo", "bar", "www.domain.com", "/", null));
then go to the page you need. Notice that this solution solves the Authent problem only, and does not control the state of the tested web-application (data previously posted, etc...).
At our company, we make an extensive use of selenium, and have a lot of tests relying on it, it's therefore a problem we know something about and we are aware of the frustation it can cause.
We use a pretty different solution to get a productivity boost on tests.
In fact, we're using a Groovy Shell-based solution which allows us to go back and forth while developping the tests and keep our browsers open. Groovy is a JVM scripting language that is really easy for a Java dev (almost all Java code is valid Groovy code) and it's really dynamic.
So you can download groovy, run groovy shell (groovysh is the command), then line by line you can launch and interact with the browser xhile your written code is saved to a buffer. When you've done with your test, export the code and put it in Eclipse. It's faster than restarting every time from scratch. Magic lines for starting with selenium are
groovy.grape.Grape.grab(autoDownload: true, group : 'org.seleniumhq.selenium', module : 'selenium-firefox-driver', version : '2.37.1')
import org.openqa.selenium.*
import org.openqa.selenium.firefox.*
driver = new FirefoxDriver()
driver.get("http://my-website.com")
From this point, the browser window is always open, and you develop right in groovy (or java). It's like a selenium-ide, but in groovy, and can be integrated in your developement workflow (but there is a bit of work to do)
This example works for Firefox (as you've probably guessed ;-)) but you can adapt it as you like. We have from this constructed a bunch of tools to develop our tests quickly and iteratively. We found this to be a great savior.
In the case you described, the tests will always return to step 1, therefore, you need to execute your automation suite from the beginning.
Tip for the future, separate your test cases to shorter ones (as Alexander suggested), so you if you need, you can easily use only the cases that needed and relevant to the module you currently working on.
There is nothing different answer..runs from first step...
And my kind advice is that to use a break point in eclipse at which u r guess of failing...and run the eclipse program in debug mode vth continuously pressing F6 key.
The excecution will be slowed and display will be step by step mode which u can easily trace the exact location at which u r code is breaking...

Is there a way to automatically log onto a Windows XP machine at specific time?

How to set a specific logon time for a specific user on Windows XP?
For example, the computer is an "always on machine" and most of the time no one is logged on. I want to set a time for my user to log on, without someone actually having to be in front of the machine. I've tried a workaround with the built-in auto logon function (control userpassword2), but I still need a secure system as I'm not the only user, and would still want a password even if I was the only user.
I have searched for third party software, but to no avail. I've a good knowledge of batch and Python scripting and a little of Java, so any pointers with any of those would help.
How can it be "secure" if it logs you on without you being there? Surely it would be better for it to wait for you to type in a password (i.e. the login prompt)?
If you want a fast "startup" time, then you can lock the workstation (ctrl+alt+del to open the Task Manager and then click 'Lock'. This shows a dialog just like the login prompt, but when you enter your password you instantly continue your existing session). Or if you want to be more eco friendly, put your PC into Sleep mode, which most PCs will return from (again with an optional password prompt) in less than 5 seconds.
One way I just thought of: Run a Vnc Server, and hack into an open source viewer program. Then you can rig it with some code to pass keyboard commands back into the computer, maybe implement some screen scraping to make sure it only does it when appropriate.
But seriously, there has to be a better way. Why are you trying to do this?

Automate Human Activity software

Anyone know any softwares that can simulate human interaction on desktop browser specifically by clicking or entering some data and run some report and print automatically obviously with some programming behind this. Main, it will be used for reducing business process steps on human interaction day to day activity (possibly testing purpose in the future).
I am appreciated your comment or input.
Thanks
I tried a few different automation tools myself when trying to automate desktop software, one is AutoIt which is one of the most complete in my opinion. It helps to automate small tasks, ie: select a window and press a button to do the rest. It even has a macro recorder to get you started.
Telerik WebUI Test Studio
Watir
Selenium
...to name a few
To keep up with the namedropping, here's 2 APIs for Java:
Robot
Abbot (Built on top Robot)