Lona has no browser tests #96
Replies: 27 comments 1 reply
-
I will have time this week to contribute my vision on browser testing, I am going to use Cypress. We can compare / merge our approaches. |
Beta Was this translation helpful? Give feedback.
-
@sobolevn Great! I am very curious how this looks in cypress. Will the tests be python or javascript code? |
Beta Was this translation helpful? Give feedback.
-
TypeScript 🙂 |
Beta Was this translation helpful? Give feedback.
-
I have some experience with selenium tests. I used following stack:
Regarding cypress. I believe tests should use Python because the whole library is about Python. I know there is a playwright, but I didn't use it. May be it is the best choice. It should be supported well by Microsoft. |
Beta Was this translation helpful? Give feedback.
-
@sobolevn I agree with @maratori. The whole library is about using a complete web-stack from simple python scripts. Also any test infrastructure we come up with should be a reusable. For me it's not enough to test Lona, i have to test Lona based projects too. So a Python based solution would be best, but i don't want to stop you from proposing a typescript alternative 👍 |
Beta Was this translation helpful? Give feedback.
-
Ok, but I guess I cannot help with that 😞
I think that I can showing some existing setups instead, this will take far less time (knowing that there's a low chance of acceptance) 🙂 So, let's have a look at examples that I / internet already have:
describe('My First Test', () => {
it('Gets, types and asserts', () => {
cy.visit('https://example.cypress.io')
cy.contains('type').click()
// Should be on a new URL which includes '/commands/actions'
cy.url().should('include', '/commands/actions')
// Get an input, type into it and verify that the value has been updated
cy.get('.action-email')
.type('[email protected]')
.should('have.value', '[email protected]')
})
})
|
Beta Was this translation helpful? Give feedback.
-
@sobolevn Interesting! Why do you run browser tests in docker containers? |
Beta Was this translation helpful? Give feedback.
-
Because I run almost everything in a docker container 🙂 You can change browsers as easy as:
It requires the whole JVM stack. It has old sync-style API with lots of tricky parts. And it is rather slow. And the last thing about Python's bindings to Selenuim (as far as I know) they are untyped. So, any bugs won't be caught by |
Beta Was this translation helpful? Give feedback.
-
@sobolevn Ah ok!
Good point! Do we have to deal with timing related issues? If i write a test with a button that turns red when clicked, how would frameworks like selenium or cypress know when the Lona client is done rendering before checking the buttons color? Do we have to add some kind of hooks into the javascript client? |
Beta Was this translation helpful? Give feedback.
-
@maratori You recommended selene. Would you use it with or without pytest-selenium? |
Beta Was this translation helpful? Give feedback.
-
I don't know. I guess what happens when you click a button is that some HTTP request is sent to your server. You can |
Beta Was this translation helpful? Give feedback.
-
I used it without pytest-selenium. Selene uses webdriver_manager under the hood to use correct driver for your browser. Also pytest-selenium wasn't useful for me that time. About waits and timeoutsAs far as I understand all modern tools for browser testing (playwright, cypress, selene) use the same approach. Example from selene: browser.all('.srg .g') \
.should(have.size(10)) \ # wait until query returns 10 elements (default 4 seconds)
.first \
.should(have.text('Selenium automates browsers')) # wait until the first element has text (default 4 seconds) Hm... I tried to find something similar in playwright and failed :( |
Beta Was this translation helpful? Give feedback.
-
@maratori: how would this look like in selene? The selene API looks very promising, but it seems to be completely sync. aiohttp testing is async out of the box |
Beta Was this translation helpful? Give feedback.
-
@fscherf You are right, it is completely sync. And it was ok to me, because server didn't run in the same python process with tests. |
Beta Was this translation helpful? Give feedback.
-
@maratori do you mean this library? |
Beta Was this translation helpful? Give feedback.
-
@fscherf Yes |
Beta Was this translation helpful? Give feedback.
-
@maratori That looks very promising! Could you prototype how we would add the playwright dependency to the test-suite so it could run in ci? I had to run |
Beta Was this translation helpful? Give feedback.
-
@fscherf I can, but not very soon. I hope at the end of this week. |
Beta Was this translation helpful? Give feedback.
-
@maratori I will create a pull request out of my proposal and create a simple test based on playwright |
Beta Was this translation helpful? Give feedback.
-
I have setup #75 which contains a first playwright based. Overall i am pretty happy with this tool. I couldn't get pytest-playwright to run properly becaus pytest-aiohttp and pytest-playwright both try to start an ioloop in the main thread. Maybe this can be avoided by let both libraries share one ioloop, but i couldn't find out how. Also playwright is python3.7+. So we can't test 3.6. |
Beta Was this translation helpful? Give feedback.
-
Hm... |
Beta Was this translation helpful? Give feedback.
-
@maratori using |
Beta Was this translation helpful? Give feedback.
-
@fscherf could you, please, share an example how Btw: I created an issue microsoft/playwright-pytest#74 |
Beta Was this translation helpful? Give feedback.
-
@maratori Oh you are right! Running async def test_rendering(page):
await page.goto("https://example.com")
await assert page.inner_text('h1') == 'Example Domain' also raises |
Beta Was this translation helpful? Give feedback.
-
@sobolevn: @maratori and i are now done with the server part of the test-suite and added 2 simple tests based on playwright (#75 ). Is there something we can't do with this approach? Has cypress advantages we miss here? |
Beta Was this translation helpful? Give feedback.
-
@sobolevn Do you still want to propose a cypress based prototype? |
Beta Was this translation helpful? Give feedback.
-
@sobolevn I agree. Then playwright it is! I will merge my pull-request and add some documentation on how to use the new infrastructure. Everything will be available in 1.7.1. Thanks for your time, to both of you! |
Beta Was this translation helpful? Give feedback.
-
At the moment Lona has no browser tests. This means the whole Javascript client stack, which involves rendering and event handling, has no automated testing infrastructure.
I created fscherf/topic/browser-testing which contains a proposal on how to start a Lona app from the pytest infrastructure.
I personally played a little bit with selenium and would try to add selenium testing to this approach.
Beta Was this translation helpful? Give feedback.
All reactions