Giter VIP home page Giter VIP logo

splinter's Introduction

splinter

Splinter is a simple and consistent API for web application automation.

PyPI PyPI - Python Version License Build status

Key features:

  • Easy to learn: The API is designed to be intuitive and quick to pick up.
  • Faster to code: Automate browser interactions quickly and reliably without fighting the tool.
  • Powerful: Designed for real world use cases, it guards against common automation quirks.
  • Flexible: Access to lower level tools is never hidden. Break out into raw Selenium at any time.
  • Robust: Support is available for multiple automation drivers (Selenium, Django, Flask, ZopeTestBrowser).

Example

from splinter import Browser


browser = Browser('firefox')
browser.visit('http://google.com')
browser.find_by_name('q').fill('splinter - python acceptance testing for web applications')
browser.find_by_name('btnK').click()

if browser.is_text_present('splinter.readthedocs.io'):
    print("Yes, the official website was found!")
else:
    print("No, it wasn't found... We need to improve our SEO techniques")

browser.quit()

Getting Started

Pytest Plugins

Page Objects

Support for page objects is available through the following package:

splinter's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

splinter's Issues

Explain what splinter is

In documentation explain with a little more details what Splinter is and why you should consider use this tool.

should be able to change headers

I heard people coming back to webrat just because capybara does not have a good way to change headers.

we should allow people do do something like:

browser.headers['Content-Type'] = 'application/pdf'

browser.visit doesn't properly work in Google Chrome

Nowadays splinter tests occur visiting always the same web page.
This approach shades a problem with chrome:

let's say we are logging into a Django website:

browser = Browser('webdriver.chrome')
browser.visit("http://localhost:8000/admin/")

browser.find_by_id("login-form") # returns the login form

browser.fill("username", "johndoe")
browser.fill("password", "123456")
browser.find_by_id("login").first.click()

browser.visit("http://localhost:8000/some-other-page/")
browser.find_by_id("login-form") # should not see the login form, since I already logged in

What happens is that every single time I use browser.visit(), chrome opens a new tab, and all the next calls browser.find_by_something effects the first tab, not the new one.

In order to workaround this behaviour I had to hack splinter to use a javascript call to "location.href".

Below I put an example from my django project (using lettuce):

# -*- coding: utf-8 -*-
import urlparse
import warnings
from lettuce import before, after, world
from splinter.browser import Browser

warnings.simplefilter('ignore')
@before.harvest
def setup_browser(variables):
    world.browser = Browser('webdriver.chrome')

    world._old_visit = world.browser.visit
    _base = 'http://localhost:8000/'
    _redirect = 'window.location.href="%s/";'

    def navigate(path):
        current_path = world.browser.url.replace(_base, '/', 1)
        if path == current_path:
            script = 'window.location.href=window.location.href;'
        else:
            script = _redirect % path.rstrip('/')

        return world.browser.execute_script(script)

    world.browser.visit = navigate
    world._old_visit(_base)
    world.current_path = lambda: urlparse.urlsplit(world.browser.url).path

@after.harvest
def teardown_browser(results):
    world.browser.quit()

Mouse events

Provide methods for mouse events: mouse over, mouse out, and others.

History

Support back and advance on history. It is important to note that some websites may block history.back() (from javascript), so I think we can't just do:

browser.execute_script('history.back();')

iframes

splinter should support iframes

refactor find pattern

Now find use one method for find by css_selector, xpath, tag, name or id:

browser.find(css_selector='h1')
browser.find(xpath='//h1')
browser.find(tag='h1')
browser.find(name='name')
browser.find(id='firstheader')

Other pattern is use one method for each selector type. Ex:

browser.find_by_css('.my-class')

wait_until method

It's need implements a method for waiting for elements to appear or to disappear on the page.

refactor form methods

splinter have finders by name, id, css_select, tag and xpath. But check, fill_in, choose get elements by name:

browser.choose("some-radio")

It's need change this, moving these methods from browser class to element class:

checkbox = find_by_name('my-checkbox')
checkbox.check()

Browser.choose and maybe others form related actions

Well, as I've saw, those methods just look for an objet using it's name. But, what if we, in example, there're 2 radio options to choose and both have the same name?

The point it's not the reason, but how to deal with that case. I think Splinter must have another options to search controls, like by id, class or even xpath too.

'pip install splinter' not working, missing README.rst

Hi,
I can't install splinter because when I run 'pip install splinter' I get the following error:

Downloading/unpacking splinter
Running setup.py egg_info for package splinter
Traceback (most recent call last):
File "", line 14, in
File "/home/cillian/.virtualenvs/batucada/build/splinter/setup.py", line 4, in
README = open('README.rst').read()
IOError: [Errno 2] No such file or directory: 'README.rst'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 14, in

File "/home/cillian/.virtualenvs/batucada/build/splinter/setup.py", line 4, in

README = open('README.rst').read()

IOError: [Errno 2] No such file or directory: 'README.rst'

Command python setup.py egg_info failed with error code 1

I think it's because the package at http://pypi.python.org/pypi/splinter/0.0.2 does not contain the README.rst file. Looks like a good package by the way.

method for input file

Create method for manipulate input files like:

attach_file('Image', '/path/to/image.jpg')

lxml install

lxml can be declared as a dependence in setup.py, so it would be installed together with splinter when installing with pip.

Provide a way to customize FirefoxProfile on WebDriver

It would be nice to be able to customize some settings on Firefox profile. Something like this code for Capybara:

class Capybara::Driver::Selenium
  def self.driver
    unless @driver
      profile = Selenium::WebDriver::Firefox::Profile.new
      profile['network.manage-offline-status'] = false
      @driver = Selenium::WebDriver.for :firefox, :profile => profile
      at_exit do
        @driver.quit
      end
    end
    @driver
  end
end

Selenium WebDriver for Python provides a FirefoxProfile class, so it's possible to create a new WebDriver instance with some customizations by hacking FirefoxProfile class. Here is an example, extracted from Rodrigo Manhẽs blog:

from selenium.firefox.firefox_profile import FirefoxProfile
prefs = FirefoxProfile._get_webdriver_prefs()
prefs['network.manage-offline-status'] = 'false'
@staticmethod
def prefs_func():
    return prefs
FirefoxProfile._get_webdriver_prefs = prefs_func

This hack looks ugly, because FirefoxProfile API has a bad design, it is just impossible to create a new FirefoxProfile instance and change some options, as in Capybara :(

Context based actions

Implement a way to execute actions on specific content areas.

Say you have many forms in a page, with similar fields, and want to select a field from a specific form, you could to something like:

in('#form-1').check('foo')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.