In the last tutorial we went through three different IDE’s, which we can choose for writing and executing our scripts. Based on your choice, the ease of use and keeping the execution environment (Win or Linux or else), you need to choose one out of that.
Because of the simplicity, plethora of support by community and a feature-rich platform, we would use PyCharm, for our scripting writing purposes.
Now that we have both the Selenium set up with Python done and , IDE choose, we would want to get started with our first simple script with Python and Selenium.
Before that, we would wonder how we would set up a simple project or write a program in PyCharm. Don’t worry. It is very easy. For a person with previous IDE experience, it should be a cake walk. For first-timers, it shouldn’t be difficult or clumsy too. You need to follow the steps, as I have mentioned here :
Installing PyCharm
As usual, before using anything, we must install it. So we’re going to see install PyCharm on out system. You can easily install PyCharm using the command line in these four commands
wget -q -O - http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -
sudo sh -c 'echo "deb http://archive.getdeb.net/ubuntu trusty-getdeb apps" >> /etc/apt/sources.list.d/getdeb.list'
sudo apt-get update
sudo apt-get install pycharm
Let the installation complete. After finish, you can search for PyCharm in the Unity dash and click on it to get started.
Creating First Project
It’s time to create first project in PyCharm. Fire up your PyCharm.
- Go to File -> New Project
- We name out Project as myFirstTest. In the Interpretor sector, you can see that by default Python 3.4 is coming up. If you click on the down arrow, to the left of it, you can see that you also have the option of using Python 2.7, which is shipped with this version of Ubuntu. In our first tutorial, we had changed the preference to Python 3.4
- Click on Create and you’ll see that you project is created.
- Right Click on the project you just created. Select New option and the you’ll see new options of creating a Python file, Package etc. Select Python file.
- In the next dialog box that appears, enter the name of Python file. The second option gives you to select the kind of Python file that you want to create. It may be a blank python file or a unittest python file (which we will use later on). Select the first option.
- Click OK. A blank python file like the one below will appear.
Now we are all set, let us go ahead and write our first script.