Hello, I'm trying to use cypress to test my flask...
# e2e-testing
a
Hello, I'm trying to use cypress to test my flask application and encountering unexpected session persistence issue. Anyone would like to check for reason and try to help me? What do I do: 1. goto https://lubomir.mlich.cz/flasktest/ 2. login link is displayed as I'm not logged in. I'll get my session created by clicking on it. 3. create project form is displayed, I enter project name and submit form 4. Project added successfully message is displayed This works well in browser manually. But step 4. is not working with cypress and I can see resulting page which says that session is invalid instead. Is it possibly some cypress-cookie persistence issue?
cypress test code:
Copy code
describe('Basic tests', () => {
    it('We can get to the page and see there is login link', () => {
        cy.visit('/')
        cy.contains('login')
    }),
    it('We will use test login to login user1', () => {
        cy.visit('/login-test/user1@test.cz')
        cy.contains('destroy session')
    }),
    it('We can create project', () => {
        cy.get('input[placeholder="Enter new project name"]').type('ProjectNo1')       
        describe('Basic tests', () => {
    it('We can get to the page and see there is login link', () => {
        cy.visit('/')
        cy.contains('login')
    }),
    it('We will use test login to login user1', () => {
        cy.visit('/login-test/user1@test.cz')
        cy.contains('destroy session')
    }),
    it('We can create project', () => {
        cy.get('input[placeholder="Enter new project name"]').type('ProjectNo1')       
        cy.get('input[value="Create"]').click()
        cy.contains('Project added successfuly')
   
    })
})
flask app.py:
Copy code
from flask import Flask, url_for, session, render_template, redirect, request, url_for, flash

app = Flask(__name__)
app.secret_key = '**'

@app.route('/')
def homepage():
    user = session.get('user')
    return render_template('home.html', user=user)

@app.route('/login-test/<string:email_address>')
def logintest(email_address):
    userid = 1
    user = { "email" : email_address, "uid" : userid }
    session['user'] = user
    return redirect('/flasktest')

@app.route('/logout')
def logout():
    session.pop('user', None)
    return redirect('/flasktest')

@app.route('/create-project/', methods=['POST'])
def createproject():
    user = session.get('user')
    if (user):
        flash("Project added successfully")        
        return redirect('/flasktest')
    else:
        flash("Session not found")
        return redirect('/flasktest')
flask homepage template:
Copy code
{% with messages = get_flashed_messages() %}
    {% if messages %}
        <ul class=flashes>
        {% for message in messages %}
            <li>{{ message }}</li>
        {% endfor %}
        </ul>
    {% endif %}
{% endwith %}

{% if user %}
<form action="create-project/" method="POST">
    <input type="text" name="name" placeholder="Enter new project name">
    <input type="submit" value="Create">
</form>
<a href='logout'>destroy session</a>
{% else %}
<a href='login-test/test@test.cz'>login</a>
{% endif %}
4 Views