Hibernate
Liquid
Karma
Deploy
SASS
REST
Upgrade
Boot
Spring
Consume
Visualize
React
Angular

Are you afraid of snakes?

Python, Selenium

Have you ever wanted to create end to end tests for your app, but just can't find the time to get those tests working. Well, I have tried several frameworks from Cypress, to Selenium. I have always felt like this technology ought to be made simple. Just recently after taking another look at Selenium, I found the IDE to be very easy to use in order to quickly create scripts that could be improved by hand later. Here is a very simple example.

First I installed the Chrome Selenium extension.

https://docs.seleniumhq.org/selenium-ide/

I created a simple test using the record button and exported it as a Python test.

Then I installed the Python Webdriver using 

 
apt-get -y install python3.6
apt-get -y install python3-pip
pip3 selenium

Next I installed the chromedriver and I used NPM

 
npm install chromedriver

Now make sure you have Chrome installed. I used Headless on my server.

I may have added source first

 
apt-get -y install google-chrome-stable

Then I ran the following script with this command.

 
chmod 777 test.py
./test.py
 
#! /usr/bin/python3.6
import os  
from selenium import webdriver  
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.chrome.options import Options  
from selenium.webdriver.common.by import By

chrome_options = Options()  
chrome_options.add_argument("--headless")  
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.binary_location = '/usr/bin/google-chrome-stable'    

driver = webdriver.Chrome(executable_path=os.path.abspath("node_modules/chromedriver/bin/chromedriver"),   chrome_options=chrome_options)  
driver.get("http://www.jonclawson.com/")
driver.set_window_size(1280, 740)
driver.find_element(By.LINK_TEXT, "who").click()
assert driver.find_element(By.CSS_SELECTOR, ".title").text == "my name is jon"
text = driver.find_element(By.CSS_SELECTOR, ".title").text == "my name is jon"
print(text)
print('success')  
driver.close()