Giter VIP home page Giter VIP logo

capybara.py's People

Contributors

bv avatar dwt avatar elliterate avatar william-yeh avatar

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

capybara.py's Issues

Add more maintainers

Hi there,

as someone who uses capybara (ruby) to test my python projects, this seems like a godsend. However, the project seems also quite a bit too much dead - as in not releasing anything.

Have you thought about adding more maintainers? Perhaps moving the project into it's own organisation? Because as far as I can tell, this project is hugely missing in the python acceptance testing ecosystem.

Support playwright-python

Playwright is a new kid on the block for browser-automation, with some interesting features. Since it also allows selection by xpath, there should not be a principle reason why it can't be supported as an alternative to Selenium in capybara.

Playwright has some interesting features, but it's API sucks - even though not quite as hard as selenium.

What do you think?

Robot Framework Library

I like Capybara from ruby. Some time I have been following and using Caybara-py, but I am sad because have no see updates since 2018.

You think about creating a Capybara-py library for Robot Framework?

Django test cases cooperation

Hi @elliterate ,

Thanks for your great work. I've configured capybara.py to support my Django app and it works OK. I'm able to visit webpages and basic functions works as expected ๐Ÿ‘

I've built my tests using django.test.TestCase and before visiting some URL i'm adding some items to my database to display them. But unfortunately in browser my application's database is empty.

My skeleton looks like this

import capybara
import capybara.dsl
from capybara.selenium.driver import Driver
from my_project.wsgi import application

from django.test import TestCase

@capybara.register_driver("selenium_chrome")
def init_selenium_chrome_driver(app):
    return Driver(app, browser="chrome")

capybara.default_driver = "selenium_chrome"
capybara.app = application


class IntegrationTest(TestCase):
    def setUp(self):
        self.page = capybara.dsl.page

    def tearDown(self):
        capybara.reset_sessions()

    def test_show_index_page(self):
        # Add some data here
        self.prepare_test_data()        

        # Unfortunately here, in browser none of test data is available
        self.page.visit('/')

Is this an expected behaviour or am I doing something wrong ?

Browser shutdown is not extendable

Hi there,

I'm currently experimenting with docker images and found that it is really hard to use capybara while running the browser in one of the selenium provided docker images e.g. this one.

I'm not entirely sure it's a real problem as on an integration server you would probably just run both the tests and the browsers either in the same image or in two images whose runtime is managed by the build service anyway.

However, in my local environment where I have pytest starting and stopping the docker container as a fixture, I have run up against the problem that capybara-py tries to exit the browser in a atexit() handler. This is very nicely test framework independent, but also really hard to extend, as I cannot easily schedule a fixture cleanup after that particular atexit() handler.

Is there a way that I'm missing to control when capybara tries to kill the browser? Ideally I could control the lifetime of the browser from a fixture too, as that would give natural control to me.

Is it possible to enable "Remote Browser" for Capybara?

In Ruby version of Capybara, it is possible to connect to remote browser (such as ChromeDriver).

For example: https://gist.github.com/jasoncodes/6025475

Capybara.register_driver :chrome do |app|
    Capybara::Selenium::Driver.new(app,
      :browser => :remote,
      :desired_capabilities => :chrome,
      :url => "http://#{ENV['CHROME_HOSTNAME']}:4444/wd/hub"
    )

Is it possible to modify the capybara.py/capybara/selenium/browser.py to add a "remote" case for browser_name?

Thanks.

onbeforeunload not handled correctly in firefox-webdriver

Hi there,

it seems that there is code that is supposed to handle this condition, but it doesn't work for me - i.e. hangs indefinitely. Also, if the onbeforeunload handler is triggered in a different (background) window, it seems that this condition is not handled at all, but instead the window just gets a close event and doesn't close.

Here's my reproducer:

# https://github.com/elliterate/capybara.py

import capybara
from capybara.dsl import page

from conftest import find_firefox

HEADLESS = True
HEADLESS = False

@capybara.register_driver("selenium")
def init_selenium_driver(app):
    
    from selenium.webdriver.firefox.options import Options
    options = Options()
    options.binary_location = find_firefox()
    options.headless = HEADLESS
    # otherwise marionette automatically disables beforeunload event handling
    # still requires interaction to trigger
    options.set_preference("dom.disable_beforeunload", False)
    
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    capabilities = DesiredCapabilities.FIREFOX.copy()
    capabilities["marionette"] = True
    
    from capybara.selenium.driver import Driver
    
    return Driver(app, browser="firefox", options=options, desired_capabilities=capabilities,
        # cannot set these after the fact, so we set them here
        clear_local_storage=True,
        clear_session_storage=True,
    )


capybara.default_driver = "selenium"
capybara.default_max_wait_time = 5

def test_isolation(flask_uri, ask_to_leave_script):
    page.visit(flask_uri)
    
    # onbeforeunload dialog
    # bug in capybara, ask to leave script is only handled in current window, other windows just get closed and then hang
    # Even though it is handled in the code, that doesn't work for firefox. (?)
    page.execute_script(ask_to_leave_script)
    # page interaction, so onbeforeunload is actually triggered
    page.fill_in('input_label', value='fnord')
    
    # bug in capybara: background windows don't even have code to handle dialogs like onbeforeunload
    with page.window(page.open_new_window()):
        page.visit(flask_uri)
        page.execute_script(ask_to_leave_script)
        # page interaction, so onbeforeunload is actually triggered
        page.fill_in('input_label', value='fnord')
    
    page.reset()  # hangs on the onbeforeunload handlers
    
    assert len(page.windows) == 1
    assert page.current_url == 'about:blank'

Redirects in the Werkzeug browser retain method, headers and params

capybara.werkzeug.browser.Browser._process_and_follow_redirects handles redirects in what I would consider a wrong way. I'm talking specifically about

self._process(method, path, params, headers)

What it does at the moment is to retain basically all data from the original request, except the path, which it overrides. This means that if you for instance make a POST request to a URL, and that URL redirects to another page, the second request will be the same. This is a violation of HTTP/1.1 for the 303 status code (which demands a GET request for the new location), and โ€“ worse โ€“ inconsistent with how all browsers I know of handle 302 and possibly 301.

Thus, my proposal would be a diff of the following nature:

-                self._process(method, path, params, headers)
+                self._process('GET', path, None, headers)

Whatever params would be needed for the subsequent request would be indicated in the response's Location header.

I am unsure whether headers should be retained in its entirety, but I don't know what would be consistent with browser behaviour.

Automatic login for each test

I'd like to skip filling in the login form for each single test that requires authentication.

Is there an easy way to do this? I was checking out session.fill_in("q", value="Capybara"). But I can't seem to find any session available to me in the dsl object even though it states that When using :mod:capybara.dsl, the Session is initialized automatically for you.

What's a preferred method of doing this?

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.