Cypress.io PH - Testing API with Cypress - 29 July 2021

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] again you [Music] so [Music] so [Music] sorry anthony you were talking to me because hello yeah uh i'm planning to share the screen first oh okay so i should stop check sharing yeah okay no problem [Music] okay sorry about that no problem well i'll just uh introduce um about the group and then i'll call you once we are ready to start with the presentation all right [Music] [Music] hello guys nice meeting you [Music] hey [Music] so [Music] okay [Music] [Music] [Music] uh [Music] [Music] [Music] okay hello everyone so good evening well welcome to our um cypress i i o user group philippines so this is our very first meet up at the end we're actually very fortunate to have philly so before we start i'll just uh wanted to have some coffee on slides to present so again this is uh to remind everyone that this session is uh recorded and will be available in um in the youtube link that we have and as i mentioned we are available in youtube and we'll be using slido for our q a so i'll message this whole thing to our chat after this and we are also in um social media page facebook uh for those who wanted to continue um advancing their knowledge in science so we have cypress uh or the ioph um so for those who don't know so we we started this group um we we done with mot um study group so for two months we've been studying um cypress and then uh we decided to continue so by putting up this community uh in manila foreign okay so i'm your host so i'm anthony so i'm for those who don't know me i'm i'm actually uh the ones um working with a mini chef testing made of philippines so and of course we have jenny so jenny is our co-organizer so you will probably see johnny uh on a few months not to be the whole specific as well so it's currently working on the back end in terms of our youtube channel and slider as well so thanks channing and yeah so i think without further ado so i'd like to call creatively and i actually just filled it with um that's automation university uh course as well and very much laughing to have uh build it to be our first speaker so we are actually making history for uh cypress i o user group williams so believe thank you very much and uh thanks for inviting me to this lovely meetup and thanks again for yeah for the invitation so hope i hope that uh i'll be able to kick things off nicely for you uh so let me let me share my screen and because i do have a presentation that i'm going to be sharing with you and of course i do have a couple of examples uh i'll be doing some live coding today and showing you how you can actually use cypress for testing different things and for maybe even testing your apis uh or not maybe most certainly because that's the topic of uh of today uh all right you can see the name of the presentation and you should be able to see the qr code uh that is on the screen feel free to take out your phone and scan that as anthony already mentioned we are going to be using slido uh so either scan the code and you'll be directed directly to the event where you can post any questions you might have uh or you can go to slido.com and enter this code in the top right corner cypressph you should be able to get in and ask me anything you like uh and i am also going to be asking you some questions so have those songs ready uh alright so let's see uh first let me shortly introduce myself so my name is philip and my background is actually kind of maybe interesting i started psychology so i'm not in the tech uh background uh but uh i came into tech like five six years ago something like that and i have been uh working as a qa lead and test automation engineer uh at slido so we are going to actually be using slido today and that's that's the company i'm working for and where i do most of my testing i'm also cyprus ambassador uh so if uh if you are ever eager to find some cypress content uh feel free to follow me on phillybridge.com that's my personal page where i write cyprus tips every week well almost every week because i was on a little break for a couple of weeks i got a little tired so i so i decided okay i'm not going to write for uh for a while but i will be coming back and writing those cyprus tips weekly besides that i do workshops presentations like this webinars courses i do streaming from time to time and i do have a youtube channel and all can be found in on the on my page so phillybraids.com uh make sure to check it out uh all right as it was already mentioned uh there is a course that i made recently on test automation university as everything on test automation university it is free so if you are already familiar with cypress you have been working with it uh you can check out this advanced cypress course where i discuss some of the more advanced topic of course not too advanced but if you are already using cypress i think you will really enjoy that so feel free to check it out uh test automation university and uh and uh all right yeah so if you are in slido hopefully you are already if you're not there are still that qr code you can scan that or go to slider.com and enter the cypress ph event code i do have a question for you since i'll be talking today and you may be asking i'm still a little curious about you folks uh what's your job title are you a q or something like that manual qa developer lead as that uh sdet all right feel free to input i'll give you some give you some time manual qa full stock software engineer do we got any designers or product managers or ceos over here let's let's see you can actually start typing and if the if the answer has already been submitted you can just tap on that and it will be added to the others uh and it seems the manual qa that's that's the area which is represented the most in this crowd we got eight volts not sure how many people are currently attending uh maybe anthony has a great uh better insight into that uh right now on the chat with that uh right now on the chat we have on on the silvia 43 disappointing three nice all right i see youtube and uh which has other audiences okay i see people submitting uh answers to the zoom chat uh it is kind of out of my uh focus out of sight so if you do have a question or you want to submit an answer please use slido for that i will be checking that out and of course i will be answering the questions and that you might have at the end of the talk so so go to slido and and we can discuss over there uh oh thanks for for sharing the link that might speed things up uh all right i do have another question for you and that is where it is how much experience do you have with cyprus so like one star being you have little to no experience you're just a rookie in this area and 10 being that you have a lot of experience and you consider yourself a pro feel free to submit all right we got 13 votes 14 votes nice i think we had around that number also for the previous ball okay someone changed their mind about about number 10. uh all right so we got this distributed mostly on the left side so we got more people beginning started starting with cyprus and i do think that you will enjoy this today if you are just starting but also folks that are more in the middle or on the right side i think hopefully you will learn something new today uh all right so let me go over uh to the next slide and uh and again if you have any question feel free to post them in slido oh and by the way here in slido we are hiring we do have a couple of positions opened so if you're interested in in the product you're just using if you find it fun uh feel free to apply and we'll then maybe we'll meet on the uh in the interview so uh see over there we are remote friendly so wherever you are you can apply all right so a little introduction so some of you know cyber some of you don't just shortly what is cypress it is a tool for testing anything that runs in a browser it is built completely from groudon ground up it doesn't use selenium in the background and it runs inside the browser that means that tests can either be written in javascript or they can be written in typescript which of course gets compiled to javascript so the browser can read that this architecture of cypress enables us to have some great debugging tools you can of course use chrome devtools which are awesome if you're working with them you already know that and cyprus is uh open source so whatever is missing in cyprus it still can be added uh by the community so uh so there's that so just a short introduction of what cyprus is and the most question that gets asked the most is okay we know we know it is not built on selenium so how is it different uh from selenium and i borrowed a couple of slides from gleb bamuto former uh engineer and and in cyprus uh where he explained in in in detail how uh how it is different so if you're using selenium you have your test code uh which then is used through selenium to call the driver and call actions in the browser so you are using http request to communicate with the browser to do certain actions with cypress you have your browser and inside that browser you have two iframes and inside first iframe you have your tests and inside the second iframe you have your application what this enables you to do is that you have direct ex access to the application and there are some and this has some advantages some disadvantages but general architecture or general principles of how these two tools operate are something like this so all right let's let's get to the topic right uh so how how can you use cyprus for testing api there are a couple of ways we can we can use cypress for testing apis uh so um in in every scenario when we want to test api we do have some application that is using uh the api so we can either directly like skip the ui or the front end altogether and just start testing api and we want to try test out the response that comes from the server this is something cyprus enables you to to do also what we can do we can open our application we can see the api calls being called and we can test those so we can look into how the api calls are sent and we can look directly into them i'm going to show you that in a minute and moreover we can do even more we can stop the api's response status we can even stop response headers and payloads or even the thing that is sent over to the to the server and we can do some dynamic respawn stubbing and this is everything that i'm going to show you uh today so let's get to the demo so let me first show you an application we are going to be testing uh i have this trello application it's a it's a clone application of the original trello app it is currently running over here on localhost 3000 on my computer and it's a simple app you can create some boards save them and inside the boards we got some lists we got some tasks and i'm writing just nonsense just to show you how that works and we can check it off or check we have some detail we can delete the task something like that uh when i look into the dev tools let me make these bigger for you so you can see them and i look into the network panel you can see that whenever i for example create a new board there is an api call right so if i look into the details of that api call i can see the url so it is localhost 3000 api boards it has a post method we got some headers and stuff and i also have like the payload that i'm saying sending so i created the name with a couple of a's in them and i can also look in to the preview of the response right uh when i look over here and i want to test an api i can go into a postman and basically replicate the same action that happened when i was working with my front end so instead of clicking typing and clicking save i can call the api directly right and i can call the same url so here's my postman and i'm sending the http 3000 api boards i'm using the post method here is the url and here is the uh the json or the payload that i'm sending to the server so when i now send this request with the name of hello manila i can see the board appearing over here and here it is right so i did it exact same thing only i skipped the ui altogether and just called an http request so this is something we can actually do in cyprus and if you have ever used postman you know how powerful it is that you can write all kinds of tests for these respawns etc and we can do exactly that in cyprus and it's really easy to do so let me open my cypress project i have my application running here and i do have two tests uh so let's let's look into the into the first one so here it is it only and i'm just going to fine skip this all together let's run my test oops it's on the different screen just a sec all right and you can see that inside my inside my application i am i've been i'm opening my request and there's something strange happening so hopefully that will not interfere oh oh i opened the wrong test sorry test start this is what we want to look into all right so let me demonstrate uh just a sec i'll try to make this a little bigger for you to see all right okay on the left side i have my vs code and i have my uh test over here i have couple of tests inside cypress so if you're not familiar with cypress it uses this syntax borrowed from mocha where you have an it function and basically it function equals a test inside uh inside cyprus so i have one two three four five six tests in this in this file and if i do something like this i write it dot only that means that cyprus is just going to run this test this single test and what i do have here is just a single command it has a visit command so i'm visiting the just uh just a base url just the url that was set up in cyprus json so that is localhost 3000 so what this does it will open my application and you can see it over here is it is the trello application and what i see here is a list of my boards um all right so let's let's try to do the same thing we were looking at inside postman so how to do a request in cyprus uh it's actually really easy and intuitive i do cy that's request and i can see that this is uh this is a function which can take a couple of options and those options will be so method so i know i want to send a post request i can define the url and when i create a new board that url is api boards and when i want to define the body i just type body and define it so i know that my boards have a name and that attribute will basically be the name of the board so let's call it hello world so now when i save my test it will automatically get re-run and i can see that it has visited my app it has fired the request and you can see that the hello world board is over here right so we did some automation but we're still not testing anything so let's try and see and uh looking to look into writing a test so let's actually write an assertion let's look into what this request has uh what kind of response it had and let's look into how we can test that so as i mentioned since we are in a browser we can definitely use chrome devtools but cypress already has some functionality for us so when i open my dev tools and look inside the console let me put it down below so it's it's not that messy and whenever i click on a command or any line in this test runner i get i get a nice uh little log into my console so i can look into the request i can look into the command and i can look into everything it has every kind of information it has so i can look into what the command has healed it and this is something i can work with so i can look into the body headers etc etc so let me let me test uh the body let me look into the response and let's see if the response that i wanted to have right so for check the the yeah i can check the body and i can also check the status so let's let's start with status because that's the like the most easy thing to do so how do i do that uh cyprus operates uh using this command chains so whenever i want to use the information that re this request command has returned that would be this whole yield it object object i can use command called then and i will use an alias board and create a function and inside this function i can test this board uh parameter so let's look into expect let's write an assertion and i will explain what i just did so board status and i want to make sure that it equals 201 because that's the status that i want to have from from this request so what i did over here i looked into this object that the this request command has yielded and the object is actually body duration headers and status of this request so when i want to write an assertion i'll write expect board status to equal to a one so i'm checking this thing over here so when i now save my test it gets reran and i can see that beside the request command i also have an assertion so let's go let's go even further let's again look into what's inside here and let's check something with the with the body right let's check for example we have an attribute start that is set to false and whenever i create a new board in my application a new item i want the start attribute to be false so if my server would response or respond with true that would mean that we have a bug and we need to fix that so just so you know what start actually means when i have this trello board over here there's there are these stars and i can basically favorite any board that i have in in the list so that's the functionality of the app so when i click that it is over here i can see that there are here are my start boards and i have some boards that are on start uh all right so let's let's check the api let's check if the response is correct so again i will continue writing my function and i i'll be writing expect board body because we are looking into the body and we want to check the attribute that is called start and we want to make sure that it is false to be false like this so now when i save my test i rerun it and i can see that i'm checking the status 201 it's good and i'm expecting the start to be false all right so let's check one more thing and then we'll move on to the next example and let's check whether the id is a number so we got different types over here we got string we got a number we got boolean so true or false so let's make sure that this id is always a number because if one day we decided or our backend developers decided that there should be a string and we change every id to uid that may maybe actually break our application so let's make sure it doesn't happen with a with a nice test and i'm going to use another type of assertion which is assert and this is bundled inside the cypress and i will check if it is a number so i want the board body id i want to make sure that it is of the correct type so this expect and assert functions these are bundled within cyprus and you can you can use them inside the then function so this is the way you can actually test your apis so let me save that and my test is complete right so i checked whether every time i get a response from that request that it is 2 1 star default false and the body id is a number and actually i don't even need to do this visit over here i'm opening the app every time so you can see that there are these boards appearing so you can see hello world hello and hello world we have done this multiple times but i don't actually have to do that right i can do a test like this and now i'm only testing my api i'm not even opening the front end and i've used cypress now just for testing api all right so let's let's move on to another example so you can clearly test apis with cyprus and we have done that right now by by directly calling our server and by the way when i say server i do have an application and i will make this repository available to you and it has everything bundled in it has the cypress project and also the trello application the installation is super easy you go just npm install and then npm start and i have already done that the application is running over here in the um in my terminal so i typed npm start and my application is running but you might be curious about the database and the database this application is super super easy here inside the trello app folder and the database is just a simple json file so if you look closely inside here you can see that there are these are the name of the boards we have created right so the uh if i would put more understandable names in there that might be a little clearer hello world hello world etc etc so whenever i create something i do the http request it actually is going to create a new item in this in this list so let me just run this test again so another http request gets called and you can see that it has added it to the to the list um all right so let's go back to the test and let's now do something a little different that we than what we did in the beginning so we did just request and we tested that but what if we want to make sure that our application is actually behaving in the right way so let's let's do something else let's match our requests let's see what the application is doing so i have a very simple test over here i open my application i select the create board item i click on that and i type in new board and hit enter and what that does is it opens my newly created board and i i'm inside so just a simple action um for those of you who have not been using cypress cypress has this amazing capability so this test runner over here on the left side can actually take you back in time and you can look into the state of your application during every step of the way so when i hover over here you can see that i'm getting my element it actually gets highlighted i can see that i'm clicking it and it's being covered by by this overlay but i can see the state before the click and after the click here it is and i can also look into the state of the typing right so i can look into the before and after so before i started typing i could see this input and after i typed the new board and enter it actually redirected me in um so besides this i can see uh all of the http requests that are being fired whenever i'm interacting interacting with my application so at this exact moment when i write new board and hit enter i can see that there's a post request to the api boards and we have seen that already right we have been creating boards through the http requests right now and what i can do with cypress is actually use intercept command to uh to basically watch that request as it happens so how do i do that i'm going to write a new command here intercept and for the basic usage it has a very similar syntax as as the request so i need to define a method so that would be post and i need to define the url and that would be api boards right we can see it over here so this is the api boards uh when i now save this and execute my action i can see that there's another item over here in my desk and it is called roots so it is a list of all the all the i'm sorry anthony are you trying to say something okay so should i continue yeah yeah okay okay sorry i i thought you were talking to me all right so let me continue right so i can in this root section i can see a list of all of the http requests that i'm trying to watch and try to see uh and there and you can see what i have matched i have matched a post request with this url it is not stopped we'll get into that in a minute it has no alias but during our test it was called a single time right so it happened right over here right after we hit enter on that uh create uh creating new board so let's let's give it an alias so we can uh see it better in our test so i'm going to type alias and let's call this a board create because that is essentially what we are doing here so when i now save my test i can see the request being highlighted over here and up here in the root section i can see that it has our alias so what do we do now right uh we are watching it it is highlighted but we're not testing anything right so let's test something let's let's actually work with this matched request so to do that we can type weight and we are going to be waiting for this board create to happen so when i save it now i can see that i have this weight command over here and i can see that cyprus has waited for this http request to happen and also to give me a response so when i now click on this and open my console i can see the details of what this weight command has actually returned again i'll look into the yield it section and i see that there's an object and inside this object i can see all of the different attributes it has so we got requests respawns state etc etc so let's let's look into that let's let's try to write a test in a similar fashion we did with our request command so again i will be using uh then command again i'll use a function so let's have an alias and this can be anything it doesn't have to be bored but it just makes sense during this test and i'll write another expect and what do i want to test let's uh let's test uh response okay let's test the response and we'll look into the status code so response status code so we want to expect that the board oh where's my cursor uh okay okay i got it board um respawns status code is equal to 201 right so again i save my test and here i have it so i i'm not only testing uh the request that i have made like as i did in the first example but i'm testing a request that my application is doing and whether it is getting the right response but also and i think that this might be the most important part i can actually check the request so say for example our application has just um been completely rewritten from ground up we migrated from angular to view or something and we want we want to make sure that our application behavior is still the same that it is sending the proper data towards the server so we can actually check not only the response but we want we can check the request so let's let's check the let's check the request i'm going to write another expect function and i'm going to write board uh requests no not response request and i want to make sure that when i type this new board um the name of the board that it actually gets sent with no extra white spaces or line breaks or something like that so when i type this new board inside that input field it stays the same so let's type in the body name right and we want it to to equal and it would be a new board in a real world scenario i probably use a variable for that but hopefully yeah hopefully you don't mind the repetition so bam and i have my test right so let's let's look into what i just did i waited for the board created http request and inside i have my request information and i wanted to make sure that the name that the request body name actually is equal to new board so i'm checking whether that that text is correctly correctly sent to the server as i um as i enter it inside this input into in the application uh all right so we have been testing our requests we have been testing requests that our application is making so let's let's do something else because intercept is actually really powerful and it has some great capabilities uh we can actually as the name of the test suggests uh suggests we can change the response body so intercept command actually can uh can take two arguments and those can be two objects so the first object we got over here and inside the object we got method uh and the url so these are the attributes used to match a certain request but if we add another object we can actually define what we want to do with that matched request and we can do really powerful things so as you can see every time since i started this example i have added a new board either named hello world or new board but let's say for example we want to test our application and see how the empty state looks we can either go ahead and delete all of the boards or we can do the following we can define the body and say it is an empty array so when i save that you can see i'm opening my application with an empty array and why is that an empty array so let me back up a little and put this back it is an empty array because the first thing our application does when it is opened when i type that visit and open the localhost 3000 the first thing that happens after the visit is that the application itself is going to do is going to fire an http request to a url that is that is over here let me the url is localhost api boards and the method is get so what our application is saying to the server okay get me list of all of the boards that you have inside the database and it will do so it will return a json file and cypress cyprus no the application is going to take that that data and it is going to render that as this nice list of all of the boards uh what i'm doing in cyprus essentially is saying okay you're not going to render the real data that comes from server instead uh this is the data that you re that you got from server so so instead of the list of the boards you get an empty array because normally the what you get from server is an array of objects and every object has an attributes and application when it gets that response it knows what to do with those and uh what i'm doing here essentially is that i'm substituting uh the real response with my own response so the body would be an empty array so when i save that i'm actually stubbing the respawns and i can see that it is now empty so instead of the real response i get my own mind that when i look into the data json or when i look into the database i can actually see that the boards are still here they haven't gone anywhere so i have cut off the real response and given it my own and this is quite cool if you want to test for different edge cases say for example you want to change the respawn status and why would you want to do that right so for example let's say you have a scenario where a server gets a 403 error or 500 or something like that and when that happens you want to give your user some kind of uh good uh response some kind of good error message so that they can understand what is happening so let me move on to the next test and i still have the same set of actions so i'm creating a board i type new board hit enter again what i'm going to do i'm going to do my own response so instead of the real response which would be 201 and it would create a board and it would give the server would give me back my real data let's do let's do an error so we're going to force network error this is what cyprus enables us to do and i'm going to type true so this actually simulates what happens if the request is actually being fired but we're not getting any response whatsoever so when that happens i want the user to see a certain error so now when i save my test uh i'm not seeing the error and that is because i have way too many boards in in the list and the application is not uh not perfect let me run that again and you can see that i have essentially created an edge case scenario where there would be an error on the server and and my response would my request would not get a release response so what this enables me to do is that i can actually look into the uh status and i can write a test for that error message to be visible right so if i want to have my test complete i'll type get [Music] error message which is a selector for the error message and i want it to be visible so let's write should be visible and when i now save my test without really touching the server at all i'm testing just my front end and i'm testing whether that error message is actually there and is there when user actually needs the needs it or is needs the information rather because user actually needs the server to be running and application to be functioning all right so we are a little short on time so let me just go through these two examples really quickly and uh there's another thing i wanted to show you and that is changing the response body dynamically so what that actually is as i said intercept can take two arguments this can be two objects so the first one is matching the the url and the second one is basically defining what to do with the response of that match matched request but not only it can take uh object it can actually take a function so we can just pick whatever we want and just change a part of data so let's say we got a couple of boards over here and none of them are start and every board is the same name so let's say for example we want to change just the name of the first board and just for the sake of this test we can absolutely do that so instead of passing an object i'm going to pass a function and i'm going to give that an argument so that would be a request and we want to change the reply or the response body dynamically so what i'm going to do and if i have my notes correctly it will work i'm going to use that reply function and and change the respawns so i want to change the response body name and let's change the name to hello manila and i will return that response body oops response body i think i accidentally yeah good all right so what i did over here just to give you a brief explanation i passed a function that is that has a different different kinds of functions and attributes inside it and i used a reply function that is inside this function so uh what i did i took the response body and just took the first item inside the response body which would be this one and change the name so when i now save my test i can see that the name of the first board is changed so i took the real response from the server so that real response actually came came to me but just changed a part of that and this might uh this is maybe not the best example of this but for example let's say you want to test an expiring subscription so if you have ever tested subscription that is maybe ending uh next year or something like that uh you can actually just take a real subscription that is live today uh take the uh http request that is actually giving the information about the current subscription subscription in your app and just change the date and you can see your front end and test it whether it behaves as it should hopefully that was uh that was understandable uh all right and for the last example um or maybe we should we got 10 minutes so maybe we should go to the to the q a but uh basically what i wanted to give you over here let me just let me just copy this because i okay are just real quick i do have a login capability over here i do have sign up so let me go philip example.com let's do some kind of password doesn't really matter and when i sign up i can see that i am logged in and whenever i'm logged in and create a new board that board is going to be private so let me before i do that let me actually reset all of the boards and i'm going to call create a private board and and yeah so i am logged in and to to tell the application that i am logged in i have this token in my cookies it's a super super long token and that is basically my authorization if i log out i'll basically delete that token and i can see that oops and i can see that i am now logged out and i cannot see my private board if i were to log in log back in or enter that cookie back so let me set cookie and that would be trello token and set the name of that cookie i can see the private board appearing again but instead of using this cookie and pasting them inside what i can do is i can intercept all of the http requests that are being fired and i can set the set the authorization inside the headers so if you have a basic type of authorization and you send the authorization cookie in the in the header as many of the applications do uh you can actually skip login altogether and just uh amend that authorization cookie inside every header of every http request that is being done in the in the application so to do that you would do something like this you would just use a function uh take all the headers from there and take headers uh authorization [Music] um miss typing everything [Music] nation and say that bearer is this and when i now save my test although cyprus normally logs out and clears out all the cookies before every test you can see that i can see my private board and my application is basically behaving as if i was logged in and why is that it is because inside every http request that is going to be fired ever during my test i'm actually adding this authorization header so it seems to the application as if i'm authorized uh that was fairly quick this two to last example so if you if you ever feel like you're confused by this uh feel free to reach out to me uh whether that would be on my page or or on the discord server that i'm usually hanging out i'd be happy to meet you and and talk to you and answer any of the questions you might have but let's jump into the q a and i see that there are a lot of questions so let's uh let's uh let's look into the into them all right so the first question is anonymous uh so can you combine api testing with ui testing and what is the benefit yes you can actually do that and this was actually my attempt of of demonstrating how that is beneficial so um so it it also depends like on the on how the how big is the application and what's the goal of your testing you can definitely combine api and ui testing and it could be absolutely beneficial so for example if you want to check whether your application is getting the right data it can definitely show you some some of the blind spots so there's a change on api which was not reflected on front end but if you're using your end-to-end tests and make sure that that you check whether the respawns whether you're getting the number where you should be getting a number or you're getting a string where you should be getting a string that can definitely definitely be beneficial so i would recommend to do that since you didn't start in tech what was the first automation framework you learned i have been actually playing with selenium ide and during my beginnings i got a little confused by that and i was uh and i was very lucky to find cyprus in its early beta stages i tried it out and basically have been using it ever since since slido is mostly a web application it has fitted within the within the flow perfectly so that was the first thing i learned and that is what i'm working with uh daily um how do you approach seeding data in api testing with cypress um seedling data in api testing uh all right so there are uh data into your database uh in the cypress documentation which i have not mentioned today but i should have because it is an awesome documentation and there are actually different recipes for for seeding your database and i would also recommend checking out the cypress real world application which which uses seeding a lot so hopefully those example can give you a good clue of how to how to do that uh all right how do you debug unit tests in cyprus i'm not really using uh i'm cyprus to write unit tests uh so i'm not really able to answer that question sorry for that um but cyprus is mostly used for testing the ui so i'm not sure how big of an application is using cyprus for writing unit tests all right so the next question is how can i test apis with cyprus when the link of the web app is static and only pop-ups change and data only pop-up's changing uh well that's that's kind of hard to hard to answer because uh in order to give you a good answer i would probably have to have more knowledge about about the application if the app is static and it's and it's only pop-ups and change of data then my question would be what what is there to test what would you like to test and that could definitely give some guidance on what on how to decide on what to test and how to test that and you can definitely change data because um although your application itself doesn't change a lot at all it actually it can actually behave differently with different types of data so for example a sign up page would be a great example for that right so if you have uh if you input a weak password it would behave differently than it would behave when you got a strong password so the data can definitely have effect on the front end and that might give you some guidance on how to test that but again not knowing the application that's kind of hard to hard to answer uh all right so how to use bdd with cyprus uh if by bdd you're referring to like a gherkin syntax and cucumber and these kinds of things there is a plugin which is basically a preprocessor so you can write your test definition files and use cucumber or the gherkin syntax to write your tests i'm not a giant fan of that but you can definitely do that there is a fairly good plugin for that i have been testing it out it's yeah i mean it's kind of fun but uh but yeah i'm not not a huge fan but uh check out the cucumber pre-processor for cyprus that would be that would be the way to go with uh bdd with cyprus why would you use cypress for api when it's simple enough to export collection to boltzmann and run it in newman and can do the same for ci cd uh if if this is what you can do if you're familiar with that if that's like more more comfortable way for you then go ahead and do that don't don't go with cypress if that's like not not the best experience for you uh it's completely okay i mean uh if you are if the most of majority of your day is writing ui tests and you're using cyprus for that and then you get a task to write a couple of end-to-end tests a couple of api tests then using cyprus can definitely feel easier for you but if you are working with multiple tools and you're using new man and postman that's totally fine you can go go ahead with that also cypress opens browser when you're you are testing anything so that means you have to keep that in mind so if you want to just write api tests so you want to write thousands of api tests not sure if cyprus would be the number one choice for for this task i think cyprus really shines for the for the ui test and the integration and end-to-end that's that's where its power is um but you can use it for api too that's what i was trying to demonstrate one is uh best to use expect versus assert and vice versa not sure if those are like one is better and other is worse and and if there would be um would be like situations where you would absolutely need to prefer one over the other uh i use those because the assertion of types is kind of easier for me to understand using assert but for everything else i use expect i suggest digging through the documentation looking and playing with that and uh yeah like those uh the the all those chai assertions that are bundled within cyprus i can i think they can give you quite a good um capabilities for testing so uh i mean choose whatever you want would be my advice are you familiar with react testing with cyprus so we do have some some applications in slido that are written in react and for me as someone who writes end-to-end tests it doesn't really matter all that much whether the application is written in react or angular or something like that it starts to matter when i want to do like more advanced stuff when i want to look inside the storage when i want to but like from the high high level point of view when you're just trying to write a scenario and automate it and make sure it works uh it it doesn't really matter much quite familiar i don't think like that's that's like a key thing in all of that uh cyprus dashboard what is the advantage i i am using cypress dashboard i think it's awesome because it gives you some great analytics and um and yeah you can look on your tests during time you can discover which tests are flaky you can see the number of your tests growing most common failures and those are really really valuable information that you can that can give you great insight into okay i need to stabilize this test okay this error happens way too often what what do we do about that and that's that's really really good and that would be like the biggest advantage for me is there any repositories such as github for or anything for your demo so maybe i can try yeah check out my github i will be i actually wanted to have this exact repo that i was working on today ready for the talk uh something broke it is there there is a repo called cyprus manila uh uh meetup but it's empty so let me fix that and i will make sure that it is a available today uh so you can try it all but i also have the trello app which is super simple to install i have tons of explanations and stuff like that on my blog so yeah definitely go ahead and try try that when will you do a workshop in english oh thank you for that question i will do a workshop in english but i'm not sure when i wanted to i wanted to do it so bad in like september october but my september and october look so crazy right now that i'm not sure i will be able to do that but i definitely definitely want to do a workshop in english i i do one in slovak language for like the local community it has been getting great responses so i i'd be super happy to bring it to the world and i am working on that it is just much slower that i that i want it and but i will will do that and i will let you know if you follow me on on social networks i will i'll start shouting to the world once that's that's ready so so you will not miss it and thank you that is so nice that you're interested in that anthony how are we with the time i think we kind of passed it already right so that's why uh if you wanted to get picked up we could pick one question just just one big one question so i i would maybe give you like you know five seconds to upload the one one that you want and i can i can answer that uh but okay let's let's pick one i think that's that's not fair to like give you just five seconds let me pick one um okay someone has uploaded a question uh i can i can answer this one how would you test sorting with cyprus because it's an easy answer i do have a blog about that so if you go to philipprietz.com uh you can see uh search for lists and i have a blog on testing lists with cyprus and that is actually about testing sorting and and stuff like that uh so oh yeah you'll you'll find an answer there and i have mentioned that a couple of times today so philippines.com that is my blog and there are some slash urls that you can check out so you can easily get to my youtube channel get to the discord where we can chat i'm trying to be there for you and you can follow me on twitter linkedin and twitch and also github so that's uh that's me and i hope we can stay in touch and chat about cyprus and everything i think that's that's well that's it i think thank you so much uh philippe for your i mean um sharing your information i know it's your other side of the world right now and thank you for uh being our first speaker for our um cypress i always ready to see you well soon and there will be still be uh i mean i'm hoping we could also um [Music] help our community grow uh with your with your blogs and your in your workshop so i'll make sure that i will be posting your um your workshops and blogs probably in in our facebook page thanks so much for inviting me it uh it was a great fun uh with you and yeah we'll see you around see you around good luck with the community yeah thank you so much and i apologize but i think this is a very interactive discussion for everyone so thank you and thanks again johnny okay bye everyone okay bye thank you [Music] you
Info
Channel: Johnny Estilles
Views: 838
Rating: undefined out of 5
Keywords:
Id: rzucGAJF1no
Channel Id: undefined
Length: 79min 46sec (4786 seconds)
Published: Thu Jul 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.