تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Planning video purchase flow0:00

In the previous lesson, we successfully finished writing our first feature, as well as the scenario. So, if we rerun that feature, we can see that yes, these first three steps have passed, but then we finished up with the cliffhanger of, I purchased a video. So we'll tackle that in this lesson. If I switch over to my feature context, here we are. So what form would purchasing a video take? And this is honestly one of the great things about doing BDD in this way. Rather than just diving in like a cowboy, instead, we take a step back and really take a moment to think, what shape and what form is this going to take? Now, what I've decided is, if I switch over to the development version of the site, notice that if you are not logged in, you see this bit of text here. Maybe we could append to this. So we'll do that in the form of just simple text. But of course, we won't focus too much

Adding purchase link step0:45

notice that if you are not logged in, you see this bit of text here. Maybe we could append to this. So we'll do that in the form of just simple text. But of course, we won't focus too much on the design aspect in this series. We're mostly interested in implementing this feature. So maybe we could add some kind of additional link that says something along the lines of, or buy this video. Well, let's set that up. I can say this, click link, and we'll say buy this video. Next, what do we expect that to do? Well, again, if I switch back, ideally, it should take us to this page here. And maybe we can modify this view so that if they don't want a subscription, we can simply remove it. That way, it's mostly the same view, they simply don't see those bits. Because remember, if somebody wants to buy a video, well, I still need to fetch their credit card information. And if they want to buy more than

Automating signup form fill1:28

they simply don't see those bits. Because remember, if somebody wants to buy a video, well, I still need to fetch their credit card information. And if they want to buy more than one video, well, I don't want to make them enter that information every single time. So if they don't have an account, we'll make them create one the first time, provide billing information. However, in this case, we won't add them to a subscription plan. Instead, when they click buy now, they'll simply be charged five bucks, and then they can download the video. And that's all there is to it. So if we return to this code, we basically want to add all of the necessary logic for filling out each of these inputs here. So you can do something along the lines of fillField, or you can even use fillFields. So for example, if we say fillField username, and I'll just add gibberish here to show you how it works.

Running tests with Selenium2:06

So you can do something along the lines of fillField, or you can even use fillFields. So for example, if we say fillField username, and I'll just add gibberish here to show you how it works. If we go back to our feature, and I will add the JavaScript tag here, and that'll make sure that we do use Selenium. That means in the process, it will boot up a browser, and you can actually watch this process in real time. Okay, let's try it. Run it again. Notice this time Firefox will pop up, we're on the page. And of course, at this point, it failed because we haven't added that link. Let's go ahead and do that now. I store that within a specific partial called video_login. So if you aren't logged in, you will see this in place of the video. For now, like I said, in the future, I'll make this look prettier. But to get us going, let's just say or and let's add a link to sign up. And I'm also going to specify that the plan should be none. Finally, we will set

in the future, I'll make this look prettier. But to get us going, let's just say or and let's add a link to sign up. And I'm also going to specify that the plan should be none. Finally, we will set the text to buy this video. Alright, so now that text should be there. If we just update this a bit to be buy this video, and let's see what we get. But also this will happen really fast. So to show you what we get, let's wait for about five seconds, just so you can take a look at the browser window. Okay, we run it. It opens up Firefox. Here's our page. And notice that it did fill out that username. So hopefully you can see this basic process here. So now what I will do is fast forward so that you don't have to see me fill out all of these fields. Okay, and I finished. So for the time being, this is all in the same method. But if we do need to extract it for a different scenario, then of course, we can do that in two seconds. So all that we've done is created a quick factory

this is all in the same method. But if we do need to extract it for a different scenario, then of course, we can do that in two seconds. So all that we've done is created a quick factory here for User. And then we've used that dummy data to populate this form. So everything from the username to the password to the credit card details. And then finally, we click on the sign up button. So let's take a look at this. And once again, I'm going to stick around for about five seconds just so you can look over this. Now once again, because we are using Selenium, don't forget that I do have my Selenium server running. If you don't know how to do that, just download Selenium server. And then you can do java -jar and then provide the path to Selenium. And that's it. So make sure that's running in one of your tabs. Okay, let's run it again. Once again, Firefox pops up, we fill out all of the fields with the dummy data and take a look. There you go. All right,

Defining download verification4:24

So make sure that's running in one of your tabs. Okay, let's run it again. Once again, Firefox pops up, we fill out all of the fields with the dummy data and take a look. There you go. All right, so now we are ready for the next step. If I return to our editor here, we're on to this next step, I should be able to download it. So once again, what form should this take? If I return to the editor, we're mostly done with this section, we click buy this video, we fill out the form to sign up. By the way, we could also purchase the video if we have an account. So that stands to reason that in the next scenario or so, we probably will want to extract this out to its own reusable logic. Anyhow, once we do sign up, we should be redirected to that same page, at which point they can click buy this video again. And this time, it will charge their card. And of course, in reality, there would probably be some kind of modal pop up asking you to confirm if you want to buy the video.

Designing purchases page check5:11

can click buy this video again. And this time, it will charge their card. And of course, in reality, there would probably be some kind of modal pop up asking you to confirm if you want to buy the video. But I'm trying to keep it a little bit simple, at least for this series of lessons. So let's imagine that's all we have to do. Then we come to this next bit here, I should be able to download the video. Well, what form should that take? Well, again, if I switch back to the browser, maybe now that they have an account, when they go to their account information area, there will be a new page over here, something like purchases. And that's where they can view all of the videos that they've purchased, as well as download them. So with that in mind, maybe if we try to visit one of those pages, and that will be /admin/purchases, then we could do something like assertPageContainsText. This comes from the main context.

maybe if we try to visit one of those pages, and that will be /admin/purchases, then we could do something like assertPageContainsText. This comes from the main context class that we extend. Maybe we should see whatever the name of the lesson is. We called it example lesson. Alright, so that'll do it for this lesson. What I will now do behind the scenes is tweak some of the billing logic just a bit stuff you don't really need to see. And I will also set up the purchases page. So I'll see you in the next video where we verify whether or not this worked.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟