Selenium tests that rely on pre-existing data, spring boot? - spring

I have a springboot web app that I have finished coding and have some JUnit and Selenium tests. One of the selenium tests relies on a admin being pre-created in the database but obviously when I build the code there is no data in the database so the Selenium test fails.
My website has an admin-dashboard and portal and the test is to login as an admin and perform the admin functionalities but because there is no pre-existing data the selenium test cannot login.
I was thinking about adding creating a new Admin object and saving it to the DB as soon as the user visits the first page (registration page) but that is a rather bad practice to create an admin in a completely different controller to the admin controller?
Thanks

you are taking about end to end testing and you have stage server you simply can add test admin user to stage database and perform your test cases on it if it is fine then go production simply ...

Related

Adding logout timer to spring security application

I created one of the spring application project (a simple login form). where I recently added "logout" functionality. I was wondering how to add a logout timer so the user will be logged out fo inactivity after a certain interval of time. I tried looking resource on stack overflow as well as spring documentation but couldn't find one. Please note that I am using ALL JAVA CONFIGURATION (NO XML bsaed configuration).
So far I have designed a simple login functionality, which works as desired but I am trying refactor the "logout functionality" so user won't have to click on logout functionality all the time. I am attaching link for my codebase, please review it.
project: https://drive.google.com/file/d/1K1yhxsrUWxJe6iaeEL_Pj2HJ9C41vYaT/view?usp=share_link
*Note
while importing my project from DRIVE, you will have to add tomcat server (v9.0) and add the path of the server in the project as well.

Cypress execute non stop first attempt when retry functionality is enable

Our application uses as login method Microsoft Azure OAuth2. As result when the user tries to open the application is redirected Microsoft Azure login page. This redirection caused to me an issue when a test failed and Cypress tries to re-executed. So, when the test failed then Cypress window is reload and lost the information that test executed already once. As result re-execute non stop the first attempt. Please for your help on that.
Cypress is focused in the testing of a single web page on purpose. But in your case it makes sense to trick cypress.
This must solve your issue: Access a new window - cypress.io

Can we run scenarios in sequence using #tag in spring boot cucumber test application. Language used is java

I have one spring boot cucumber based test automation and I want to run scenarios in a specific sequence. Below is my feature file example:
Login.feature
#Login
Scenario: check login
Given user is on login page
When user enter id and password
Then user should be logged in
Admin.feature
#admin
Scenario: check admin panel
Given user is logged in
Then user should see admin panel buttons
By default, it runs in alphabetical order. I want to run in a specific sequence either from cli or using #tag

spring mvc only one user login per browser

I am developing spring MVC application, in my project, i have login page where I can successfully log in, the problem is that if I open new tab and log in with different username it's logging in, means at a time in the same browser I am able to login in multiple users which I don't want ,I want my application to single user login per browser how to make it.
While rendering login page, you check authentication. If you are using Spring security, you can check for principal auth present or not. If auth is present render home page else render login page. I think this can solve your issue neatly.
I suppose that Spring Security session management is what you're looking for:
Spring Security is able to prevent a principal from concurrently
authenticating to the same application more than a specified number of
times. Many ISVs take advantage of this to enforce licensing, whilst
network administrators like this feature because it helps prevent
people from sharing login names. You can, for example, stop user
“Batman” from logging onto the web application from two different
sessions. You can either expire their previous login or you can report
an error when they try to log in again, preventing the second login.
For more information, read the following docs:
http://docs.spring.io/spring-security/site/docs/3.1.x/reference/session-mgmt.html
Control the Session with Spring Security

Is Ehcache force reload possible?

I have two separate web applications to handle a website for customers and other admin application for call center agents. Using the build script I am bundling the same model classes into both web applications.
There is a database for customers where we keep the password. If we change the password from website it should be immediately shown in the admin site. I am not using distributed cache.
Is there a simple way that I can enforce reload from database for a specific flow? So that I can reload from database if I want to get the password property.
If you don`t want using distributed cache, you could remove element from admin cache. Customers application should notify admin application about this event. Possible way to notify is simple rest call.

Resources