After creating the pipenv we need to make sure that PyCharm is using the new environment as the interpreter.
To set it up, go to PyCharm Preferences > Project Interpreter (under Project), click on the dial (gear icon) and Add.
Select that we want to use an Existing Environment.
Navigate to the path where the virtual environment is situated.
Select bin > python and tap OK.
As you can see our Python interpreter is now pointing to the virtual environment that we just created.
Now that we have the API key from Applitools, let's add it to use in our automation framework.
There are a couple of approaches to that.
We can either add it as an environment variable and use it directly with our framework.
Or a simple approach could be to add it as a constant in the project for us to use and then, later on, override it.
For the purpose of these demos, we are going to add it as a constant in a base.py
file and use that within our test.
So here I have the sample project structure under automation > config I have a base.py
file and a constant by Applitools API key.
Let's post our API key here, which we will be using later on in our automation framework.
In this video, we are going to see how to initialize Eyes in our automation framework.
I have a basic HelloWorldTest
with an empty method definition that is inheriting from a BaseTest
class.
BaseTest
is actually an instance of Python unittest TestCase
class.
In it we have a simple setUp
andtearDown
method.
To add Eyes into this setup, let's add a method, initialize_eyes
and let's create an object of Eyes
class.
Additionally, the Eyes object also needs the API key to be set. As you can remember, we had the Applitools API key situated in the base.py
file. Let's import that.
Also, let's make sure we call the initialize_eyes
function in the setUp
method
from unittest import TestCase
from applitools.selenium import Eyes
from selenium import webdriver
from automation.config.base import APPLITOOLS_API_KEY
class BaseTest(TestCase):
def setup(self):
self.driver = webdriver.Chrome()
self.initialize_eyes()
self.driver.get('https://applitools.com/helloworld')
def teardown(self):
self.driver.quit()
def initialize_eyes(self,):
self.eyes = Eyes()
self.eyes.api_key = APPLITOOLS_API_KEY
return self.eyes
And that's it.