Python for frontends :P
Annotation: This is my first contact with selenium :)
Selenium es un paquete de python para automatizar pruebas permitiendo simular las interacciones que realizan los usuarios en el navegador (browser).
Nació en el 2004, la versión 1 era conocida como Selenium RC (Remote Control), la versión 2 es conocida como Selenium Webdriver.
La instalación como cualquier otro paquete de python se realiza con pip
pip install selenium
Para usar selenium en la configuración con docker es necesario usar las siguientes imagenes:
selenium/standalone-chrome:2.53.0
selenium/standalone-firefox:2.53.0
selenium:
image: selenium/standalone-chrome:2.53.0
container_name: <nombre>
environment:
JAVA_OPTS: -Djava.security.egd=file:/dev/./urandom
volumes:
- /dev/shm:/dev/shm
- ../..:/app
ports:
- "4444:4444"
networks:
<network name>:
aliases:
- <nombre>
from django.test import TestCase
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class SeleniumTest(TestCase):
def setUp(self):
self.browser = webdriver.Remote(
command_executor='<a class="linkclass" href="http://gollum23-selenium:4444/wd/hub">http://gollum23-selenium:4444/wd/hub</a>',
desired_capabilities=DesiredCapabilities.CHROME
)
def tearDown(self):
driver = self.browser
driver.quit()
def test_google_site(self):
driver = self.browser
driver.get("<a class="linkclass" href="http://gollum23-django:8010/admin/login">http://gollum23-django:8010/admin/login</a>")
self.assertIn('Log in', driver.title)
driver.close()
from django.test import TestCase
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
class SeleniumTest(TestCase):
def setUp(self):
self.browser = webdriver.Remote(
command_executor='http://gollum23-selenium:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME
)
def tearDown(self):
driver = self.browser
driver.quit()
def test_admin_login_fail(self):
driver = self.browser
driver.get("http://gollum23-django:8010/admin/login")
username_field = driver.find_element_by_id('id_username')
password_field = driver.find_element_by_id('id_password')
username_field.send_keys('gollum23')
password_field.send_keys('platzi2016', Keys.ENTER)
self.assertNotEqual('Site administration',
driver.find_element_by_tag_name('title'))
driver.close(
Por id
self.browser.find_element_by_id('id')
self.browser.find_elements_by_id('id')
Por name
self.browser.find_element_by_name('name')
self.browser.find_elements_by_name('name')
Por clase
self.browser.find_element_by_class_name('name')
self.browser.find_elements_by_class_name('name')
Por xpath
self.browser.find_element_by_xpath('//form[0]/div[0]/input[0]')