Skip to content

Instantly share code, notes, and snippets.

@sqe
Last active February 14, 2023 21:04
Show Gist options
  • Save sqe/50cd0acdd29e00849313e8822e9afe68 to your computer and use it in GitHub Desktop.
Save sqe/50cd0acdd29e00849313e8822e9afe68 to your computer and use it in GitHub Desktop.
ea - self homework
{
"_company": "#company",
"_email": "#email",
"_first_name": "#first_name",
"_industry": "#industry",
"_last_name": "#last_name",
"_phone": "#phone",
"_start_trial": "/html/body/main/section[2]/div/div[2]/form/div[6]/div[2]/button",
"_title": "#title"
}
FROM alpine:latest
MAINTAINER Aziz Kurbanov <azizbek@gmail.com>
# To build:
# docker build --no-cache=true -t ea .
# To Create Container:
# docker run --name ea_flask -i --restart=always -p 50789:5000 -d ea
WORKDIR /api
COPY ./api /api
# up
RUN apk update
# Install bash
RUN apk add --no-cache --update-cache bash
# Install python
RUN apk add --no-cache python
# Install UWSGI
RUN apk add --no-cache uwsgi
# Install pip
RUN apk add --no-cache py-pip
# Install Flask
RUN pip install flask
# Install gunicorn
RUN pip install gunicorn
# Install requests
RUN pip install requests
# Install git
RUN apk add --no-cache git
# Clean up
# RUN rm -rf /var/cache/apk/*
EXPOSE 50789
CMD ["python", "service.py"]
# -*- coding: utf-8 -*-
import requests
from flask import Flask
from flask import jsonify
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
app.config['PROPAGATE_EXCEPTIONS'] = True
s = requests.Session()
@app.errorhandler(500)
def internal_server_error(error):
return "HTTP 500 error"
@app.route('/', methods=['GET'])
def index():
return "please go to /elements"
@app.route('/elements', methods=['GET'])
def elements():
return jsonify(
_first_name = '#first_name',
_last_name = '#last_name',
_company = '#company',
_title = '#title',
_email = '#email',
_phone = '#phone',
_industry = '#industry',
_start_trial = '/html/body/main/section[2]/div/div[2]/form/div[6]/div[2]/button')
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', threaded=True)
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import selenium.webdriver.support.ui as ui
import unittest
_first_name = '#first_name'
_last_name = '#last_name'
_company = '#company'
_title = '#title'
_email = '#email'
_phone = '#phone'
_industry = '#industry'
_start_trial = '/html/body/main/section[2]/div/div[2]/form/div[6]/div[2]/button'
class FreeTrialPage(unittest.TestCase):
@classmethod
def setUpClass(self):
self.verificationErrors = []
self.driver = webdriver.Chrome()
# self.driver = webdriver.Remote(command_executor='http://localhost:32771/wd/hub', desired_capabilities=DesiredCapabilities.CHROME)
self.driver.maximize_window()
self.base_url = 'http://www.elementanalytics.com'
self.uri = '/free-trial'
self.driver.get(self.base_url + self.uri)
self.wait = ui.WebDriverWait(self, 30)
self.wait.until(lambda driver: self.driver.find_element_by_xpath(_start_trial).is_displayed())
self.driver.find_element_by_xpath(_start_trial).click()
@classmethod
def tearDownClass(self):
self.driver.quit()
def warning_message_of_element(self, element):
parsley_id_value = self.driver.find_element_by_css_selector(element).get_attribute('data-parsley-id')
parsley_id_name = 'parsley-id-' + str(parsley_id_value)
parsley_ul = self.driver.find_elements_by_id(parsley_id_name)
warning_message = parsley_ul[0].text
return str(warning_message)
def test_empty_first_name_warning(self):
assert self.warning_message_of_element(_first_name) == 'This value is required.'
def test_empty_last_name_warning(self):
assert self.warning_message_of_element(_last_name) == 'This value is required.'
def test_empty_company_warning(self):
assert self.warning_message_of_element(_company) == 'This value is required.'
def test_empty_title_warning(self):
assert self.warning_message_of_element(_title) == 'This value is required.'
def test_empty_email_warning(self):
assert self.warning_message_of_element(_email) == 'This value is required.'
def test_empty_phone_warning(self):
assert self.warning_message_of_element(_phone) == 'This value is required.'
def test_empty_industry_warning(self):
'''
test_empty_industry_warning
This case must be clarified, for now we will just make sure that the proper exception is thrown.
'''
# assert self.warning_message_of_element(_industry) == 'This value is required.'
self.assertRaises(IndexError, lambda: self.warning_message_of_element(_industry))
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import selenium.webdriver.support.ui as ui
import unittest
import requests
class FreeTrialPage(unittest.TestCase):
@classmethod
def setUpTestData(self): # Loading elements from API
self.s = requests.Session()
self.api_data = self.s.get('http://localhost:50789/elements').json()
return self.api_data
@classmethod
def setUpClass(self):
self.data = self.setUpTestData()
self.verificationErrors = []
self.driver = webdriver.Chrome()
# self.driver = webdriver.Remote(command_executor='http://localhost:32771/wd/hub', desired_capabilities=DesiredCapabilities.CHROME)
self.driver.maximize_window()
self.base_url = 'http://www.elementanalytics.com'
self.uri = '/free-trial'
self.driver.get(self.base_url + self.uri)
self.wait = ui.WebDriverWait(self, 30)
self.wait.until(lambda driver: self.driver.find_element_by_xpath(self.data['_start_trial']).is_displayed())
self.driver.find_element_by_xpath(self.data['_start_trial']).click()
@classmethod
def tearDownClass(self):
self.driver.quit()
def warning_message_of_element(self, element):
parsley_id_value = self.driver.find_element_by_css_selector(element).get_attribute('data-parsley-id')
parsley_id_name = 'parsley-id-' + str(parsley_id_value)
parsley_ul = self.driver.find_elements_by_id(parsley_id_name)
warning_message = parsley_ul[0].text
return str(warning_message)
def test_empty_first_name_warning(self):
assert self.warning_message_of_element(self.data['_first_name']) == 'This value is required.'
def test_empty_last_name_warning(self):
assert self.warning_message_of_element(self.data['_last_name']) == 'This value is required.'
def test_empty_company_warning(self):
assert self.warning_message_of_element(self.data['_company']) == 'This value is required.'
def test_empty_title_warning(self):
assert self.warning_message_of_element(self.data['_title']) == 'This value is required.'
def test_empty_email_warning(self):
assert self.warning_message_of_element(self.data['_email']) == 'This value is required.'
def test_empty_phone_warning(self):
assert self.warning_message_of_element(self.data['_phone']) == 'This value is required.'
def test_empty_industry_warning(self):
'''
test_empty_industry_warning
This case must be clarified, for now we will just make sure that the proper exception is thrown.
'''
# assert self.warning_message_of_element(_industry) == 'This value is required.'
self.assertRaises(IndexError, lambda: self.warning_message_of_element(self.data['_industry']))
[uwsgi]
module = main
callable = app
processes = 8
threads = 8
max-worker-lifetime = 30
enable-threads = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment