Create Alias for Interactive Console for Capybara on Windows


If you are working on shell most of the time Aliases are very help full and time saving. For testing purposes you can use Alias for getting ready your test suites. In this post, I want to explain both running Selenium and Capybara on console and creating aliases for each. This post is for Windows machines, if you are using Unix-like see this post.

Creating Scripts for Selenium and Capybara

First of all, it is assumed that you have installed Selenium and Capybara correctly and they work on your machines. If you haven't installed, you can see my previous posts. I am using Capybara with Ruby. You can use several different language for Selenium but Capybara works only with Ruby. Create scripts in a directory called scripts (better to use this all user so the path should look like c:/scripts) for your automation tool as following, save them as capybara.rb and sel.py respectively:

Creating Aliases For Windows

Creating Profile File

For windows we can use PowerShell, we can add for only current user or for all user. My aim is configure this in Jenkins machines so that it will be used for automation engineer to debug failures easily so I set it as for all users:

For current user, create Microsoft.PowerShell_profile.ps1 file by the following command under C:\Users\user.name\Documents\WindowsPowerShell:

New-Item -path $profile -type file -force
For all user, create profile.ps1 file by the following command under $PsHome folder, so first you need to get run $PsHome, but you should use PowerShell (x86)
new-item -path $env:windir\SysWOW64\WindowsPowerShell\v1.0\profile.ps1 -itemtype file -force


Writing Alias Description to Profile File

For current user, you should edit the following file:
C:\Users\user.name\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

For all user, you should edit the following file:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\profile.ps1
Add the following aliases to Profile File:
function cp-selenium { irb c:\scripts\capybara.rb selenium }
Set-Alias capybara-firefox cp-selenium

function cp-chrome { irb c:\scripts\capybara.rb chrome }
Set-Alias capybara-chrome cp-chrome


To run it


Open your shell and type capybara-chrome for Selenium with Chrome. Keep in mind that the scripts are include minimum required library so if you want additional functionalities you can import/require them. 


Other options:


> capybara-selenium
> capybara-chrome
> capybara-poltergeist

Comments

Popular posts from this blog

Selenium Error "Element is not currently interactable and may not be manipulated"

Change Default Timeout and Wait Time of Capybara

Performance Testing on CI: Locust is running on Jenkins

Selenium Chromedriver Error Message: u'unknown error: unable to discover open pages

Getting the text of elements in Espresso