Transcript#
This transcript was generated automatically and may contain errors.
And I'm also joined by our featured lab manager today, Barret Schloerke, from Posit as well. Barret, would you like to say hello? Hello. Hi, everyone. It's been a long time, like almost a week. Ha ha. It's been a week.
Barret joined us last week to talk about testing Shiny for R, and he's back for the end of Testober. Testober was Barret's whole idea, which we love. He inspired this to talk about testing in Shiny for Python. And just like last week, this is not a, we're going to take you from zero to 60, and you're going to become an expert in this thing. We are going to give you a taste of what Shiny for Python looks like. We are going to give you a taste of what testing can look like as a concept inside Shiny for Python. And you have the chance to ask all kinds of questions.
Barret, I would love it if you could go ahead and share your screen and take it away. And I am very excited to just get a glimpse at first of like what Shiny for Python looks like, because I have built precisely one Shiny for Python app. That is a good amount. Hopefully we can double that today. Hey, let's do it.
Polling the audience
All right. Before we do that, I would love to ask some quick polls in Discord. One, have you used, written, done anything with Shiny before, familiar with? I just, you know, trying to make sure the terms and things that I talk about today are appropriate.
We have some votes happening. Things are shifting. We have about 15 people in and about 80% yes. I'm betting that a lot of this I have used Shiny before is Shiny for R. So, we'll see. That's okay. The concepts all transfer.
And then the other one that I have for today is have you used Playwright before? Oh, so much more specific. Your girl's a no. I'm seeing lots and lots of no's. Okay. We are about the same amount of votes, 20 in, and seeing about 90% no. Oh, I see a couple of maybes. Maybe. Maybe I've used Playwright. I sure like the word Playwright. Playwright, Cypress. Like, there's a bunch of different similar testing frameworks, but they're a very different approach than what we do on the R side.
This is great. Awesome. This is great. We'll get to it. But to me, Playwright was like discovering one of those new things of sliced bread, kind of like when R got the pipe operator. It's like, oh, boy, this is going to change what I do. Connor says Claude has used Playwright for me. That counts. That works. Yeah. We'll get into some of the reasons why Claude probably picked it. I think it's a great program.
Introduction and Shiny for Python overview
All right. So let's dive into this. All right. More officially, hi. I'm Barret Schloerke. I am a Shiny software engineer. I've been on the Shiny team since 2018. I think that's like three technical lifetimes now. And I love it. And my days are always different.
And just for context, I will be asking any and all dumb questions that come to my mind. So if you have a question that you think is dumb, don't think it's dumb. Just ask it. And we'll get it into Barret. Yeah. No questions are dumb questions. Absolutely. You only think they are.
So this is Shiny for Python. And I want to think of it as express mode. I love express mode in Shiny for Python because it removes some of the coupling that's required in R Shiny. And instead now in PyShiny, when you have a renderer, in this case, it's not we didn't have to say something like UI.output. It's not going to show up. But it will be something like output code. And then if we had this as render code instead. And then we would do something like my this would be what the ID of output value. Yeah. And then here it would say output value.
So this would be very much closer to regular oh, I have the core code. There. Okay. So in core mode, very similar to R, we would have a app that's just over here. And it will show a checkbox. And it will say some ID, a title, and your default value. And then it'll have a single output value. In this case, some UI, which happens just to be text. We can say code just to have it print a little bit differently. Code and I could change this to code because I like code better.
And if I run this app, sometimes my apps take a little time to load too many things. We'll see if we've lit enough candles in the chat for everything to work. There we go. There we go. Yeah. And so if I check the value, it'll be like, oh, it's true. It's false. It's true. It's false. True. It's false. So this is a great app because there's just a single input. We declare the output. And then inside our server, we have how we're going to handle some of this reactivity.
And Shiny is awesome in that, you know, as you're all aware. They'll only recalculate the necessary outputs. And so if you have some calculations that don't need to be performed yet, they won't be. And then as you only make some updates to your inputs, only the affected outputs will be re-rendered. And I find this mental model to be very appealing because it doesn't just blast and rerun over and over and over. If you've done UI framework development with React, it's a very different concept where React loves to go so often. And with Shiny, it's very surgical in what is performed.
Okay. So moving on. So in express mode, we can get rid of that matching output value item because we just go, oh, this is being printed. You probably want to print it here. So now your code looks very similar. Anyways.
So back to testing. Oh, how do we know when to reach for core or express? Should I just start with express generally? Absolutely. Personally, if you're starting a Shiny journey, just start with express. I think core is useful for people who transfer from R. Because it's going to be very similarly shaped. But I find that how do you know that some value isn't a typo? How do you like the only time it shows up is on input some value and it's down there. And to me, that's a coincidence. And I don't appreciate it.
We're here. At least what we can do now oh, this isn't needed anymore. At least what we can do now is you have some value and it's going to get better even later. But at least with the renders, now you've removed some of that duplication. And so it's just like, hey, print some code. Here's the calculation and do it right here. From the top down execution where you have checkbox, then code. So I like express mode.
If you find a use case that you can't do something in express mode, let me know. And then I will make it so it's actually possible the first time. Let Barret know and he'll just fix Shiny for you.
I have a quick question. Could you just look through the project structure in general on the left there and tell me what I would be looking for to match my brain to Shiny for R if I'm a Shiny for R person? How would this project file look different or similar?
I am a little off here in that I'm actually in my Shiny for Python GitHub repo. I was noticing commit histories every time you hovered over something. And I was like, wait a minute. Yeah. No, I'm in my Shiny for Python GitHub project. So this is not your standard situation. Okay. I'm going to skip this for now. We can get some resources in the chat. But it'll just be like if we look at this folder here, it would be just app.py. Okay. Where normally you have your app.r, it'd just be app.py.
And if it's Express, it doesn't need any special things. If it's core, you need to have some app defined app object. That's the requirement. But Express, we handle that for you. Like you don't need to do this boilerplate. Awesome. Yeah. I can see how the app core definitely looks more like boilerplate Shiny for R where you've got a server, you've got a UI, and then you've got your call for your app. All right. Let's keep going.
What is Playwright?
Okay. So this is Shiny for Python. Now I want to take a step back and we're going to just totally shift gears to what is Playwright. So with Shiny, there's like a lot of moving parts. If I check this box, you know, the value updates, I think I can do this import. What is it if I do async? Let's try this live. Right? Import async.io. I saw it. Come on. There we go. Oh, wait. Async.io. Sleep. Right.
So now if I say check, let's up this to three seconds because that's a better version. So I've checked it. Two. Three. Great. Now if I check it again. Two. Three. Boop. Great. So this is really nice because now there's a delay of computation. Your browser is slow. You're running things on CI. You don't really know. And with testing, timing is really important.
If I say in my test, when I write this test, I could write it and I could do something like hey, just don't worry about the actual implementation of what it is. Just kind of read the names with me of like can you set the value to true? And then can you expect that that value is true? But what if you don't know how long it takes for that true, this true over here to show up? So if I uncheck it, two, three, it takes three seconds to turn into false. If I recheck it, it takes another three seconds to turn into true. So I can't just say, hey, browser, check the check box. Hey, browser, is it true? Hey, browser, is it true? Hey, browser, is it true? It's really fussy. It's really flaky, actually. And you'll most likely get it wrong. And so there's this timing issue.
In ShinyTest2, I originally tried to get around this by having a function of wait until idle. You can see that it's thinking and it's working hard and then oh, it's got a value. It is now idle. And then we can move on. And so that works, but it's really annoying to have to write that. It's really annoying to have to say, OK, set the value. Now do your app, wait until idle. Now do it down here. Now do it down here. Now do it down here. Like you have to do it in a lot of places, and I find it very annoying.
And so Playwright has this magical thing where it will replay some assertions for you. So it actually internally has a magical timeout equals, I think it defaults to five seconds. Something keeps taking over my mouse, and I don't like this. So I believe it's timeout is, timeout is, I think it's milliseconds. Don't hold me to it. So we can expect checked, and what it will do is it will actually retry that value for five seconds. And I think that is really powerful as to what can happen. Yeah, it is spooky season. Something is taking over my mouse. I swear it's Zoom. It's always Zoom. Blame Zoom for everything. I will.
Yeah, so this, that little like extra bit of this timeout of like waiting until it's true is very, very powerful. So I'm going to go into that a little bit more.
Yeah, so this, that little like extra bit of this timeout of like waiting until it's true is very, very powerful.
Anyways, backing up a little bit because I jumped the gun. Playwright, as they describe it, they enable reliable web automation testing and scripting. And AI agents, yes. But we're not using that right now. But it's automation, reliable automation for testing web apps. And I think that is just so awesome and so powerful.
The magic part about this is that underneath the hood, it uses a item called a locator. And I'm going to find this. I'm going to see if they have the class first. See if I can describe it. I don't see it right away. Nope. I see locators over here. New tab. There we go. Okay, locators. So the magic part to me about Playwright is locators. And as they describe it, it's a central piece of Playwright's auto-weighting and retry ability.
In a nutshell, locators represent a way to find elements on the page at any moment. And I think that's really important. It's not the elements found. It's a way to find the elements. The elements found, it's a way to find the elements on the page.
This allows you to ask the locator, can you get the elements for me again? Can you get the elements for me again over and over in that five second timeout?
Auto-waiting in Playwright
So Playwright has built in this item called auto-weighting. And this is really nice for the example of check. Yeah. So that input, I was going to the checkbox and I'm saying, hey, can you set this?
And what it does is underneath the hood, the Shiny team has defined a locator for that checkbox given the ID. And then what it will do is it will actually say, hey, is that checkbox visible? Is it stable? Meaning are the DOM elements moving it around on the screen? Can that and if that's stable, then we're good. Can it receive events? Like does it have disabled put on the input or not? Is it enabled? That would be the disabled one. Oops. Sorry. Can it receive events? Those are like JavaScript events, like a click event. And then checkboxes can't really be editable. But things like fill or yeah, they can be editable.
So I think it's really neat that it's going to do all four of these checks every time I want to alter the state of my app or even perform an expectation.
CSS selectors and locators
Jumping again back to the locator. The locators are defined using CSS selectors.
And a CSS selector is something like this where you say, oh, I have an ID that's like, let me, I guess I'll put this one in Discord for you guys to go through later. But you can define a long list of elements to describe what is like your items that you want to select. In this case here, it says find all the P paragraph tags and it would match them.
These aren't that complicated. So I'm going to move on.
So I don't have any examples here. But in Shiny testing, I'll just describe it as we've taken a lot of work to make these locators very, very descriptive so that we can do a single test in one shot.
So I think for something like a checkbox group where there's multiple checkboxes, I think I have if we needed to let's say we had let's say we did something in Positron where we had the group. Let me open this one up. And let's run this app just so that we can see it.
Waiting, waiting, waiting. This is my computer. That's really slow.
So now we have a checkbox group of red, green, and blue. And then the output showing you what has been selected. In this case, it's just red and blue.
The locator that we have defined when we say dear colors, expect that you have selected red and blue. We have to make sure that the that I think it's now a set so order doesn't matter. But we make sure that the colors ID has a child of an input whose value is red and is selected. We have a child whose value is blue is selected. And we have we also make sure that the colors and whose input values child is selected count is two. Because we know red and blue are unique. And we want to make sure that the count is two. So that way if there was like, you know, a purple color, we don't want to have that show up all of a sudden.
So we define this really big long CSS locator selector. And then we just say, dear browser, is this true? Try it for the next five seconds and let me know until it's done.
And all that happens inside the test file is it would say in this case, it's all that happens is we go, oh, expect choices this or expect selected red and blue. And so all the magic happens underneath the hood. And it's just absolutely beautiful.
And it's just absolutely beautiful. There's never a wait. There's never like, all I did was say set. And then I add I call the expect choices or labels are selected right away. And I didn't have to wait or do anything with timing.
There's never a wait. There's never like, all I did was say set. And then I add I call the expect choices or labels are selected right away. And I didn't have to wait or do anything with timing. Because you can imagine your your server can move forward in time. And the browser hasn't received the set method yet or hasn't even performed the set method yet. So there's this like separation that is just so fussy, especially with like GitHub actions, those machines are much slower than your local one.
Live demo: CSS selectors in the browser
Let's look at questions because I know I have kind of gone off the deep end here. I need a more concrete example of location. And I was wondering if you could open up a website, open up the DevTools pane in the browser. That's right. And give me a little like tour of what is actually happening to locate something. Because what we are testing, like I think about testing so much in the sense of hands on, like, let's test that the data is coming in, right? Let's test that this function that I wrote is doing the right thing. But we have sort of switched gears here at the end of test over to we are actually testing UI elements.
And I'm a super visual person. I actually, fun fact, have aphantasia. I can't picture anything in my head at all. I've never been able to. I didn't even know people could do that until I was an adult. And so I need to see everything. Show me what this looks like.
I am on the other end of the spectrum. I can visualize everything. And I can't articulate it to save my life. I think my husband can too. My mother and I both can't picture anything in our heads. And I didn't know that anyone could do that until somebody was doing a visualization exercise with me. And I was like, this is so dumb. Nobody can do this. And everybody was like, yeah, we can visualize things. And I'm like, oh, crap. I can't at all.
I don't know what I'm looking at here. So these are this is jQuery's website. Just because I know they'll have jQuery on there. And it's nothing related to Shiny. This is how I learned CSS selectors. I wanted to find elements with jQuery way back in the day.
And if one of the things that is neat with the jQuery is that they get all of the elements right now. Let me look at...
And so I have right here, I have this says jQuery. This would be find all elements that are of type H3. Which are these little headers over there. So if we hover over them, a couple of them show up. And by default, I think there's nine H3s.
So if I looked at some of the DOM, and I believe there was a parent item called section. So if I do that, it will remove four of them. Because these first few, I believe, are... Anyways, they're hidden away. So they're not something that we can easily see. What I'm looking for is the H3s over here.
So we have one, two, three, four, five. Great. So each of these little like heading number threes. Wait. So wait, wait, wait. Yeah. Okay. So the event handling, Ajax. My brain didn't catch that. Like what you were hovering over and what was highlighted. So DOM traversal, event, Ajax. Oops. Ajax didn't get it. And then where my mouse hovering isn't working. There we go. H3, jQuery, and Ajax. Event handling, DOM traversal. Awesome.
If I save this in JavaScript of items, okay. Great. Now, one little fact. You can mess with the DOM. And so I can come over here and I can just delete this because I feel like it. And it's great for the demo. If I were to ask jQuery now, what, how many elements, it will say that there are four. Length four. Because it didn't find it. It didn't find the one that I deleted. So now it's just event, Ajax, UI, and mobile.
Now, here's an interesting question. What do you think items represents? Earlier we got it and it had five items. I then manually deleted it. And now what do we think items has? Four or five?
I think it still has five. Also, Hubert wants to know if the dollar sign that you're using is a search function here in our console in the dev pane.
No, it is actually jQuery's item. It adds it in the JavaScript. So they like pioneered that they represent the dollar symbol. Okay. I think that was his question if it was just in jQuery. Yeah. Yeah. There is some Chrome DevTools things of like dollar zero. But like if you like highlight something, but that is, yeah, that was the item that I had highlighted up above. But no, this is jQuery's searching.
I still think that it's five because you defined it as five and that that won't change your definition. Am I right? Yes. So items still won't change it. Yes, it still has the five items. It still points to the I didn't cover. There we go. Event handling. And then this H3 is actually like not attached to the page. So it was captured.
But I think the important thing here is that jQuery, whenever you search for something, it captures them right now. And so now if I make any assertions on items, it's possibly stale information. And so instead what locators does is it kind of like backs it out one level and it says, hey, what was the thing that you were trying to find? Oh, that was section H3. Let's define this as a locator on your page. And then now we have this section H3. And like underneath the hood, we could actually like use jQuery to grab the items and then make the assertions. But we're starting with the selector, the thing that we use to define the search, not actually perform the search. And I think that separation is really, really what makes Playwright so powerful.
And I think that separation is really, really what makes Playwright so powerful.
Sorry, I'm reading things in the chat here. Adam says, the dollar sign is jQuery itself and jQuery's default operation is query. Hubert says, this is what I liked about Shiny to start with. I could ignore most of the stuff happening in the web client level. Yes, absolutely.
Shiny's Playwright controllers
So, we actually want to take that, Hubert, and extend it to testing. So, Shiny has come out with all of the I want to back out one. There we go. We have Playwright helpers for every single input and output that is defined in Shiny UI. So, if we did, as we did in examples, a input checkbox or checkbox group, we have a controller for input checkbox or checkbox group.
So, for the checkbox, we know there's a ID, a label. You can set it. You could get the value. You could, you know, that's about all you can kind of do with a checkbox. There's not much. So, if we define a input checkbox item in our tests, So if we define a input checkbox item in our tests, we need to provide the Playwright page that it exists on, and then the ID value that we want to go towards. Like, some value, I think, was the example that was used. And then I prefer just using the methods, and you can say is it expect-checked, expect-label, expect-width, and then you can also set. We tried to make it canonized so that every parameter that you supply to your UI function, there should be an expect method for that. It's not perfect, but that was what we're striving for. Because you have control
over the label, you have control over whether it's checked or not, and then you have control over the width. And, yep. All right, so let's look at that in action. We have, okay, so this is your standard-style test file. Not CompTest, but at least you'll have Playwright. I use the sync API. I don't think we support async, but underneath the hood, we do test async shiny things, but I just use the synchronous API for testing Playwright. Then in shiny, you could import the controller module, or if you wanted to, you could do shiny Playwright controller import input checkbox. But it's also hard to remember these, so I preferably use controller, and then that way autocomplete works really well, because if you start typing, like, check, like, checkbox, and then it autocompletes for you. You don't need to think about it.
And so, I liked a little bit of a lazy way. Then, normally, we would do, oh, this is, let me look at an accordion one. Just to be a little bit nicer. Normally, what would happen, then, is you would just say, hey, give me a local app, and this is a fixture that will start up your app and then shut down your app at the end of the test. So, you don't need to manage that for yourself. A fixture is a helper parameter that we can register behind the scenes, and so, a local app will look for any app.py that is a sibling to the test file.
Then, once we've done that, we tell Playwright, hey, go to the app's URL, and then we can now make some assertions about those apps or actions or other things.
So, for example, this is testing aspects of your accordion. Physical pixel widths, pixel heights, the expected class, and I'm guessing that's, like, an SCSS class, or well, a CSS class, should be the bg slash light, and then expect multiple is something, like, we only have one. You can only open one at a time, I believe. Right. And it's a parameter that you can supply. Yeah, when you open it. Okay, cool. Thank you.
And then, yeah, similarly, then, if we're looking at the first panel of the accordion, ah, this hover is getting me. The first panel of the accordion, then, we're going to make sure that it's open, it's labeled as panel one, and there's no icon.
Just to see the app, because, just for you, Libby, let's run the accordion app. I shamelessly love accordions, and I love, like, designing them and figuring them out and using different, like, JavaScript libraries to see what different accordion types I can get. So, I'm glad you picked accordions. Accordion is awesome. It's such a nice way to, like, containerize your inputs or components of your app.
Karan had a really good demo where he had almost, like, a multi-step workflow that had, like, three or four inputs in each panel, and you couldn't go to the next one until you hit submit, and then we would automatically update the accordion positioning and opening and titles given the inputs that were given.
I don't like that multiple false, though. I want to open all the accordions that I want. Don't tell me I can't do it, Barrett. True. But it was something that we had to opt into it. So, by default, multiple is true.
But with multiple false, if I click panel two, panel one closes, panel one opens, and then panel two had a icon here. So, now, in our test, panel two, expect icon true, just to have something. Yeah.
Testing at scale and assertion-based testing
All right. We have a request from Sol. Sol says, would you mind sharing how you're using Playwright on larger scale apps? I'd love to learn about specific use cases or patterns that would become important as the complexity increases. Ooh, are we ready to move up in complexity, Sol? What does complexity mean to you? Yeah, that's a great question.
Sol, we need a follow-up. We're laughing at GIFs in the Discord. Everybody should be in the Discord.
Sol is following up with us, but I think that complexity might increase with number of pages, number of things that you have in your navigation, for me, and number of things that work together to influence each other. Like, as the React graph grows, right, to me, that's complexity increasing.
To me, I like to have each test, in this case, it doesn't, I'm overreaching in this case, because I would argue maybe that is a good test. We go in, we make sure that the container is okay, we go in, we make sure that the container is okay, and I make sure that my first panel is all right. I mean, asking about the second panel is good, but it's very arguable that actually I think there's a there's a second accordion in here. It is very defensible that this should be another, a separate test, you know, accordion in Kitchen Sink 2, like it should be its own test over there instead. But because my purpose in this one is to test all of the knobs and whistles, you know, I'm putting them all in one.
We talked a little bit about this with Rich Iannone as well, I think, where he was like, you know, don't do too many things in one test, right, like have one test, do one thing, and then it might feel like you're repeating yourself a lot when you are testing, but you want them isolated, because if one fails, you want to know what inside of that failed, you don't want to be guessing like, okay, well, which of my five accordions that I tested in this test file is the actual problem, right? So isolating is probably good.
Isolating is good. A phrase that, you know, we came up with last week was a screenshot is worth a thousand tests. And this is one part where Playwright is different, and Playwright by default, all of this is assertion-based testing. We're not doing screenshot testing. We're not doing snapshot testing. They have it. You can do that. But if a screenshot is worth a thousand tests, things are brittle. Things do break. Chrome doesn't round things the way it wants to consistently. So even if you've done everything perfectly, the system is still going to fail you. Your font changes on GitHub Actions. Oh, man, I hate that one so much. It's nothing that you did. And now, you know, 30% of your tests are broken.
Isolating is good. A phrase that, you know, we came up with last week was a screenshot is worth a thousand tests. And this is one part where Playwright is different, and Playwright by default, all of this is assertion-based testing.
So this is why I, like, lean towards doing Playwright testing much more because of its assertion-based testing. I can target very specific things. And if I do need to check is, like, the background color, a certain, you know, a certain shade, you can do you can access, like, computed. Where is this one? Dot container. It's not perfect. But Git. No.
Element. I've done, like, you're very kind about this. But I've also failed probably 10 more times than I think we've all, like, maybe collectively in this room have attempted. So I have the scars to know my way around. All right. So this would be my element. And then I could say my element dot I think it's Git computed. Yeah. Git properties. Or there's a Git there's a CSS. I can't remember it. But it's something towards the you can ask the element to get computed properties. And we do this for, like, checking a background color of a div to make sure the CSS class was applied properly. Not just not just confirming that the attribute exists, but we actually confirm that the computed background is a certain hex color.
So that's even more targeted with that assertion testing. But any like a pitfall, though, any time you call Git elements or element handle or element handles, you pull a jQuery in that you extract the elements right now. Where as long as it's just a locator, then items are found on demand. So only call element handle if absolutely necessary or you've proven that your state is good enough to extract. Yeah. Git computed style. Thank you. There we go. Yeah. Spella found it.
What is jQuery?
And I wanted to like we've said the word jQuery several times without defining jQuery. And I would like to just like give a little what is jQuery. I never had to use jQuery until I was getting deeper and deeper and deeper into Shiny development. And I needed to do things like listen for keystrokes and I needed to find things inside of HTML. And so I think of jQuery as like I am using JavaScript in a small containerized way or a small like little way to navigate HTML, to like figure out HTML, to listen to things that are happening to HTML. Am I right in any of that, Barrett? Or like is there a better way to describe jQuery?
Yes. Yeah. So like your example of the listen to HTML, like here for this button that is defined or found at button container button, when a click happens, you know, let me run some JavaScript. Before jQuery, especially when we had IE and other browsers, you could like put the JavaScript in the event in the DOM structure itself. You could write it in. But not like sometimes Windows didn't work. You know, Firefox was a little different. IE was definitely different. And jQuery said Internet Explorer, which is end of life. Please don't revive it.
But jQuery came along and said, hey, here's some JavaScript you can write once and it will work everywhere. You don't need to do special things. And like that as a selling point is just amazing. And so, you know, today's world, maybe it's not too useful. Because agents can and also JavaScript is, you know, conforming and becoming centrally uniform. But this was just a game changer 10 years ago. Yeah. And I feel like if you work in Shiny, you can recognize the concept of like an event or listening for an event. And like one of the things I've used jQuery for is listening for key clicks, key presses, right? Like, hey, I want you to listen in this login modal for an enter so that you can apply that enter to the login button. Otherwise, it's difficult to just like type in your password and hit enter. Not that I'm super, super successful using jQuery all the time. But that's one of the things that I feel like I've used it for in the past that I can relate to Shiny development. I find myself learning dev work just to work with Shiny so I know what's what. Absolutely. I feel like I only know enough about development to get the Shiny thing to work. And then I'm like, okay, I'm done. It's too overwhelming.
Writing tests and using agents
Yes. Yes. Some of the phrases from last week as well. My dad, he was writing documents for work when computers first came out. And he worked on his document for three days. And then at the end of it, his computer crashed and he lost all of his work. And autosave was not a common feature. And, you know, it was gone. So he really instilled the fear into me of like, you know, if you have time to rest, you know, save your file. And, you know, that kind of goes towards doing things of like McDonald's does this. If you have time to rest, you have time to clean.
And, you know, you work so hard on your Shiny applications that, like, if you have time to rest, you have time to write a test or even record a test. If you're using agents, agents are wonderful in that if you add a feature, just have the agent write the Playwright test in parallel to confirm its behavior. And I think this is really important because six months from now, I'm not going to remember 100% of the features in my app. I'll remember the two main ones, but not the little finicky ones that took you two hours to figure out and get over.
And, you know, you work so hard on your Shiny applications that, like, if you have time to rest, you have time to write a test or even record a test.
Like, no one wants to rediscover that. So, write a test to confirm that behavior that you want. And then that way teammates also can't bust your app because they didn't, they weren't aware of the feature that was only in your head. Six months. Yeah. Next week.
Next week. More like, I was going to say, Andrew, I agree. Yeah. Anytime someone says, oh, you next year, you're going to need to remember what you did. I'm like, no, no, no. Like four days from now, I'm going to need to remember. I have a question with our last 10 minutes left. To finish, though, the nice part, though, about these shiny controllers is that hopefully this code does not change. Maybe internally and underneath the hood. Who knows what happens. But these expectations should be stable over time. And I think that's the important part. So, even if your app gets adjusted or we update the styling of it or the structure looks a little bit different, here you can just say, hey, I know my accordion is titled this. Make sure it's with the 600 pixels because that's what I put in my UI definition. Thanks. Like, I think that's, that's just really powerful.
But these expectations should be stable over time. And I think that's the important part. So, even if your app gets adjusted or we update the styling of it or the structure looks a little bit different, here you can just say, hey, I know my accordion is titled this.
Okay. Okay. That, that was actually my question was like, I'm so wishy-washy with like how I want my things to be in my app. I'm constantly changing things where I'm like, oh, this looks better. Or, oh, I need to, I need to add like dynamic sizing for the screen type. Right. And then I'm like, okay, well, I'm going to go in here and add like, if it's, if the screen is this many pixels wide, I want you to actually just show all of these stacked up like this. And if it's super wide, then I want you to like dynamically get bigger and like, let's let these accordions be side by side. And then I'm like, oh crap, I have to go back and manually change my expectations in my assertions for all of these tests. And like, how do I keep up with that? So, how do you think about that? How did you think about that before AI? And are you using AI for that now?
Is that just like, we would test that completely independently and we would let those accordions stay the same size or? I don't have, this isn't what I want specifically. This is a specific question. I think the question is more like, how do you keep up with your own changes if you're a whirlwind of changes? Like I am.
Um, at some point I'm going to imagine you will go, okay, I'm done. And like, that's like an hour later. That's fine. Like at worst, at worst you would lose an hour of work. That's not bad. Um, if it's something where you would go, okay, I can make a PR now if you're doing team development with pull requests on GitHub, like before you submit the PR or merge the PR more or less, um, make some tests. Like you don't need to do it at the very beginning. I know it's like standard software development is, uh, write your tests first and then build the feature out. But in this case, you don't know with Shiny UI, like what you want. So get it to where you want and then like solidify it with tests.
Maybe this is a case of don't over optimize too early where you're like, maybe don't write your entire test suite test before you feel like you are really good with all of your changes. Cause I'm thinking of like being a shiny dove where you're like, I'm going to make this thing. I'm going to make it look pretty nice. I'm going to send it to my client. And then my client's going to send me revisions, right? Where they're like, Oh, I don't actually like this. I don't like the way this works. Can you make this work a little bit different? And if I've already written all the tests to my basically sketch or, or wireframe version of my app that I think is pretty great, I'm going to go back and have to redo all those, all those tests.
Yeah, that's fair. Um, I think you could trim down as to what is important. Then in this case, I'm being very explicit to test all the things because I need to make sure that all the functions work for you. It does not mean that you need to do that. Oh, that's good context because you're actual shiny engineer. Yes. So I need to make sure all the functions work that way you can trust it. Um, but if I was doing this to me, I would make sure that like, I wouldn't care about the height or width. I don't care about that. Expect multiple false. That's an important feature of this accordion. And then personally, I would say, okay, the, I need to make sure that the first one is open by default. And then panel two, the important one to me is that there's an icon.
I like this so much better. This is great context. My brain loves this. Cause I'm like, just test the essentials. Just test the essentials. Um, what is important to you? Like it's not like, it doesn't, does it ruin your day? If panel one has a different text, like if, if it said paneled or like paneled four or something, you know, it'd make a difference if, if one was dependent on data, but like, if it doesn't, if it wouldn't ruin your day, then it doesn't need an exact test. But, uh, for me testing the multiple, you could make sure that that works by setting panel two to true. Like I click it. And then now I know that panel two is open and panel one is not open. Um, right. That's makes me feel so much better. Cause when I saw all those tests, I was like, Oh no, y'all, I don't test depth. I don't, I'm bad at testing in general. So like, wow, seeing all these tests is making me feel like I'm not doing enough ever makes me feel a lot better.
Just test the essentials. Just test the essentials. Um, what is important to you? Like it's not like, it doesn't, does it ruin your day? If panel one has a different text, like if it doesn't, if it wouldn't ruin your day, then it doesn't need an exact test.
Also, Connor said in the chat, I add quote, tests must match the features and quote to my agents dot MD. Then Claude scolds me for not having tests for the features I just added. And then I have Claude write those tests. So that's a little bit, a nice taste of like someone's, um, agentic workflow that I like. This was wonderful. Thank you, Connor, for adding context.
Wrapping up and final resources
I hope everybody has had a little small taste of what playwright looks like. I wanted Barrett, if you could go back to the shiny docs where all of this playwright code is, and just like, I wanted to emphasize that we are actually looking at the shiny documentation where it's specific to shiny for Python. And all of this playwright code is there for you because all of these devs at posit have done all of this for you to like, show you how all of this goes together. So you don't, I don't think you have to like, navigate the playwright docs by yourself either.
No, no, no. And I don't want anyone to think, well, I have to go read playwright docs. Just use the shiny docs. Use the shiny docs. And we have Oh, bless you, Barrett.
I think Barrett is sneezing and coughing or one or the other.
Sorry. Yeah, I coughed. Um, we have a unit testing docs to give you a quick intro. And then also we have a end to end article of like, help introduce you into a playwright and why you do full end to end, meaning browser to server and back to browser again.
Amazing. Okay. This is wonderful. I'm so thankful that you're giving us a peek into all of this. It sounds like you have to cough again. I'm so sorry.
We're hanging out with us. Tell Barrett to go drink some water. And I just want to thank you as a shiny dev. You, Karan, like everybody on the shiny team for making this happen and be being as cool as you are and like looking out for all of us who use this tool, making sure everything works. And thank you to all the people that we saw in Barrett's commit histories today that were like ghosting all over his screen. Every time it was like, this commit two years ago, it just shows you that there's so much active, active development on shiny and shiny for Python. And the last time I made a shiny for Python app, I was, I too was like reading documentation and testing it to make sure that the documentation was good. So I just love how wonderful this community is. Thank you so much, Barrett. Everybody say thank you in the chat.

