Automate Application with Specflow and Selenium WebDriver C# | Elias Spock | Skillshare

Automate Application with Specflow and Selenium WebDriver C#

Elias Spock, Chance favors the prepared mind.

Automate Application with Specflow and Selenium WebDriver C#

Elias Spock, Chance favors the prepared mind.

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
67 Lessons (5h 58m)
    • 1. 00 Promo

    • 2. 00 TestStack

    • 3. 01 Intro to Integration and Acceptance Testing 01 Outline

    • 4. 01 Intro to Integration and Acceptance Testing 02 Different Types of Tests

    • 5. 01 Intro to Integration and Acceptance Testing 03 Integration and UI Testing

    • 6. 01 Intro to Integration and Acceptance Testing 05 Why Automated UI Tests

    • 7. 01 Intro to Integration and Acceptance Testing 06 What is Acceptance Testing

    • 8. 01 Intro to Integration and Acceptance Testing 07 Acceptance and UI Automation Testing Frameworks

    • 9. 01 Intro to Integration and Acceptance Testing 08 Conclusion

    • 10. 02 Intro to SpecFlow 01 Outline

    • 11. 02 Intro to SpecFlow 02 Why SpecFlow

    • 12. 02 Intro to SpecFlow 03 BDD vs ATDD

    • 13. 02 Intro to SpecFlow 03 SpecFlow Workflow

    • 14. 02 Intro to SpecFlow 06 Gherkin

    • 15. 02 Intro to SpecFlow 07 Basics of SpecFlow

    • 16. 02 Intro to SpecFlow 08 Two Approaches to Implementation of Acceptance Tests

    • 17. 02 Intro to SpecFlow 09 Conclusion

    • 18. 03 SpecFlow in Details 01 Outline

    • 19. 03 SpecFlow in Details 02 Generating Steps in Details

    • 20. 03 SpecFlow in Details 03 Demo Example Overview

    • 21. 03 SpecFlow in Details 04 Writing the First Test

    • 22. 03 SpecFlow in Details 05 Running and Debugging Acceptance Tests

    • 23. 03 SpecFlow in Details 06 Adding new Cases

    • 24. 03 SpecFlow in Details 07 Passing Parameters

    • 25. 03 SpecFlow in Details 08 Scenario Outlines

    • 26. 03 SpecFlow in Details 09 Passing Data Tables

    • 27. 03 SpecFlow in Details 10 Scenario Background

    • 28. 03 SpecFlow in Details 11 Converting Parameter Types

    • 29. 03 SpecFlow in Details 12 Converting Tables

    • 30. 03 SpecFlow in Details 13 Converting Tables to Sets

    • 31. 03 SpecFlow in Details 14 Custom Conversions

    • 32. 03 SpecFlow in Details 15 Sharing Data Between Steps

    • 33. 03 SpecFlow in Details 16 Categorizing Tests by Tags

    • 34. 03 SpecFlow in Details 17 Scoped Execution

    • 35. 03 SpecFlow in Details 18 Scoping and Workflow

    • 36. 03 SpecFlow in Details 19 Hooks Overview

    • 37. 03 SpecFlow in Details 20 Hook Demo

    • 38. 03 SpecFlow in Details 21 Conclusion

    • 39. 04 Selenium Fundamentals 01 Selenium Overview

    • 40. 04 Selenium Fundamentals 02 Demo Web Site

    • 41. 04 Selenium Fundamentals 03 First Automation Example

    • 42. 04 Selenium Fundamentals 04 Locators

    • 43. 04 Selenium Fundamentals 05 XPath

    • 44. 04 Selenium Fundamentals 06 CSS Selectors

    • 45. 04 Selenium Fundamentals 07 Input, CheckBox, RadiButton, DropDown Menu

    • 46. 04 Selenium Fundamentals 08 Dynamic Nature of Modern Web Sites

    • 47. 04 Selenium Fundamentals 09 Explicit and Implicit Timeouts

    • 48. 04 Selenium Fundamentals 10 Locators Priority

    • 49. 04 Selenium Fundamentals 11 Scenarios to Test

    • 50. 04 Selenium Fundamentals 12 SpecFlow and UI Testing Frameworks

    • 51. 04 Selenium Fundamentals 13 Conclusion

    • 52. 05 Selenium

    • 53. 05 Selenium

    • 54. 05 Selenium

    • 55. 05 Selenium

    • 56. 05 Selenium

    • 57. 05 Selenium

    • 58. 05 Selenium

    • 59. 05 Selenium

    • 60. 05 Selenium

    • 61. 05 Selenium

    • 62. 06 Selenium Extras 01 Outline

    • 63. 06 Selenium Extras 02 Writing Tests for Different Browsers

    • 64. 06 Selenium Extras 03 Managing Window Size and Location

    • 65. 06 Selenium Extras 04 Open new Tabs and Windows

    • 66. 06 Selenium Extras 05 Close Tabs and Windows

    • 67. 06 Selenium Extras 06 Conclusion

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

BDD with SpecFlow (based on Gherkin) and Selenium WebDriver with C# + Intro to UnitTesting and TDD with TestStack.White.

This course is all about growing object-oriented software guided by tests.

SpecFlow is a framework which brings Behavior-Driven Development (BDD) into life. It is all about filling the gap between technical people and domain experts. SpecFlow is based of a Gherkin language which is very close to natural (though, it is formalized). So, non-technical people can write executable documentation on their own.

Selenium is a framework which allows to drive browsers (Chrome, Firefox, Opera etc.). In other words, with the power of Selenium, you can write a program which automatically interacts with elements on a web page.

TestStack.White (sometimes, written as "teststack white") is a framework which allows to drive WinForms and WPF applications.

This course covers:

  • Theoretical background behind different types of testing (unit, integration, and acceptance testing)

  • SpecFlow: generating steps, run and debug tests, passing parameters, scenario outline, data table, converting parameters, converting data table, custom conversions, sharing data, categorizing tests, scoped execution, hooks, and other features

  • Selenium WebDriver: Locators, XPath Locators, CSS Locators, Interacting with all the types of Elements, Timeouts: Explicit and Implicit, Locators Priority, Picking Scenarios to Test, "Page Object" design pattern, Page Object Factory, uploading files

  • Scraping a Live Web Site with Selenium WebDriver

  • Selenium Extras: managing a web browser

  • TestStack.White and Building a WPF App by TDD (with MVVM)

  • Appendixes: Intro to Unit Testing and Test-Driven Development

Meet Your Teacher

Teacher Profile Image

Elias Spock

Chance favors the prepared mind.


I'm thankful enough for that I love what I do.
I began my career as a postgraduate student participating in Microsoft ImagineCup contest.
I've been working with .NET platform since 2003. I've been professionally architecting and implementing software for nearly 7 years, primarily based on the .NET platform. I'm passionate about building rich and powerful applications using modern technologies. 
I'm a certified specialist in Windows Applications and Service Communication Applications by Microsoft.
I'm one of the coordinators of the MSK.NET User Group in Moscow.

"If it's work, we try to do less. If it's art, we try to do more." - Seth Godin.

What I can say is that software is my art.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.



1. 00 Promo: Hi. This is injury spark from injury spark dot com, and they'll be leading you through the course. I've been working with the dot net platform since 2003. I've been professionally architect ING and implementing software more than 10 years, primarily based on the DOT That platform I'm passionate about building reach and powerful applications using modern technologies. I'm a certified specialist in Windows applications and service communication applications by Microsoft, and I'm one of the co organizer's off the most kudos that user group in Russia. And here's my teaching approach. No fluff, no ranting, no beating the air. Steam your time course material is succeed. Yeah, comprehensive. All the important concepts are covered particularly important topics not covered in depth for absolute beginners. Offer my help on Skype absolutely free if requested. Take this course and you'll be said it's fine. Hi, This is a lives fulfilled. A key engineer spark from engineers dot com. Welcome to the automate application with backflow and selenium. Web driver in search our course. This course is all about growing object oriented software. Guided by tests, Spec flow is a framework which brings behavior driven development, or BDD. In short, into life. It's all about feeling the gap between technical people and domain experts. Spec flow is based on a girl can language, which is very close to nature, though it is formalised. So long technical people can write. Execute herbal documentation on their old selenium is a framework which allows to drive browsers such a scrolled Firefox, Eldora, etcetera. In other words, with the power off psyllium, you can write a program which automatically will interact with elements on a Web page or Web pages test. That, quite, is a framework which allows to drive win forms and WP F applications in shirt. These course covers theoretical background behind different types of testing such a union integration and acceptance testing spec flow, including how to generate steps how to run in debug them. How to pass parameters. Helped to write scenario outlines how to pass data tables. How to convert parameters to convert data tables to plain structures and data sets. How to write custom conversions. How to share data between steps. Hotel categorized tests by applying tags. How to imply the feature of scoped execution. How to apply hooks and other features. Ceiling him with drivers, including the theoretical background behind locators. In general, expect locators, CSS locators. How to apply them, of course, how to write such locators hope to interact with older types of elements. Timeouts, explicit and implicit locators. Priority. How to fix in theirs to test what is page object designed better, how to apply it, how to enhance it, how to upload files and other things. How to scrape a live website With Cillian Web Drive It means that we're going toe automate aerial world website selenium extras, including how to manage a Web browser, how to Opened New Tabs Windows, How to close those tabs. How to manage the location and size of the Browser. And So Destec White and How to Build a WP F application by playing test Dream and Development with M V. M. And in this section, we're going to write acceptance tests s well with SPAC Flow and a band exes, including introduction to unit fasting and test driven development. There is a plant e of topics we're going to discuss in the role right now and start learning for the automate application with spec flow and selenium Web driver into Sharp course. I'll be waiting for you 2. 00 TestStack: the white framework uses the automation a p i u I A. To find controls on the window, you are a communicates to displayed window via window messages. This find is performed by iterating through all the controls in a window. The basic scenario if using the framework is the following determine the director often application. We're going to test launch that application through the glass application, which belongs to the white framework like this. Then find the window we want to manipulate. I will to notice once again that application window and other classes here you'll see like Barton, all of them belonged to the white framework. These classes do not belong to WBF or any specific ey framework having a window. Instance, we can query it to get the controls. Calling the get method. A U EY item can be found by a variety of search criterion like this. You can see in this example that we search for a text box using the so called automation I d. These automation ideas the property, which can be assigned toe almost anywhere element and thus can be found without any problems. I also want to say a couple off words about the difference off working with built in well known controls and third party controls. Is there any difference from the white framework? Yes, indeed. There is a difference fundamentally. All you Iittle czar, either Elementary label e g having no other item in it, were composed off other items in these Destin Quite there is in build support for standard you I items These are called standard mainly because of their prevalent use and ready availability in development environments. When we use 1/3 party controls, this might not be enough even though these you I items are still made up off elementary items and can be automated by finding them individually. But we might miss some abstraction while doing this. Also, when you build a lot of things in these items ourselves which are tolerated down and white for other idols, this is where customers ey item would be useful. White provides support for all the controls which come with standard dotnet library. This support, it's partially just abstraction over your automation and window messages. So, in case of third party controls like them, express pure components, etcetera, there are no standard you I item in implementation in white, which you can use out of the box. The reason being the automation element structure beneath is unique to each of them. These custom, your item can be blocked in tow. White. While implementing these, you might face issues. Of course, in most cases, we can search for elementary or composed items to act on them. You'll see this course how I manipulate 1/3 party control named into Europe Down, which consists off a text box and to Barton's. So in most cases, everything is fine. But there can be custom scenarios when you need either to implement the support off you I automation on your own or to ask the provider of 1/3 body component. To do that, you'll see the white frame of connection while we implemented acceptance tests. 3. 01 Intro to Integration and Acceptance Testing 01 Outline: Hi. This is Engineer Spark from engineer spoke dot com, and in this section we're going to learn what is integration and acceptance Testing. The task of translation business requirements to unit tests lies on the shoulders off software developers. However, developers can interpret business requirements in the wrong way. There is a well known gap between software developers and a team off customer, which is responsible for delivering those requirements to reduce or remove that gap. Developers came out with the concept off acceptance tests, which allowed to formulate business requirements in a formal language, which is very close to in nature. In this short introductory section, you will learn what types off tests exist and when TDD can be applied. T d D stands for test driven development. What is integration and you I testing. And what is the difference between them? What is acceptance, testing and why we need it. You learn about frameworks, spec flow, selenium and desk stack white. Okay, let's get straight to business 4. 01 Intro to Integration and Acceptance Testing 02 Different Types of Tests: before moving to specifics off certain frameworks and all the details related to specific problems off those frameworks. I want to make sure that you fully understand what categories of tests exist and what role they play in the ecosystem off software testing. Even if you feel like you know these basic concepts, I want to remind you about some particularly important points. At first, you need to understand that basically, tests can be divided into three major groups. Unit tests, integration tests and acceptance tests. Unit tests are those tests, which verify the behavior off a unit under test in isolation. That's why when the unit under test has dependencies, we often mark them or, in other words, to replace by special test doubles unit tests are great, and the majority of tests should belong to these type of tests. This is because these type of tests is hard to break and easy to run off course if they're written in in good style. If you know nothing about unit tests, then I would suggest you look at the appendix, a introduction to unit testing which I attached to the end of this course of the country. Integration tests verify the behavior off either a part of a system or a whole system saying part off a system. I mean any significant part, which consists off a few units which communicate with each other. Integration tests are brittle, easy to break and hard to maintain and slow. The only one benefit is that they verify how many components interact with each other without any marks. Components air going to be tested in the environment close to the production's environment . That's why integration tests can detect defects undetected by unit tests. Acceptance tests verify the software from the user's point of view. Acceptance tests are expressed in irregular English language. Yes, indeed, they allow customers to write tests in plain English, just in a formal syntax. Off course. Customers are not allowed to write novels, but writing acceptance test is much easier than writing unit tests for customers. Written acceptance tests get compiled by special framework into unit tasks, which have to be implemented by developers. These way off writing tests allows to meet the requirements written by a customer himself. We will look into an example or a few off examples of how to write such tests in a corresponding section. You should understand that each type of tests has its own pros and cons. Integration tests are not better than unit tests, or vice versa. It wise approach of testing is to use different types of tests. Moreover, usually end up with a pyre amid of tests. Here is the firemen. There is no silver bullet regarding the right balance off different types of tests. That balance depends on the type of software you're working on. What I wanted to stress here, a part of different types of test is that TDD can be applied to all these types of tests, by the way, usually people right acceptance tests before the court. This is because of the nature of acceptance tests. They arise at the step off the system analysis, including user stories and all the analytical related stuff, though of course, you are allowed to write acceptance tests to cover legacy codas. Well, what means you ride them after the actual implementation was written? While it's possible to apply T D writing integration tests, I haven't ever done that. It's unnatural to apply. T D d writing integration tests usually will write them when everything is already implemented and we need to keep off a big part of system and verify the behavior 5. 01 Intro to Integration and Acceptance Testing 03 Integration and UI Testing: we discussed different types of tests previously, you should remember that Byron Mint of tests The most significant part of the spire mint is unit tests that integration tests and acceptance tests. Integration tests, as we discussed, verify the behavior off either apart off a system or a whole system. They verify how many components interact with each other without any marks. Components are going to be tested in the environment close to the production environment. That's why integration tests can detect defects undetected by union tests. There's also a notion off your eye tests. When are you I tests? Remember that you eye tests are integration tests. Your eye tests allow to drive the executing, often application by automatic actions performed on the why it allows to save much time. Since he doesn't require manual testing. We just dried code, which performs old actions on the why assertions in your eye tests verify what you are shows to users. Integration tests are not comprised of finally, your eye tests. Your eye tests are only a part of the sweet off integration tests. We're not going to learn the techniques off writing integration tests except you. I tests. I can't cram all the staff into a single course anyway to Manu Plate. Why you need a framework to do this? No matter. Will you write plane you eye tests or acceptance tests through why? 6. 01 Intro to Integration and Acceptance Testing 05 Why Automated UI Tests: Let's recap why we might want to write automated your eye tests at all. The major benefits off writing you eye tests unrelated to benefits off any integration tests, since your eye tests are integration tests. So here are the main benefits off. Writing your eye tests your eye tests can play a role off end toe and tests, which bring into play literally all the code layers off the application you and religious you eye tests can catch anyway. Glitches, which is very important for providing the best user experience. For example, you eye tests can catch such box like a health message doesn't appear. That button gets disabled or enabled inappropriately and so on you. I tests reduce sometimes down to zero, the amount off work that need to be done by manual testers. In case off Web you eye tests, you'll be able to run the same tests against different Web browsers such as Firefox, chrome Opara and so on. I bet you understand what value it brings to the table, especially if you're a Web developer. I mentioned that you eye tests can reduce the amount off work that need to be done by manual testers actually, teams quite often try to compare automated You I testing against manual your testing. Let's mark out some benefits off automated you eye tests over manual tests automated your eye tests run faster than manual tests, and because of that they provide feedback much faster. They also can be run at any point in time just by a couple of clicks. Executing a sweet off automated your eye tests. You ensure the fullness off your eye tests, while human beings very often forget to perform some tests even when they work with a checklist. Automated your eye tests very often served as a mechanism, which is complementary toe what manual testers do. I would say that if your development team has manual testers, the software developers or sometimes even taskers on their old can right all the automated you eye tests, which are simple to implement, leaving all the complex your eye tests, which are hard to implement in code for manual execution. In such a case, your eye test will free up human testers and allow them to use their skills more efficiently performing the so called exploratory testing. Human beings are pretty smart, and they can discover such sleek bogs, which cannot be discovered automatically 7. 01 Intro to Integration and Acceptance Testing 06 What is Acceptance Testing: in general acceptance tests are business readable automated tests. Why do we need them? There are several benefits off writing acceptance tests. The first benefit is to bring people from the problem domain. In 99% of cases, people from the problem domain are not software engineers and know nothing about unit tests and coding process. In general, they can only express the requirements in the natural language. So beat acceptance tests allow non technicians to write tests in the nature language. Not, of course, not. In the completely arbiters tile, there is a special form for writing scenarios. We will look into it shortly, so the first goal is to reduce or completely remove the gap between software developers and specialists from the problem domain. Another benefit is that acceptance tests form the documentation and what even better they form execute herbal documentation. That documentation reflects what features does the system have? How do those fissures work and what different usage scenarios does the system support? The good thing is that tests reflect the needs off the end users. What means that developers can build the right thing and build it right? Indeed, acceptance tests are Elektronik incarnation off use cases written on cards within the agile process. Another benefit is that acceptance tests always reflect current requirements. Either would keep acceptance tests always updated or ditch the whole idea completely. There is no something in between these states. Acceptance tests should always stay in sync with actual code acceptance tests as well. As any tests are backed up by a framework. The most popular framework to write and draw on acceptance tests is called spec flow. 8. 01 Intro to Integration and Acceptance Testing 07 Acceptance and UI Automation Testing Frameworks: We talked about testing frameworks earlier and I would mark out the following your eye testing frameworks. Selenium visual studio coded you. I test and test stack White selenium is a framework for testing. Web. You? Why? While V s coded your eye test allows to write your eye tests both for web you, I and desktop you I selenium and devious coded you. I test frameworks, record all your actions and generate code which replaced them. Generating the script. Selenium, however, supports another approach which is more suitable for developers. And that approach allows to write tests manually. Such tests in general are more customizable, irritable and maintainable. Destec. Why it doesn't allow to record actions and replay them. It allows to write your eye tests manually in code. But this approach takes more time, but it allows to write a celebrated said, human, readable and, well, maintainable cold. While generated code is hard to understand and maintain. And by the way, tastic white is roughly five times faster than via scolded You. I test being tested on and WP f application in this course. I'll show you how to use psyllium for Web you I testing and test a quiet for testing a WP f application 9. 01 Intro to Integration and Acceptance Testing 08 Conclusion: Let's sum up what he learned in these short but important section. You learned that there are three major types of tests. Union integration and acceptance tests You I tests are integration tests. Integration tests are brittle and hard to maintain. However, integration testing is the only way to make sure that the whole system works correctly. In general acceptance tests are business irritable automated tests. Acceptance tests reflect the needs off the end users. What means that developers can build of the right thing and build it right tastic wide is five times faster than visual studio code. You eye tests and allow to write more maintainable your eye tests. Selenium is a you I testing framework for automating websites. Let's get to the next section, where you learn more about spec flow as one of the most important tools for keeping requirements alive and always up to date. 10. 02 Intro to SpecFlow 01 Outline: Hi. This is Engineer Spark from engineer sparked dot com and was start to learn about testing frameworks from this section. This section is an introduction to spec flow and Gerkin s, a special formal language for writing business readable tests. In this section, you'll learn why you might be interested in using spec flow. What is the difference between behaviour driven development, BDD in short and acceptance test driven development or a T D. D. In short, how irregular, respectful a workflow looks like. You learn about the basic features off spec flow, and you'll learn about the basics of gherkin. At first, let's discuss, why would you want to use SPAC float? 11. 02 Intro to SpecFlow 02 Why SpecFlow: Have you ever heard the statement? Build the right thing and build it right? This is how developers should implement features. The most frustrating thing is when you implemented a feature, right? But in the end you discover that that was not a right feature. In other words, the specification off what you implemented was incorrect. And spec flow is a tool suited exactly for avoiding this kind of situations. It allows to ride high level, business readable automated tests in the nature language E g. English. Okay, let's define what is a business readable automata test. It is a test that Iran's automatically to verify the correctness off a system, and it documents the system in a way that non technical people can understand and contribute to when we analyze a certain problem domain. We almost always talked to experts who working that problem domain 99% of time. Those are known technical people or technical, but not in the field of software development, so they know what a program should do. But they cannot describe its behavior in a way understandable for a computer. As a result, we have a gap between developers and domain experts, toe overcome this problem. We need to build a bridge between these two camps in the form off a formal language, which allows to specify how a program we're thinking off to build should really work. We often refer to such business irritable, automated tests as to acceptance tests. This is because such tests become the main criteria, which helps to understand if the program works correctly a customer except our program. If all the acceptance tests pass, in other words, so there are three major benefits of having acceptance tests. The sweet off acceptance tests is a document which describes how a system should really work. An acceptance test is an execute herbal document. Really? Yes. Really. Acceptance tests are executed. Herbal weaken. Just click the button and verify the state off a system at any point in time. Feel communication gap Acceptance tests. Feeling the gap between developers and domain experts. Acceptance test is a point off agreement between developers and domain experts 12. 02 Intro to SpecFlow 03 BDD vs ATDD: BDD is about having conversations to help teams overcome misinterpreted requirements and deliver issues. BDD stands for behavior driven development Have you ever worked on the project, where the team has delivered a feature that didn't match what the product owner wanted and heard them say? That's not what I wanted. In a nutshell. The purpose off applying BDD methodology used to address that issue. It's about promoting a shared understanding between team members as earliest possible in the user stories. Life cycle. To summarize 80 d d or acceptance, test driven development is a process in which high level acceptance tests are automated to fail and then developed against to create enough production cold to make the acceptance test pass. BDD. Our behavior driven development leverages these technique along with other techniques around conversations, collaboration and automation to ensure that a team delivers would the business once this first time around 80. Didi is a technique used within BDD there not one and the same 13. 02 Intro to SpecFlow 03 SpecFlow Workflow: before diving into the technical details off using SPAC flow. I want you to understand this scenarios of how we can use backflow and when. Indeed, SPAC flow can be used in different scenarios. For example, you are free to write tests before writing production code, and no one duplicates to write tests after writing production code Spec Flow does not impose the all or nothing approach. Use backflow always when you need to improve the communications between developers and domain experts. One of the most irritating questions is. Should domain experts right acceptance tests on their own? Well, it is a logical question, since the land which we use for writing such tests is natural, though a little bit formalized. But in general, it's form is quite free and well, if the answer is more irritating than the question. In 99% of cases, no one except programmers who will ride those tests. So in the majority of cases, developers listened to customers and then write tests on their old showing the final result to the main experts. Sometimes when a customer is enough interested in the development process, it's possible to involve domain experts into the writing off tests, teach them how to do that and so on. But that is still a rare case. Unfortunately, so irregular Workflow is the following. A team of developers organized a meeting, discussed the domain and rights backflow scenarios. Domain experts validate scenarios and either approve them or send a request to change something. Then the coding process goes, and when all the tests best, the circle starts again. Off course. There are thousands off small differences between possible work flows in details, but generally this is how the process works. 14. 02 Intro to SpecFlow 06 Gherkin: Ger King is a business readable, domain specific language created specifically for behavior descriptions. It gives you the ability to remove logic details from behavior tests. Joking serves to purpose, serving as your project's documentation and ultimatum. Tests like Camel are python. Gherkin is a line oriented language that uses indentation to define structure line endings , terminates statements, gold steps and either spaces or tabs may be used for indentation. Finally, most lines and girl can start with a special key word. The bar, sir, divides the input into features, scenarios and steps. Let's walk through these example. Feature some ter, see a descriptive text off what is desired, starts the feature and gives it a title. Spec. Flow doesn't parse the next three lines of tax. You know, the two s and I want to the's Lions simply provide context to the people reading your feature and describe the business value derived from the inclusion off the featuring your software scenario. Some determine herbal business situation, starts the scenario and contains a description off the scenario. The next him in lines are the scenario steps, each of which is matched to a regular expression to find elsewhere. When you're executing the feature, the trailing portion off which step after keywords like given end. When etcetera is matched to a regular expression which executes a C shop function, you'll see how this works in a minute, taking to account the following best practices writing feature. Hatter's first think of who benefits for is interested in this feature and be specific about the who it is right manager instead of Fuser editor instead of user gamer instead of user. And so think of what is required for the future. Express Why the feature is important or valuable and no, you wire. Internal technical details do not expose them. So each scenario consists off three steps given when and then after their given step, we should set up initial state off system at the well step described action that takes place and at the then step observed and verify outcome. Defining the stabs avoid low level details. These are the high level business rules, so don't write when click on save button instead. Right when a statement gets saved, for example, following this style, you don't tied business rules to user interfaces, and this is good, since you I can change. I could dedicate a whole separate course writing off acceptance tests. This is definitely out of the scope of these course. Let's write a couple of simple scenarios for the TIC Tac toe game in the next lecture. 15. 02 Intro to SpecFlow 07 Basics of SpecFlow: to write acceptance tests using spec flow when you took properly, set up the environment and attesting project. At first, we need to install a speck flow extension for visual studio we needed because spec flow integrates into visual studio, allowing us to easily format features and scenarios and generate corresponding code and other things. You can do this by going to tools, extensions and updates online and search for for the spec flu, the installation process is straightforward. The only thing is that it will require from you to restart visual studio. I'm going to write acceptance tests in a separate project, so I'll create the acceptance tests project at first. Well, this is going to be a classic standard class library. I'll name it acceptance tests to use this backflow framework AP I. We need to install us back flown. You get package. Apart from that, when need to install in, you get a package for integration off spec flow and a union testing framework, which will be used to run tests and right assertions. In my case, I'll go to manage you get packages, and I'll install that package for integrating spec flow within unit. But at first. Of course, we need to installed this backflow itself. Here it is I stole except and spec flow and unit integration. Let's install this package a swell and this package. We'll bring the end unit to the testing project as well and do that automatically Here. You can see that he depends on the end Unit three. Everything is fine. And let's other reference to the project, which contains the Tik Tik tok game implementation the implementation in the TD d course a project, so I'll add their efforts to it. TDD course. Yep, Now we're ready to go. At first, we need to add a speck flow file. Let's add it, you item spec flow feature file and I'll name it. Tick tack toe play Tick tack to play James Feature file. It's her to ride high level business requirements and scenarios for such a simple game so we will break town beat. Let's describe a feature in order to I can remove this in order to play attic. Tak Tau game s a gamer. I want to be able to Putin crosses or no, what's and determined and Weiner. And let's describe at least one scenario the Stiner. I'm going to call it play game Given I started and you gain when I put three crosses in a row, then I should win. Yeah, I should mean why not? This is the simplest form off a scenario we can past tables, off values or constants to code from scenarios. Hero Joe's generate the C sharp code and implement the test. To generate the code, I'll click on the ride most button and click on the corresponding menu item generates stab definitions. Here you can see how spec flow is going to bind, given when, then steps to the corresponding gold so I'll generate the code. It asks where to create this year's file. I'll put it into the Acceptance Tests folder and save it here. Fine, let's go to the generated file. Here it is. Here you can see the generated testing class spec flow obliged special attributes like binding and given when and then for the steps. It doesn't matter how spec flow does this internally. If you want to learn more, you can look in a documentation how all the things work internally. Let's implement the test given when and them steps directly. Map to the corresponding a ranch actor, Sir triplets. So at the given step, we need to arrange the object under Tasked. Let's do this. I'll create a field off the game time and we can initialize it from here after the when step, we should perform the actions. Let's implement them. I'll remove that banding girl and I'll make several moves Well, for to, uh, three. So here is the winning combination. Here it is. These are the crosses and the combination of crosses. Putting the fields indexed 1st 2 and three should lead to win. Let's verify this fact at the them step. Just writing the assertion with the power off the end unit framework using the are are equal method expecting Weiner crosses as the result of calling the game. Yet Weiner Method. Let's rebuild everything and Ron the test from the test Explorer. The test explorers shoud see this test. Let's open the test Explorer. Yes, here is this test visual studio detects it Fine. Let's Saraya and the testes passing in 133 milliseconds. Great. Actually, you've got acquainted with the basics off acceptance testing in this section 16. 02 Intro to SpecFlow 08 Two Approaches to Implementation of Acceptance Tests: another concern I need to say about, Ah, use. So an example from acceptance test. Our acceptance test was implemented through the A P I off the game class directly. Well, that was caused by toe example in case of big applications with you. Why you have two ways of implementing acceptance tests by implementation off acceptance tests. I, of course, mean the code we'll write in given. Well, then phases. So what are these two ways? There are two camps which prefer to different approaches. Implementing acceptance tests, manipulating you I and the implementing acceptance tests through special high level system into faces. There are pros and cons in every approach. What about acceptance tests reading through I? The main advantage off writing acceptance tests through you I is that such tests become truly the so called and toe and tests which involve the whole system. The main disadvantage of this approach takes its roots in the comes off Your eye tests themselves. Your tests are brittle, her to ride and easy to break the way off. Implementing acceptance tests based on high level into faces is beneficial because it allows two tasks more robust, cleaner and maintainable. The unfortunate thing is that the white part will stay uncovered by tests. In this case, this is an advantage and disadvantage at the same time. In this course, I want you to get acquainted with the right tests because it's more interesting from the learning perspectives. It will teach you how to manipulate the why, while showing the other way of writing sevens test through business interfaces. Eight guys will not teach you anything special what you possibly haven't ever seen. Another question you may be pondering right now is doing need to write acceptance tests, and you I tasks at the same time. Just in case I load is that writing acceptance tests through ey is not the Samos writing you eye tests. I hope you understand that. If not, you'll see shortly the difference. I wouldn't say that the difference is so big, but you need to understand that acceptance tests written through you. I expose and express, so to speak business requirements and scenarios through you. I whereas I blame you, I tests just test the why they don't expressing business requirements and scenarios informal, high level business language having acceptance tests written through you, I and a sweet off your eye. Tests alongside is excessive and usually doesn't worth off. An enormous amount of efforts that will be spent with no doubts maintaining off to sweets off tests based on you. I will be hard as hell. Don't try this yourself either. Right? Plane you eye tests or right acceptance test through your wife. 17. 02 Intro to SpecFlow 09 Conclusion: Let's recap what you learned in this section. Spec flow is a tool which allows to build the right thing and bill it right. 80 d d easy technique used within BDD Spec Flow is a mature acceptance testing framework, which allows the writing special feature files in a semi formal language called Gherkin. Gherkin is a business readable, domain specific language created specifically for behavior descriptions. Each scenario consists off three steps given well and then which map? To arrange act, assert triplet in unit testing. To write acceptance tests, you need to install US Back Floor Extension Spec Flow Newgate Package and Spec Flow Unit testing integration package, which in its turn automatically installs the corresponding unit testing framework package. 18. 03 SpecFlow in Details 01 Outline: Hi. This is Engineer Spark from engineers bob dot com, and in this section, we're going to learn SPAC flow in much more details. Spec Flow is a quiet, bigon powerful framework, which supports many important features. You need to learn spec flow more carefully if you want. Not only just right acceptance tests, but you want to write maintainable and reliable acceptance tests. For that, we will learn a great number of topics here. Step generation in details, how to run and debug acceptance tests. We will learn about maintain ability, problems. You'll see how to pass parameters. How to harness the power off scenario outlines how to use data tables, scenario backgrounds. How to convert types. How to convert tables. How to share data between steps. How to categorise tests by using tags you learn about sculpt, execution and bindings and how to apply hooks. As you can see, we have plenty of topics to discuss. Let's start right away 19. 03 SpecFlow in Details 02 Generating Steps in Details: we already generated the steps bound to this feature file. You can see that the tax here is black. Let's go two steps and remove the given step and get back. Now let's or be able to application. And Luke, the text of the given step turned into the purple color. This color denotes which step is no generated. Let's click the right most button here l click generate step definitions. Let's look more careful in this window. The first thing you can notice here is that this window shows that Onley the given step should be generated. We have some options here, the style of naming methods, reviewing and coping method to clipboard. Let's check them. So clicking on the preview, you expectedly get the preview off the cold, which is going to be generated. Let's change the naming style. We have three styles off naming methods via a regular expression, which is the option by default through underscores and in Paschal case, let's select the second option. If you just click the copying methods to clean Bert and go to the steps file, you can just based the generated method. It's not going to copy all the methods only those which are not bound in this case, the given step. You can see how this method is named. It no longer uses the regular expression seen tax the name off such a math. It starts with the step name, then underscore. And then all the words from the description off the step, separated by underscores. In my humble opinion, the regular expression style is better, since it's more readable because you see the regular tax, the redness usual. Now, if we get back and rebuild AB, you'll notice that the text off the step turns black. The last option is the Paschal case naming. Let's look at it. I'll get back and remove the Given stab Islander Building AB. All right click here generates step definitions. I choose Basco Casing. If you click on generate spec, Flow suggests to regret the whole file. That's why we want to just copy one method to the clipboard. And here's how Paschal Casings Tile looks like it starts with the step name and then the text off a step in paschal casing without any symbols such as underscore. And that's all you need to know about bindings with SPAC flow so we can implement this givens tab and let's get back and revealed and the binding works correctly. 20. 03 SpecFlow in Details 03 Demo Example Overview: for demonstrating the main features off spec flow. I decided to take a simple example from my course. What's new in C Sharp six and seven, where I demonstrated the features off C. Sharp six and seven. Here it is. This is the character class, which has a time type is an enumeration, which contains two items. Orc or else a character has a name where a farmer and health we calculate their defense here like this. If where is greater than armor than defends equals zero. Otherwise, armor minus where a character is dad. If it's health is equal to zero or less, character can be damaged and the damage is calculated like this. Subtract defense from damage and subtract of the result from health. The default where is equal 15 and health is equal to 100. Let's write a bunch off acceptance tests for this class and learn of the major features off spec flow 21. 03 SpecFlow in Details 04 Writing the First Test: Let's create a feature file for writing acceptance tests. I'll go to Solution Explorer and add you item. It's going to be a backflow feature file in English, and I'll call it character, not feature. Okay, And now we can describe the feature. It's going to be playing a game, he noted. To play a game s and gamer, I want to be sure that Carrick T ray sticks often character. Our Cal kill related correctly. And now we can write our first scenario. No damage in case off. Zero hit Given I'm in your player when I on God, he'd by zero. Then my health should stay equal 100 like so, Yeah, so in case off zero heat, the health should not be changed. Let's generate the steps. All right, click here. There'll click on generates step definitions and then click Generate. And I'm going to store this file in acceptance test folder and I'll name it playing a game steps. Okay, let's go to the newly created class. Okay, The steps have been generated. I don't want to explain. Right now. Weiss backflow passes parameters here. I'll just fix that for a moment. Isla revealed the app the steps are bound. Okay, By the way, I want to cover one important and simple feature right away here before going further. How to leave a comment in the Fisher file. Everything is simple. Just start from a sharp character and then write your command like so very important. Important comment like this. Okay, lets go further. Now we can implement all the steps so I'll get back to stabs, given I'm a new player. So let's create here character like so let's instead initiated in the givens tab equals a new character like this passing, for example, health when I got heat. So character dot Kate Fasting zero hand lance assert Here in the unit framework of that character, health is equal to 100. Great. Let's look at how we can Iran and D buck acceptance tests in the next lecture 22. 03 SpecFlow in Details 05 Running and Debugging Acceptance Tests: I'll quickly demonstrate you that you can run and debug acceptance tests as irregular unit tests. At first, I'll rebuild the app and I'll go to tasked. Oh yeah, we have the test Explorer right here, actually, and he discovers to acceptance tests I can right click here and click Ron Selected tests and all the tests pass. That's great to debug our acceptance tests. We have two options. The first way is to put a break point inside generated steps. Right here. I'll put break points and now we can debug the test. I'll go to test Explorer and I'll test around this test clicking on debug and we're each and break point s usual. I'll press of five. We hit the following break point and click again and we reach the van. Step everything as usual. Okay, I'll stop debugging. However, we have another way of debugging acceptance tests. We can put break points right in future files. Let's try to do that. I'll go to character feature, and I'll put the break point here on the ones tap pressing nine. And now Al debug the Task T bog. And as you can see, we reach the break point right in the feature file. And now if I step inside by pressing F 11 I get into the implementation off this step. So everything is pretty simple. By the way, let's prove that our test will fail. In case it is written incorrectly. I'll stop debugging. And for that I'll change the then step, let's say 99 and I Laurent for the task. Indeed, the test fails. I'll revert the implementation back and around the test once again to make sure that it works correctly. Great. Okay. These is how you can roll and debug acceptance tests. 23. 03 SpecFlow in Details 06 Adding new Cases: Let's add a couple of tests here before moving further in learnings Backflow features. I'll add two new scenarios. So the first scenario is going to be the following health calculated correctly. So, given I'm in your player when I got here by 60 then my health should be equal. 50 um, should be equal 15. Do you to the fact that I have are more and the where characteristic, all for that armor and in others in there, I'm going to name it. Too much damage leads to leads to death. And given I'm a new player when all right, God, he'd buy 110 then player shoud the dad like so and last generated step definitions. I'll copy methods to clear Bert, and I'll go to the implementation of steps and based here. Call the methods generated by Spec Flow, and I'll fix for now a little bit. What's backflow has generated for us. I'll explain what it generates a little beat later, so I got heat by 16 and by 110 and let's implement these stabs. It's going to be character heat by 60 and the same goes here by 110. My health should be equal 60. Oh, I mean 50. So I'm going to write here. That surgeon, we expect 15 calling character health. And here I'm going to call. Assert is true. It is true that character is that block. So all the steps are implemented. I'll get back to the character feature all I rebuild the application to make sure that all the steps are bound. Okay, It seems that all the steps are bound correctly, So let's run all the tests and all the tests. Bess, that's good. Let's move further. 24. 03 SpecFlow in Details 07 Passing Parameters: If you're a seasoned developer, then I bet you know how harmful duplication ca NBI duplication infected our scenarios and generated steps indeed. Look at this. Look at the implementation of generated steps. The only difference between when steps here he's the number being passed to the heat method . Yeah, I see the duplication in the van steps as well. We have here a surgery goal, 15 character health and here a sort article 100 character health. Do you remember House backflow generated these stabs at first spec Flow generated specific descriptions with placeholders in round brackets with a dot and the star. Let's change one off the steps, for example. Less re factor our wen steps when I got heat by dot star like so and damage and I'll pass here the damage I will remove these method. These is the same and then my health should be equal. Let's refectory it out as well and health Hells and let's remove this and let's for a factoring a little bit s well, not sure abstain, but we can should be equal 100 to make these scenarios similar. So I also changed the description off the then step here. And if we rebuild the application now, all the stabs are bound as you can see no text in purple. So these placeholder allows to pass a specific value into the test from the scenario. So as a result, as a result of Farrah factoring, we use here the same step implementation for all the scenarios. And this is true in this case regarding the wen and then step except this one, because we use here not to the health property, but we use here the is dead method. So this code is thrives shorter than before, and this is house backflow can pass parameters to methods. That's good. Let's run the tests to make sure that everything works and all the test pass that's great, by the way they seen tax off passing parameters is different in other naming styles. I'll show you how it looks like in case of underscores and paschal casing. For that, I'll remove the well step and try to regenerate it. I'll remove it. Uh, build the AB. I got hit by turned purple, right click generate step definitions and I'll choose Method name underscores couple methods to clipboard, and you can see here that the name off a parameter in case we bind these method by using the style with underscores is being put in the end. It is called P zero right now. So if I call here character, don heat passing thes parameter, everything should work. Yes, expected indeed. And if I remove these when step to rebuild the app and regenerate the step definitions using the Paschal casing style copying methods to play bird, you can see that the way of passing the parameter he is roughly the same. We can, of course, rename it to, say damage like so. And if we run no, the tests, all the tests best. So this is how you basically can pass parameters using spec flow. So there are three ways. The two ways with Paschal casing and the style we've underscores is roughly the same. It is based on passing parameters, denoting them by saying P zero and P one best another parameter. And when you use the naming style by default, which is based in the regular expressions, you should use such a placeholder. And in many cases, spec flow generates this place holder on its own, so you don't need to do anything except naming the past argument in a well irritable fashion 25. 03 SpecFlow in Details 08 Scenario Outlines: previously, we eliminated the duplication at the side of steps. However, if you take a look at the feature file, you'll see that the only difference between our scenarios concerns input and output values . The meaning off these scenarios is roughly the same. For such cases, spec flow provides similar outlines. Would you describe the same basic scenario to be executed multiple times each time with different test data so we can remove duplication between scenarios using scenario outlines ? Let's look at how this feature works. At first we need to define a more general description off multiple duplicated scenarios, declaring the singer outline, Let's do that. So I'll say Sendero outline. I'll name it heating player. In this case, I named it heating player, and after that we should declare, given when and then steps as usual except one difference. Look at this, given I'm a new player when I got he'd by damage, and the value will provide us damage. We need to wrap in angle brackets. You can see that and and then I say, then my health should be expected. Health expected health is also in angle brackets. The syntax allows us to pass at least off arguments by specifying a table off values. For that, we need to define the example section examples leg of this To define a table, we need to define columns damage and expected Hells so Well, we he'd by zero the expected health should be 100 16. 50. Take a look. Once again, we now have a scenario here which will be called by tests Runner a sling. At times as we have records in the table. In this case, the writer will execute this test passing zero as their matured 100 s expected health and the second time passing 60 s damage and 50 s expected health. Okay, so which scenarios? Now we can remove. We can remove these two scenarios. I'll commend them out. And let's review all the app build succeeded. And if I go to test Explorer, you can see that these test with scenario outline is displayed here as actually two tests. There are two test cases, So let's around our tests off course. We need to generate the steps for these test al copy methods to clipboard. Oh, actually, now I see the events tap was not bound because it differs just a little bit. Let's rebuild the app. I just removed it equal the word equal. So now everything should be bound correctly. And indeed, all the tasks best great. So everything works as expected. These sees a very cool technique which allows to reduce duplication, keeping feature files as short as possible. Okay, then let's add another record to the table, just in case. So when we heat by 18 they expected health should be 30 lattes. Wrong. The Tet. Let's rebuild it just in case. How many test cases now? Three. That's great. I'll run all the tests. Not only this one, with three cases and all the tests pass. Everything works as expected. Good, let's move further. 26. 03 SpecFlow in Details 09 Passing Data Tables: before moving further. I want to tweak a little bit our character class. So I'll go to that. The character class. I'll add here and in, um oration named Spell with three values. None Green block and dark spoil. Okay, I lead here the corresponding property off police in admiration type Name spell without any proper encapsulation and I'll tweak the defense proper. Teen. I'll turn expression body too, a regular property. And now the defense will be calculated a little bit differently. So this is going to be an intermediary Result. Oops into juror. And if spell equals green block because then we end 25 to the defense and IV spell is equal to dark. Spoil. We subtract 10 and no, we can return the result. So we've the result is less story golden zero. Then we returned. Zero. We don't need to return negative. Well use. And otherwise we returned a result. Okay, so let's try the feature off passing tables from scenarios. Okay, So for example, we may want to check that spell and armour. Where have influence on damage. Let's write a scenario for that. I'll go to the future file and ride and use in there so spell and are more aware, have influence on damage logically. And now let's start with the steps So given I mean, you player and I have the following have the following let's say properties. I want to pass more than one value in conjunction. And for that I need to pass a table of values. Uh, say prop value where 13 spell green block like so And no, we don't need another end here When I got hit by 30. No, by 18 then my health should be 45. Okay, let's generate steps for this scenario. Generate step definitions coping methods to clip Bert, I'll go to the steps file two band and paste then given step and you can see here that we need toe work with the table class provided by spec flow for retreating our values. We need to dig the table in the following way. So let's get back. Yep, we pass here two values 30 and green Block 30 s the where and Green Block has the spell. And you can see here the syntax off passing this table. Yep. And in such a case, spec flow generates a special binding passing the table. So I'll say String where and axes the table table arose. I'll use the link extension first. Passing the following Lambda Grow prop prop is the name of the column. So if the value in this column physical to where I want to take the value from here like so and I'll copy these line renaming here the name of the variable to the spell and we're searching here for this spell. All the other things remained the same and seems this is the given step. Let's create a character here and not a character player equals new character. Yeah, by the way, of course, we need to very wry it here, the glass field named character. Of course, I don't need the local variable. So character dot where equals let's bars, they wear string, character and dot spell equals. I'll cast the result off, you know, off in him that parse to spell. Yeah, I know Alina parses a cumbersome method like so. So we iterated over the Rose by calling the link extension, searching for what we need and finally retrieved vendors. And actually, after that, we need to convert strings into certain types and If you're a seasoned developer, I bet you understand that the so called string Lee type code is extremely ugly and dance to become very bagging. I'll show you how to fix this problem. Of course, at this time I want to just verify that our tests work by running them. Let's revealed the EP on the lads. Go to the test Explorer. Let's run all the tests and all the tests pass. Everything is fine. That's Bess. Okay, let's move further in learning spec flow features. 27. 03 SpecFlow in Details 10 Scenario Background: Another cool feature of SPAC flow is called sin Era Backgrounds. This feature allows to gather duplicated, given steps to a common section, steps withing. The background section will automatically be executed before each scenario or scenario headline. You can see here that we have too many duplicated given steps, which are absolutely identical given a menu player. Given I am a new player giving them and you player, they all say I'm a new player. If all this in errors share the same given step, we can create the background section like this back ground, given I'm in your player, and now we can remove all the given steps from all the places which are the same. Of course, now, if I put a break point inside are given method, you'll see that it will be called as many times as many scenarios we have here. So I'll rebuild the APP. I'll go to test Explorer and debug selected tests, and we reach with the given step oppressive five, and to reach it again, I'll press the five and Richard once again oppressive. Five. We reach it again, so, as I said, it will be called before each scenario or scenario road line. Okay, I'll stop debugging. I'll remove the break point. Go to Test Explorer and Iran. Its usual to make sure that everything works without debugging and all the tests best. So this is another feature which helps with improving the maintain ability of the feature files. 28. 03 SpecFlow in Details 11 Converting Parameter Types: Let's look at how conversion to in in admiration works. Do you see here that the given step actually contains information about the type of the character type? It says that we're testing an elf. So until this moment we created elves implicitly because we do not say anything about Elf's here in the given step. But explicitness is very good for readability, so we could explicitly state that the given step accepts the type and admiration for that. I will say here I'm a GNU player off elf type. Then I'll get back to the steps and I'll tweak a little bit the regular expression here by using the placeholder like this. And now I'll add the enumeration is the argument, and I'll pass it here like so and let's to rebuild to the APP. Okay, it turned it italic, so it sees that this is a parameter. And now if I go to test Explorer and drawn older tests, all the task steel pass. So it means that everything works as expected, and the Elf string from the future file gets automatically converted to the in admiration type. And as I said, I'll show you a little bit later how to write custom conversions 29. 03 SpecFlow in Details 12 Converting Tables: the previous experience with a table was frustrating. We ended up with a weekly type code. What is always bad in the world off object oriented programming. Generally, we have two options to remove weak typing here. The 1st 1 is to create a separate class, which describes the table values. I'll show you how that works that first, let's create a glass, uh, created right here, and I limit character info, and it will contain two properties. The 1st 1 is of type into Gold, where get set and another one off type spell, which is an, you know, cold spell. Not surprisingly, get set. And now we can call the generic create Instance method on a table. I'll command these two lines out and I'll call table, create instance, like so, passing the characterising full ASA type as a genetic type. And it's going to be the characterising full. And now we can remove parsing using in four directly and spell we can use directly as well . We don't need any parsing here, and let's verify the correctness of this code by running tests, and I'll actually put and break point here, and I'll debunk this test. Actually Let's run all the tests and be a debugging, and we re just a break point and you can see that the instance here he's the character in for type, which we just created. The spell is green block, where equals 30 and everything works fine. I'll press of five and all the tasks best. This approach looks not as ugly as the previous. While, of course, I would even say that it's hard to compare them with the second ways way better. The only disadvantage of this approach is that we create an additional data structure he up in the character in For In this case, there is another approach, a dynamic one to rely on. Dynamic creation. Winnetou Installing you get package at first, which is gold SPAC flow s East dynamic. So I'll go to Solution Explorer and I'll go to managing get packages and I'll browse for spec flow dynamic. Here it is. Spec flow dot ss dot dynamic islands Tallet Okay, let's rebuild the application just in case everything is fine on now. We can harness the power of dynamic object creation by calling the create dynamic method. So, uh, commend this out and here's another way of doing this dynamic info. Equal table. Create a dynamic instance like this With this approach, we don't need to create any additional data structures so I can commend this out. Yep, In the real world, I would remove this cold just entirely, of course. So let's reveal the app and let's run the tests to verify the correctness of the code. I'll put a break point here and debug all the tests, and we reached the break point. And if I hover my mouse over these variable, the dynamic one visual studio says that it is of type expand our object. Indeed, Edie's a special type served by the dynamic language Run time or dlr insured. If you're not aware off how dlr works, then I would suggest you to take one of the C sharp advanced courses where the topic off dynamic feature East covered in details. So where it was 30 spell is green block here and everything works as expected. Not exactly. Ah, the thing is that ah, around time buying Their exception has a cured and it says that it cannot implicitly convert type string to spell. So yes, actually, in this case, we need to use here. The not bars. The type off spell like this and Blatt's debug our tests once again. And no everything works fine. Yes, indeed. All the tasks best good. Now you know the better ways of dealing with tables. Inspect flow. So I would suggest you to always use either create instance or dynamic feature to work with the table instead off relying on strings. 30. 03 SpecFlow in Details 13 Converting Tables to Sets: previously, our table represented a plane structure. But what if we want to work with the least of vitals? Imagine that our character Glass can have several weapons. I'll go to the character class. Look at this. It has a list off weapons. I'll go to weapon and the weapon class contains three properties. The name price and power. And let's say we heaven method, which allows another character to steal a weapon like this public. Avoid steel who happen W. And I'll remove here. The weapon searching it by name happened on name equals Dahlia name. And now we want to write a test in our future fund. Let's go to the future file and listen area. We're going to test his the following. It's in there. Oh ah, Character can carry on weapons given I'm a new player or felt type and I have the following weapons on. Let's define the columns, name, price and power and it's going to be a knife. It costs 100 the power is 50. And let's say it's going to be an axe. 215 cost 16 and let's say have pistol, which costs 1000 on the power is 100 the most powerful weapon. And when I got robbed on knife, then I shoud have only two weapons. Let's generate the yet absent steps. Um, generates step definitions, copying methods to Clippard and let's go to playing in games, taps and paste. All this stops here again. We're working with a table here. Yep, But this time we cannot just call, create instance or Cray dynamic because they do not return a set of values to create a set of values who have two options. Call the create sat lethargy and called the Crate dynamic Set Mattered, which is exposed by the spec flow, is his dynamic library. In this case, we already have the weapon class. So create set is a pretty effective and straightforward way to go so we can implement the given step like this. I innumerable off weapon weapons equals table dot create said off weapons, and now we can call weapons and add range to addle the weapons, like so so create SAT returns and I innumerable, and that's what we need. After that, we just had all the weapons to the least off weapons seemed the character object. If you do not have a dedicated data structure like in this case, I'm in the weapon class. Then you may want to consider to call the create dynamic set method. So I'll come in this out of our weapons equals table dot create, dynamic sat like so that the only thing is that in such a case, if you need to perform a conversion between types, then you'd have to perform it manually like this for rich weapons, our weapon and character dot weapons dot ad you weapon and passing all the values directly and explicitly like this. If you try to cast a dynamic object to a state IQ one through the ass, keyword or just casting directly, you'll get an exception instead of what you warned. So this is why you need to create the weapon, object explicitly and let's implement the remaining steps so when and got robbed on life, I just need to call the character Doc Steel. And by the way, let's introduce here that placeholder because I want to accept here a parameter off string cold weapon name passing it like this. Oh, it seems like yeah, that's take here he name instead of the weapon object. Okay, then it should compile, allow it compiles and let's right here. The assertion a certain Eric will we expect to s a result of calling character. Where happens? Weapons dot count? Yeah, Everything is straightforward here. We still one weapon and then assert that only two weapons should remain. I'll put a break point of the Crate dynamic set method here. Who, by the way, Oliver, back this change and I'll put a break point here. I'll go to test Explorer and debacle the tests. And where is the brake point? I'll press have 10 and you can see that the type of weapons is off by Lou Maribel Off. Expand object Time again. That expand object type. Okay, let's look at the results off the test, I'll press a five and all the deaths best. So this is how you can work with sets off data using spec flow if you have. If you already have a class which represents an item off the sat you want to create, then you'd better to call the create set directly. If you don't have such a type and you don't want to introduce one, then you can try to work with the dynamic sat by calling the create dynamic set method 31. 03 SpecFlow in Details 14 Custom Conversions: previously, I said that speck flow supports custom conversions. Indeed. What would you do if you have to pass an integer and converted to date time? Well, you could just taken integer in your step method and convert that integer inside the method . However, this is not the best way to go. In case you need to perform such conversions in mainly step files, for example, you need to come up with a stated conversion class at best. But there is a better way. Let's doing Street that at first let's assume that our character class ah, should expose a specific property. Let's assume that our character should eat periodically, and if a character didn't eat for three days, then it receives double damage to simulate that, I lead a some logic to the character class, so it's first I'll add and other property. Asai said he is going to be a public daytime. Eight. Last time. Get set Island Stan shaded in constructor um, tank. Last time equals in daytime that now like so and I'll expose and private method actually not exposed. Implement Private bull 83 days go and I'll return with the following expression. The result of the following expression date time. No. Now don't date. Subtract eight less time. Get the difference in days is greater or equal three. And let's change the implementation of the heat method a little bit. Eso ive eight if 83 days ago is true than damage. Multiply too otherwise damage. So we have and a little bit more complex turn their operation here Actually the nested one Okay. And now we can ride the acceptance tasked to cover these functionality. So I'll go to character feature and writing your scenario Sin, a room hungry character receives double damage and given oops given I mean you and you player off elf type And I didn't and I didn't eat for three days When I God he'd buy 40 Then my health should be equal 2 40 standard elves Armor by default is equal tam because the default armour where is equal to 15. So in normal circumstances, that elf would be damaged by 30 because 14 minus 10 equals 30 and in this case it will be damaged by 60 scenes. Our character didn't eat for three days, so the final health should be equal to 40. Okay, let's generate of these steps generates DAP definitions, coping methods to clear bird Oops, and I'll go to the end and paste it to differentiate this step from other cases. When an Inter Juris passed, I'll include the days word into the round brackets like so and I'll I want to take here the daytime instance eight last time. But off course, these won't work until we roll out a custom conversion and to roll out the custom conversion, which detects such a placeholder with included Days, Word and the retrieves an integer converting it to a datum value. For that, we need to create a separate class where we're going toe hold custom conversions so I don't go here and I say public class custom conversions and to make it visible for a spec flow winning two decorated by the binding Attribute. Binding attributes. Let's move it to a separate file. Okay, and now we can implement the conversion method. Let's say public daytime, since it should return the daytime instance and I'll name it end to date term, and it accepts an integer named days. A speck flow will not call this method until we market by the step argument. Transformation attributes with a correct regular expression. So let's market by that attributes. Step, argument, transformation. And we need to pass inside a correct a regular expression, and it will look like this slash D plus so it can contain more than one digit and days. Yep, like so. So this regular expression means that we're searching for a string, starting with an integer followed by the days word. And now we can ride the actual implementation in return date time dot Now that date dot subtract time spent from days passing our argument here and let's get back and implement of the step that was generated previously. This one, we said to the eight last time property using our argument and seems like everything is ready for casting. I'll put a break point at of the step implementation, and let's debunk the newly created test. Where is it? Here it is, the box selected test and we reach of the break point. And look at this. My current date. He's October 17. So as you can see, we have a date time here, calculated as expected, it points out to date. Three days ago, I'll continue execution pressing F five and look at that of the test has passed. That's great. Actually, we're not obliged to provide a regular expression to a custom transformation step. I would say that we need to do that if we really need it. However, we can harness the power of custom transformations in another way. Let's look at the old case we covered, which concerned the influence off spells on damage. Where is that step? This one? In case you already have a class which represents data that you need to get as an argument , you can replace table by the type of that glass. And for that you'd have to write a custom conversion before writing a transformation. Let's command out of the previous example and re righted so I can just command it out and right and other implementation, which is going to be much simpler public roid um, and natural copy into paste the name of the Mass. It is going to be the same and actually the answer, but is going to be the same. A swell. But at this time we will take the character info directly, and actually, we have this class here. I'll commanded well uncommanded. And let's move it to a separate file. Okay, I'll get back. I'll call this argument in foam and weaken. Just set where and spell without any casts. The remaining part is to implement a custom transformation, and for that we can just implement it directly. Yes, but this Let's go to custom color versions. So I'll say public. It should return an instance of character in food, and I'll name it table to character info, and it will take an argument off the table type. And, of course, we need to apply a step argument. Transformations toe arguing transformation without and your regular expressions in the last return table. Create instance off character in full. When's backflow sees that it needs to pass a table, but your step method signature requests another type. Spec flow will search for custom conversions, and in this case it will see that we have such a method. Just by investigating the signature off our transformation method off course going this way , you can transform a table into a set of data, for example, not only to a concrete class. In short, it is a place where you can insert an arbitrary code which transforms one type to another. So it's up to you how to implement a custom transformation. Let's put a break point at the step. We have changed and lads debug, uh, debug all the tests. And no, I'll remove this brake point of five and we reach the break point we need so you can see that we have an instance of character info with correct values. So the transformation works as expected. Great. I'll press of five and all the tests pass. So this is how you can harness the power of custom transformation since backflow. 32. 03 SpecFlow in Details 15 Sharing Data Between Steps: you've seen that we shared the given step between all the scenarios implementation off the given step. We create an instance of the character type in all the other steps. We just use that instance, this one we don't share here the same instance, actually, because before executing each scenario, SPAC flow runs the given step again and again. This one step this one thus recreating that instance from scratch. Sometimes you face the situation when you need to share some data between steps, and I would recommend you to avoid such situations. Actually, by re factoring, send other techniques which allowed to avoid sharing data because share data very often leads to box anyway, if you have to share some data, you have a couple of major ways to do that in SPAC flow. The first way and it is the way I wouldn't to command you at all is to use the special context objects provided by SPAC flow. We need to inherit this class from the steps Claris, and if I tap these go on text, you can see three context members called feature context, scenario, context and step context. A context is a lot object which stores. Data spec flow provides three levels of contexts. The most useful is scenario context, which lost to share data within a scenario. Fisher context persists for the duration off the execution off an entire feature, whereas sin their context. Onley persists for the duration office in error. Remember that the narrower the context is used, the last chance you'll introduce a bog. You have two ways off working with a scenario context, either through scenario context that current, like this scenario context, that current, for example, health equals character hills. In this case, I want to keep the health shared between steps within scenarios we access here a dictionary adding a key value pair. And one of the major drawbacks of this approach is that scenario context that current is not threat safe in the modern world, we tend to run tests a synchronously what means that they have to be isolated and threats safe. And if you want to access that dictionary in a threat safe manner, you can work with it like like this. Well, commend this out heat would be better to get back and use senior context. Calling it at this hills Care turned on health. Like so, this is a threat Safe off access ings their scenario context and another drawback with this approach is that we work here with a week type because values in a dictionary are stored as objects, off type object and actually keys are strings. So to retrieve them, he will need to cast them at some point in time, passing a string a key. And here is an example. For example, if I want to access it here, then I would need to scenario context, trying, get value, passing, that string, the key out and health like So let's say the bag ride debug right line health like this and the cast will be performed inside the tragic value method, of course, and by the way, keys, air of string type what is also not very good? As I said from the maintenance perspectives, however, we have another way of sharing data through the so called context injection. Let's say that we want to share the same given step between all the scenarios. For that we create a separate class for holding the givens tap, and actually we will inject a context, object there to hold any data we want to share between scenarios. So at first I'll create a context object. I'll go here and I'll say, public class character context and it will store public character, character. Look at set and the shared data between scenarios is going to be the health property, God said shared between scenarios. And now I'll create a separate bound class move character context to a separate file, so I'll create another class decorated by the binding attributes. I'll name it Common character stamps inherited from steps and I'll define here that private read only character context text of the constructor Everything is fine. Spec flow will provide any instance of the character context class created via default Constructor. The only thing we need to do here is to write the given step for initializing the character objects. So oh, define here A method public world given, uh, and you and you, player, which takes time and when you to cover it by the given Yeah, tribute and pass a regular expression. I am you, um and you player off Everything s usual the placeholder off type and let's initialize here the context character de closing you character passing the type and let's initialize the health equals context dot character and a health like so okay to work with the context, we need to inject it into the steps. Class. Yes, well, so let's get to the steps Class Cand off course. We need to command this out. We don't need it anymore. And we don't need to The character class a swell here that the field, I mean and let's different here. Private read only field of type, character context, context like so And that's great here. And constructor, which takes the character context instance and initialize the field like so. And we also have to fix all the references now. Yes, so we need to replace character by com text dot character. Okay, Now you can access the health property in any place you want at any point in time. For example, here, contexts, dad, health. Yep. No problems with that. So this is how you can share steps and the data in a strongly typed manner by using the context injection feature off spec flow. Now, any step can access the character context instance and very sad. The health, for example, to we can set said it here said it when said it, then anywhere you want to share the data with in Essen era, of course, you can add other properties. Maybe you don't want to share the health. You want to share another data between steps within a scenario. No problems with that. Just tweak the character context. Remove health or just at another data and right values to eat and read those values from any step within a scenario you'd like so you can do it. Ask you want to? 33. 03 SpecFlow in Details 16 Categorizing Tests by Tags: Actually, I forgot to demonstrate you that everything still works after introducing off the character context. So if I go to test Explorer and Ronald the tests, let's look at the results. All the tests best, so everything is fine. Okay, any testing framer provides the feature off grouping of grouping tests. I mean, for example, and unit exposes. The category attributes, which can be applied to any union test tests under the same category, can be grouped by user interface in visual studio Spec. Flow is not an exclusion from the rule, and it also supports that feature to group tests. With SPAC flow, you need to cover tests by tags. Let's look at how to do that. One of the common cases is when we need to separate long running tests from fest running tests. Let's pretend that we have a couple of long running tests here and mark them by the long running tag. Uh, I'll go to character. Fisher and ah, go here, and a tag starts from the at sign, and then the name goes so lung running. And let's say that the scenario is also long running. Okay, now we can rebuild a solution bill succeeded Open test Explorer and we have a grouping button here here two years which provides several options and to group by categories or traits. Click on the corresponding menu item and you can see that we have our two tests marked by the long running tag here. Now we can run on Lee these to test separately without necessity to select them manually each time. We need to run exclusively these tests. So I'll around them and you can see that only these tests are running. So in they pass. Okay, Spec flow supports a special tag called Glory. Well, I bet you can guess. What does it mean? The glower tag marks a test which will be excluded from the tests which were queued for execution. For example, I'll mark any off our tests by this special tag, for example, of this one, ignore like this. And now if I rebuild the app and go to test Explorer and and if I run all the tests, you can see that the test marked by the glory tag was actually ignored by the test runner. You can see a special a symbol here, and actually, if you glower test toe often. Remember this, please. Then these may be the sign off. Badly written tests, if once ignored, a test tends to be ignored forever. Strive to ignore tests only temporally and fix them as soon as possible. So this is how you can differentiate business tests Using spec flow. You can apply texts with any meaning like long running or whatever you want. This is up to you to split test by categories. 34. 03 SpecFlow in Details 17 Scoped Execution: there is another way of differentiating tests. Execution, apart from adding tax. But just from another angle. What if you have the same bound method? Two steps in different scenarios, But you want to specify another behavior for that method for particulars taps in particular scenarios. Well, it might sound vague, I know from the first side everything gets more clear in practice. So let's look at our code. I'll open the steps. Um, where are the steps yet? Playing a game steps when I got heat, whereas they are when I go to heat method. Okay, here it is. I'll remove it for now. You can see here that we have a single when and got hit method, and if we go to the Fisher file, we will see that we have more than one When I got heat steps, mania steps what? I got heat by 110 by 80 my 40 and so on. It means that several steps from different scenarios are bound to the same method. And what if I want to have another method for that step in scenario? Smart by the long, grinding tack, Let's go to the steps implementation file. If I just copy and paste the when I got hit method and rename it by the way, to demonstrate the Fisher I want to to demonstrate. Um, I need to convert the Wen's tap two method marked by the attribute to which the regular expression is passed. So I'll go here outer Beeld, um, copy methods to clipboard. Here's the implementation hopes, of course. Okay, so Context Dodd character dot health apps hit p zero. Let's rename it to damage. So if I call paint paste this method and just rename it like so let's rebuild the APP. And if I now go to test Explorer and run the tests, you can see the problem here. He says that there is an ambiguous step definitions found for a step and here a swell and hear us well because it care. It cannot distinguish these tumor thuds, but the thing is that the binding is the same. The actual name off the method doesn't make any difference, because now I use the default binding by irregular expression, and this is exactly the case when scope bindings come to the rescue for scoping and method . We need to decorated by the scope attributes scope, and you can see that actually weaken scope, execution by feature, by scenario and buy a tag. And in my practice, the most common way of scoping methods is through tags. In our case, let's pretend that I want to scope this method by the long running tag. So I'll said the tag too long running like this. This is helpful when you need to perform something different for the same step in difference in theirs. But, as I said, Different, shaded by some criteria in this case by attack and before executing test, I want to show you how you can dig the information about the currently executing scenario for treating such information. You can call the scenario context current scenario in for property. Let's ride to the debug window. Some information about the currently executing seen there Anti Bagdad right line, Senior context Dark current dot scenario info Let's say, let's longer the title and last log the Ted in this case, the 1st 1 I know that the only one tag has been applied and before and before debugging the tests. Of course, I need to apply the win attributes as well. So now I'll go to test Explorer and I'll deep boggle the tests and we reached the break point of 10 of 10. Let's look at the output and you can see that the current scenario for title wasa spell and armour, where have influence on damage and the tag is long running so you can see that information is being printed out about the currently executing scenario. Yes, we expected. On this method is cold is scoped by the long running tag, so everything works as expected. You also can combine scope criterias. If you have more than one setting for scoping, you can apply logical end and or if you said tag scenario and feature in a single line like these ill show you somewhere down here. So if you do this like this tag name and then you also said the scenario scenario, name and feature future name. But then such a method will be called only if all the conditions are met. By the way, you are not obliged to settle the three older three settings as you've seen a minute ago. We just set the tag eso you're free to combine as many settings as you like in the order you like. And if you set the same settings in multiple lines like this X like this, of course you applying to some kind of method, then a such a method will be called, if any off these conditions is mad, at least a single one. So multiple lines work in a way like the logical or is applied to an tributes. Beware that excessive using off this feature off scoping leads toa unmaintained herbal cold since code executing paths become inter tangled between HR lor. So in practice when you need to separate steps by logic, it's better to express it explicitly by writing such a special step differently in the future file and as a result, come up with a different binding rag axe and going this way, you won't need to introduce scoping. Always consider this option before applying scopes. 35. 03 SpecFlow in Details 18 Scoping and Workflow: Very often you start to write an application or a specific feature by writing acceptance tests. First, this is called acceptance test driven development. 80 D. If you already have a bunch off acceptance tests, you would not be able to just run all the tests. Since you would always see some failing tests, what would irritate you? Believe me, you'd have to apply a tag and then group tests by traits. This is actually a possible way to go, however, using one trick with scoped bindings. You can cover this particular case in a more beautiful fashion, making things more more explicit. Let's get back to our tick tack toe play game feature. Here it is. And if I just wrote the feature file like this one, let's pretend and I want to exclude it from execute herbal tests and at the same time market by something explicit. I can mark it by a tag. I'll take it by a waiting review. For example, if you mark a feature filed by a tag, it automatically get inherited by all the scenarios. If I want to make it pass without implementation, then I need to implement a special scope binding for that, I'll create a separate class. Let me do that, lad. Your item. It's going to be that class and I'll name it waiting. Review steps. It is going to be a public one. And let's apply that binding attribute and let's apply the scope. Let's go buy a tag and waiting review. Analysts do the falling treek I'll exposed here Method named Stub and I'll decorated by given attributes like so and when and when. And then Uh huh, move all down Used directives. Okay, And now if we around the whole suite of tests, all the tests marked by the awaiting review wheel pass. So the normal workflow will not be spoiled by failing tests, and other team players will be available to search for tests that need to be reviewed and so on and so on. So, for example, if I go to the tick tack toe, a playing games taps and I'll let's say I'll, uh, I'll command the whole file. Okay, let's revealed it. Oh, yeah, of course. We need the enclosing part. Let's rebuild it. And now if I go to test Explorer and run all the tests, all the tests past, including the test from the U TIC tack toe playing game feature. So this is one off the special cases when scoping can be really helpful. Off course, there are different work flows out there. Some teams may prefer to keep tests failing and red until they're reviewed and implemented . However, it depends on the workflow off a particular team, so feel free to use the feature off scoping if you're really needed. 36. 03 SpecFlow in Details 19 Hooks Overview: any testing framework, such as a unit testing framework, lack and the unit provides special seems to which you can inject arbitrary code. Those shames exist not in the form off dependency injection. No, they're based on attributes treated by a framework in a special way. Annual testing, framer defiance and execution flow. Some steps off that execution flow are hidden by default, and actually they are empty and do nothing. Spec flow supports such seems and gives you the ability to provide code for execution at particular execution steps in a form off the so called hooks. So hooks in this backflow are defined by the following attributes before test Ron before feature before scenario before scenario block before step. And each of these attributes has its own counterpart started by the after profits. Let's briefly describe the meaning off these attributes at first how these works. It works pretty simple. You just define a method and market by particular attributes at playing a certain attributes. You make sure that it will be called at a particular moment in time, so all these attributes denote a certain point in time. During the tests, execution and method covered by the before test Ron attributes will be called once before running all the acceptance tests it's after Counterpart will be called the last You know the test execution flow logically before feature allows to define a method that will be called before running tests from a particular feature before scenario allows to define a method that will be called before running tests from a particular scenario before scenario , Block allows to define a method that will be called before running each step within a scenario, so a method marked by before scenario block will be called before given before when and before then. Each block, like when or then, can be comprised of several steps because you can apply compound operators such as end. So if the wind block consists off two steps, then a method marked by the before a step attributes will be called twice. This is the difference between before scenario block and before step all that before attributes are enclosed by there after counterparts. So if we have a single tasked and methods marked by all of the before and after attributes , the execution flow will be the following before Textron before feature before scenario before scenario block before step after step after scenario Blawg after scenario after feature and after a test run, you can declare more than one method marked by the same before attributes. For example, you may have to methods marked by before scenario attributes. In such a case, they will be called in an unpredictable order to establish the order. You can set the value to the order property off the before scenario attributes. I would never command you to use the ordered methods since it leads to a very complicated and harder to maintain code. Another concern I want to address here is the difference between before scenario, attributes and the background section declared in the future file. From the first sight, their meaning is the same. However, not exactly. The first difference is that in the background section, you should express details irrelevant to business people because implementation off this taps is hidden from their site. So boot business details related to set ups to the background section, while technical details put two methods marked by before scenario, and another difference is the order off execution. Remember that the method marked by the before scenario attributes will be executed first and only after that the background bound method will be executed 37. 03 SpecFlow in Details 20 Hook Demo: all the tests follow the Arrange act Assert pattern in unit tests, we usually have a single method. Where have all three phases in place? In acceptance tests, we divide these three phases into three different methods which correspond to given when and them steps. In. Our simple case off testing the character class were satisfied by arranging the object under test at the given step. If different steps should make different setups on the object under test, then it could be beneficial to introduce another step. Which Iran just a bear object and each test sets it up for its own needs and other quite common example concerns. Disposing of objects. We're engine you character object at each given step. But what if our character object contains unmanaged resources? Before creating a new instance? We need to dispose the previous one to solve this problem in an elegant way. You'd batter to implement a method marked by the after scenario attributes disposing the character object in it. Let's demons trade that At first I'll implement of the eye disposable interface by the character class. Oh, inherit the I disposable and implement the missing members. And since I am simulating the disposing process here. I'll just right here. Debug right line, pretend pretend we dispose Unmanaged, very sources. Done. Now we can implement a hook. Let's go to the steps playing and game steps. Okay, Okay. Let's do that here. I'll name it. Tear down and market by the after scenario attributes we don't need to passing it parameters here to this attributes. And we can just called and dispose here. Okay. Implemented in a so straightforward way that this method will be called after each scenario not only contained within the character feature but after each scenario contained within any feature. So if I put here a break point and debug the test from the other feature file, um, for example, play a game contained in tick tack toe play game feature, but let's go there and I'll command theirs out, OK, And the lats debug of these tests logically, our method marked by after scenario should not be called. But oh, sorry. Before debugging with these test, we need to go here and on command this file, lads, debug it once again. Sorry. And this I said we unfortunately reach the break point despite the fact that we are debugging the attached from the other feature fund off course. In 99% of cases that would be meaningless. And to reduce the number of calls to hook methods, I would recommend you tagging them and taking a feature to which they are related. In this case, I would tech by the character, uh, these method for that We can do that like this just passed character and off course. We need to go to the future file and mark the future filed by the stag character. Let's revealed Okay, and now let's debug all the tests. Okay, we're agent, that's great. And by the way, let's try to debunk that play game. And in this case, these break point should not be reached since we sculpted and it did. Indeed, these tests passes, but we do not reach the break point I left here, going the same way. You can define other hook methods marked by attributes we discussed throughout the previous lecture, but do not forget to scope them by attack 38. 03 SpecFlow in Details 21 Conclusion: congratulations. You reached then off a pretty long and full of knowledge section. So let's briefly recap what you learned. If you need to regenerate only apart off a scenario you can copy generated steps into clipboard and then paste it into steps implementation. You can debug acceptance tests even by putting break points at steps off a scenario writing the feature files Off course. You can put break points on implementation of steps you can pass parameters two steps by leaving placeholders in bindings. Sometimes spec flow does everything automatically, for example, when you pass numbers. If scenarios share the same data being passed to stabs, you can write the scenario outline with examples written in the form off a table. Multiple values can be passed two steps by specifying data tables as argument types required by steps. Scenario. Background can be used to remove duplicate givens taps, spec flow supports, automatic type conversion and custom tap conversion data. Tables can be converted by calling create create set or dynamic future offs. A shop scenario context can be used for sharing data between steps. You can run tests by categories which can be set via tags scoped. Execution can be used for running tests in a more granular manner. Hooks can be used for injecting arbitrary code into invisibles taps that seat in between scenarios, features and scenario steps. Let's move to the next section, where you're going to learn about selenium. 39. 04 Selenium Fundamentals 01 Selenium Overview: Psyllium is a portable software testing framework for Web applications. Basically, it automates browsers. What, in other words, means that it simulates how human beings interact with browsers. E g. Click on buttons, select check boxes, type in some taxed and someone there are two measure ways off using the power off psyllium Silly name. I D E Varies psyllium i D, which in short allows us to click on the record button, do all the actions in the browser and then replay them by the means off the same I D. In other words, it allows to record automation tests. Creeps I D will generate screamed based on our actions in the browser that I d allows to edit such generated scripts manually. So there are no problems with that Web driver. Web driver is a framework which enables writing you eye tests manually in code manually. Written tests are more maintainable, comparing to generated Scripps with ugly member names, and it off course implies that there will be a full power off a programming language such as C sharp at your disposal. Testers very often rely on Selenia my d e. When they need to automate Samuel. I tests, usually due to the lack off programming skills, while programmers more often rely on the Web driver, since it gives more freedom and power in this course, we're going to talk about the Web driver 99% of time in general. The Web driver AP I can be consumed by different languages such a C shop Java, ruby, etcetera. So we're going to write code and see shop referencing psyllium with driver knew good packages. Roughly speaking, there are as many Web driver a pie implementations as there are. Browsers were going toe work with the chrome implementation and finally, a specific Web driver. AP I Implementation directly manages the browser. The modern ceiling in three Web driver directly calls where browser commands, rather than feeling around some JavaScript code to manage browser and elements on a page. So we need three components to work with selenium. The Web browser installed the Web driver, which is really a Web server, sanding commands to a browser. Each browser has its selling driver because each browser exposes different commands. Indus script, which can be written as I already said in different programming languages such as job, our See shop or Ruby. So these is how the overall process works. In short, with the power off Web driver, you can do literally anything you want. Navigato. Any Ural resize the browser window, click on any button, select any element, upload files, delude files and so on. 40. 04 Selenium Fundamentals 02 Demo Web Site: modern sites are so powerful and dynamic and full of extremely different features elements that is just unfeasible to demonstrate all the features off Cellini. Um, it would take hundreds of hours. I believe that even the main contributor to the psyllium open service project do not keep in lamb Meriel the features off Cellini, Um, and all the caveats that are waiting for us on the road off white testing. And because of that, our goal is to get acquainted with the major features fundamentals. Understand how major things work. Relying on a solid background, you will be able to dig into particular problems which will arise here and there, re documentation and make right decisions. I'm going to demonstrate you the basic features on an ideal website suited for practicing Cellini. Um, specifically let me open that website on, and these site contains several pages where you can practice your skills in Cellini. Um, we're going to cover only the basics in Paris and then we will try to automate aerial dynamic website. Applying our new knowledge, I'll click on the link, which leads to a page with many simple elements, which is the basic page for practicing the most relevant and commonly used features off selenium. Here it is. We have many elements here. Baden's taxed input labels else own. We will try to search for elements on these webpage. And when you played them Okay, lets start learning about psyllium in details. 41. 04 Selenium Fundamentals 03 First Automation Example: the key parts when we work with Selena Maher Web driver, which is the most important class they're responsible for managing and browser. 99% of Web driver FBI calls go through the Web driver object Web element is another class, which encapsulates any element on the Web page, such as button link or an input element and so on. It provides methods for manipulating elements, clicking on them, sending tax to them and so on by by his ulcer class, which represents an extremely important notion, which is called a locator. It encapsulate information used by Web driver for searching for a particular element on the page. Let's write our first automation example without digging into details. What I want to do is to navigate to this webpage and click on this button renders the result of clicking. The website sends us to another page, which says that we clicked on the button successfully. I'll switch to visual studio and create console application. Close old the taps. I will remove all the break points. I'll open up the solution Explorer, and I'll create a new console application New project, and I'll name it well, Teammate que a automation and before writing any code we need to install tomb, you get package of selenium. Web driver and one of the drivers. Island stole Cellini. Um, Web driver. Chrome driver. Look at this. So I'll go to the managing. You get packages on brows. Well, search for selenium. We need this package. Island. Stall it. Okay. Accept all the terms and look at this. We have here silly name, chrome Web driver and selenium Web driver. Chrome driver, selenium Web driver. Chrome driver is the right one. It has 3.3 millions of downloads while this one on lee 700 k Okay, so I'll install this one except told the terms and the job is done. I'll close it. Okay. The driver is an e x e file. And after installing at chrome driver and you could package that execute herbal will be copied to the bin folder as a result of building the application, let's rebuild the APP and open the BIN folder, Open folder and file Explorer. You don't see this option seen Sire Records in 7 20 p on a 10 80 p screen. So the assumption is gold open in a folder. Let's go to be in a folder. The bag Where In the Buck and you can see here the chrome driver execute herbal. It's the heart off a chrome Web driver. Let's get back to visuals. Do you dio? At first, we need to instance she ate a Web driver. So I'll say Web I Web driver. It's an interface implemented by all the Web drivers, and in this case, I want to. Instead, she ate the chrome driver having a driver at our disposal. We can start to issue commands. I need to navigate to a specific page so I'll say driver dot navigate, Go to you are all and I'll pass the Eurail as a string flak. So after navigating to a page, we need to find the button that we want to click. Let me open up aerial browser and inspect that button by special developer tools embedded into the chrome browser. So we want to click on this button. I'll right, click on it, and you can see here the inspect optional critical inspect, and it opens up an inspection window where you can look at the HTML markup. It's apparent here that this button has the I D, which is equal to I. D. Example. Let's get back to the code and find these element. For that, I'll ask the driver to find an element. So I'll say Driver find element and it asks for the by instance. In this case, we're not going to dig deep into locators. I'll write What is necessity for locating an element by i d. Bind up I. D. Heidi example, and it's going to be a Web element. I'll call it element, and now we can click on the element element dot click and alcohol consoled it read line when we use Cellini. Um, we either just write some automation cold. If we need toe automatically, achieve something on a website or right automation code and finally use a particular unit testing framework to write assertions. You'll see many examples how I do that in the section where I used test equipped for automating WBF app and in unit for writing assertions. For now, I'll just drawn the app and look at the results out like hoops. Let's said these project s startup and I'll click of five and you can see that and browser opened up, and it navigated to page requested, and the click happened on the bottom where aircraft were requested to click on. So everything works as expected. This is the basic scenario of how we use psyllium to drive a browser. 42. 04 Selenium Fundamentals 04 Locators: the most important thing you need to learn to successfully use Cellini, um, concerns the problem off locating a Web element To search for an element you need to provide the so called locator to a Web driver. Locators are represented by the by class. We have eight ways of defining a locator. Assuming that a page has the following button, we can find it by i D i d stands for identify, and they're guaranteed to be unique in a document object model or Dom insured. Think off. Dom s off. A document structure by name. Name is not guaranteed to be unique in a Dom, but you're still able to search for an element by its name. If that element defines it, html coders are not obliged to provide names for elements by class name on complex Web pages, the appearance off almost all the elements is defined by CSS classes. CSS stands for Cascade style sheet, and in general it allows to apply styles to elements in a convenient fashion. So you're able to locate an element by its CSS class calling their corresponding a P I. By tag, you can search for an element or elements by eats or their tags. In most cases, searching by a tag, you'll find more than one element, and then you'll have to filter them out to find one that you really need to find. So saying by tag, we imply irregular HTML tax, such as a Baden input I M G. And so the next two options are about searching for an element by link text. Let's assume that we have the following to hyperlinks, and we can find them by link text to find the first element by text union to call of the link taxed method and passed a string that should fully match the link Text off course If you need to find the second element with these method, you need to pass another text string by partial link text. Partial link Taxed allows to find elements by searching for matching sub strings within link tax. So passing text. In this case you'll find both elements passing another. You'll find only the second element and the remaining locators are bisi Assess selector and by expense. These locators allow to query a document object model by writing other and expect expression or a CSS selector. I'm going toe cover these locators separately, especially the CSS selectors. Seems they're the most important. So for now, let's get to visual studio and try to locate several elements using different locators. Except see, assess selector and expect before writing locators. I'll implement a function which clicks on an element and navigates back to the initial page . So let's create here static. Avoid click on Method, which takes Allocate her Okay, and he tries to find an element by using this locator. Um, I need to. He was here a driver and let me create a field, and we'll instance she ate it here. So I'm trying to find an element hell here by using the past Locator got sake and I I'll click on it and I'll sleep here for five seconds, and I'll then navigate, navigate back to the original page off course. We sleep here just to avoid too fast switching between, you know, clicking on elements and navigating to back to the initial page to have some time for watching what happens on a screen. So I'll open the website for practice, and here we have a button that we need to find via its name. Let's inspect it. Unfortunately, you don't see the inspect option because I'm recording in 7 20 p. So I right click on the button on down Click Inspect. Here it is. You can see here that it's name is Button one, and we also have a button that we need to find Violet. A glass name. Here it is. I'll click on it and now you can see the Inspect option inspected and eats class name. Here it is, class equals button class, It's glass. Name is button class and what we have here else we have a link here which says, Click me using these link text. Here it is. Let's get back to visual studio and try to find these elements. At first, let's click on a button, searching for it by its name, so I'll right click on passing by name, but in one now let's click on a button, searching for it by its glass name. For that, I can call the click on passing by the last name, passing bottom glass like so and last click on a link in two ways. The 1st 1 through the fooling text click on passing by Link text and here. We need to provide the full link taxed. So Klink me using these link text. It should be equal and through a partial link text click on by partially taxed Click Me Using. It's a sub string, and it's enough in case self calling, the partial link taxed method and separately, let's find elements by the button tag. VAR Buttons equals driver that find elements by Ted Name passing But, um great. And let's iterated over these buttons, printing out tax from those buttons if they contain text at all. But actually, it's not so important for us, anyway. Button dot text It's a display text, and now we can run the app. The first click by D button success Get back leaked by name button Success. Let's get back Khalid by class Name Link, Success by Link and again by link and get back and everything works as expected. Let's look at the console window, and we see here that we have many buttons on the page with the following text on them. This is how the basic location process works in Salina. And yes, I said that the first click waas by a i d. But off course I was wrong because I commanded out clicking on a button by I D. So indeed, everything works as expected. You can see here that we do not click Buy I d. We clicked by name, class, name of them, two clicks on links and then we to rate over buttons so everything is fine. Let's move further. 43. 04 Selenium Fundamentals 05 XPath: html code is basically a maximal document. X Path stands for XML PATH, and its intention is to query XML documents. Expect Isn't XML quater language with its own seen tax? We're not going to fully cover X Path here. The first reason is because it would be a quite long, lyrical digression. Yes, it's beneficial to understand X Path in details, but I haven't told to say that it's beneficial. Turn, Distancia Assess and html in details us. Well, while to understand these topics is truly beneficial, it would. It would still be a lyrical digression to talk about these topics too much because the primary topic off this course is Cellini, um, spec flow and India I testing in general. And if you want to learn more CSS X Path, Dom JavaScript and all the related stuff, I would recommend you taking some simply supplementary course on you. To me, there is a plan to of course, it's about these topics here on you, to me. And the second reason off why I would not spend too much time on learning X path from the psyllium learning perspective is that see, assess electors represent an officially preferred way of locating elements. So in general, you should prefer CSS selectors over. Expect selectors, due to some reasons. And one of the reasons is that CSS electors work much faster than expected anyway, Let's get back and look at the basic self X Beth. I'm here in visual studio and I'll write a couple of ex Beth selectors. So at first I'll create a method test. Ex Beth selectors. Let's call this method from here. So the basic syntax off any ex bath query is the following 12 slashes a tag name goes square bracket opens, get attributes. It grows value and closing square bracket. For example, we can easily locate a bottom by its i. D. Writing the following expects selector By the way, there is a button with this i d I D. Example. But actually it's not a button on the page. It's off tag A. It looks like a button because off specific CSS style applied to that element. So the ex Beth select your It would look like this var by i d equals driver. Don't find element. I'm buying expense, slash, slash a square brackets. Um, I of course I d at I d equals I d. Example like this Is everything right? Yes. It seems that everything is ok. Uh Okay, um, and the same weakened right. Searching for a bottom with this specific name. So by name. And we have a really button. We have the name equal. Equal button one. Yeah. And by the way, if you want to search for an element or elements which has a particular attributes setting , you can know Meet the tag name and use the asterisk instead. Here's an example by name too. And I'll use here an asterisk instead off the tag names. So it will look like this. Yes. And in this case, the result will be the same as in the previous line where we try to search for a button with these button One name, since there is only one element with this name on the page. Nevertheless, the syntax says that you want to search for elements off any type whose attribute values match arguments in the selector. I bet you caught the idea that this is the simplest form. Often X bath selector Ex Beth allows to dig document object model, taking into account the hierarchy off elements Actually, when you start the EXE Beth selector with two slashes, you say that the searching process will start roughly speaking somewhere from the middle of the dome. So two slashes imply the relative path. But X path allows to navigate through the dome, building an absolute path. For that. You should use single slashes to navigate through an XML hierarchy. For example, let's build an ex Beth selector for one of the buttons allow our page for practice. Let's click on this button. I'll inspected. Here it is. And now let's look at the full path, which leads to this button from the top. The document starts from the HTML tag, then body, then Deve Deve again, Deve again article than 12345678 nasty Deif's than form And finally, our button to build an absolute path for this high rocky we can run to the falling. What we need to write is the sequence of tags separated by slashes of RBD n equals. Um, driver don't find element by expense, and let's build the X bath selector so it starts from HTML than body than three. Nasty Deif's, then are too cool. Then eight nested Deif's The of DVF. I'll copy and paste this. Okay. And then form. And finally our Barton. Okay, I'll put a break point here, and I'll debug our app. Okay. Oh, press f 10 And you can see that we found our buttons. Yeah. No exceptions have been thrown. We found all the buttons. Indeed. Sometimes navigating through an absolute path can be helpful. And I'll show you such a scenario in a second. However, try to avoid building absolute paths whenever you can, because even a tiny change in the document structure will break your expect. Selector. Absolute paths are too brittle and unreliable. Our Web page for practice contains, um, a couple of buttons that have been added specie thickly for trying to find them by an ex path selector. Here they are. We're going to find the 1st 2 and finding the last two will be your homework. So we're going to find these two buttons islands back to the first button. Here it is. And I lost bag to the second button. Okay, here's the 1st 1 Here is the 2nd 1 and you can see that these buttons are equal in their own definitions. And because of that, we cannot write a general selector for searching one or another bottom because we can distinguish them to distinguish them. We need either to find the difference in the ancestor elements or to find their route and build absolute paths starting from their route. Let's collapse buttons. Dave's and divas are also the same. We cannot distinguish them. So let's look further. They have their Deve we, the class name equal to E. T. Bebe column E T P B column for Underscore for etcetera. We could try to find these dif by its class and then Deke two buttons, but I want to show you how to build a more complex, absolute path. You can see on the top that one of the DIF ancestors declare I d. It means that we can easily find it without specifying a very long Britain class name. It's ideas e t dash bark, and then we need to dig to the first dif first dif than to the Fourth Deve than to the first. They're into a single Deve and then to the first dif. The first button is contained within these div. So after digging to these dif we can navigate to our bottom directly by using the special keyword following. You'll see it in a second. Let's get back to visual student Build two x bath. The selectors So far Element one equals driver The find element by ex Beth and Deve at I d Equals 80 bark, then Deve, then fourth defeat in the list of Dave's that than the first Deve than a single Deve, then the first D flu the least. And then following and after After these dif we say that the driver should found the first button in the hierarchy within that Deve. And actually the second element is the same except the fact that it lies within the second even the list of deeps after these dif and I'll start actually these expanse using the asterisk. So the first selector digs to a specific deep within which of the first button lies. And then, using a special seen tax, we search for a button. The second selector is the same. There are two differences. The 1st 1 is that it starts with an asterisk. Would actually doesn't make a difference. Things with search The route dif by i d and the second differences that we dick to another dif within which the second button allies no help with a break point and try to debunk the app have 10. I'll expand the properties off these buttons and you'll see that they have different. Why coordinates the 1st 1 The 1st 1 location he's higher is higher than the 2nd 1 So we found exactly those buttons we were trying to find. Okay, yes, I said, X path is a pretty big topic, and we cannot talk about it for several hours. If you want to learn more about X path than start from visiting a link I attached to this lecture, that link leads to a very, very good article about expense. 44. 04 Selenium Fundamentals 06 CSS Selectors: as I said previously, See, assess electors represent a preferred way of locating elements on the page. Using CSS selectors is the official recommendation from these selenium documentation. CSS selectors allow almost everything with other ways of locating allow may be the exception from the rule is complex navigations through the XML hierarchy. For such things, you may still have to rely on expect sometimes very rarely. Anyway, let's talk a little bit about CSS selectors again. I'm not going to talk hours here about CSS electors since it would be meaningless in the first place. So I'll just briefly cover the basics and share with you some links that will shed much more light on CSS selectors. So the most important process off CSS selectors over X Beth selectors is that they're faster and more readable. A part from that X path is badly supported by Internet Explorer, though that said that horse Anyway, I had to warn you. Okay, let's move to see assess electors. CSS selectors have their own seen tax, which actually he's quite similar to the scene. Text off X bath selectors. So I'll right here a method ST ick void test. Um, CSS selectors looks idiotic with three s in a row. Yeah, that would be better. Okay, so the basic syntax we're going to use throughout this course is the following one. Slashes are just for commenting out this line. So CSS selectors do not start with slashes. They start with a tag name, then an attribute goes, and tribute equals value. Like so. Values go within single quotes while in X Beth, they go within double quotes. Okay, So, as I said, very similar to what we've seen with Ex Path instead. Off learning more theory. Let's just get our hands dirty by writing several selectors test CSS electricity, I'll call it right away. So to find the button by its name, we can use the basic success. Elector form so far by name equals driver and don't find element by ah CSS selector. Of course. Who button? This is the tag name. Square bracket opens name. It's an attribute equals single quote button, One single quote and the closing square bracket done. If you need to find an element by the class name, you can either use the full form or a short form. Here is the full form of our by Class one class Barton class. This is the full form and here is the short form by class too button dot button class. So the last two lines are the same in their semantics. So if you see that a glass name consists off many words separated by spaces, then building Ah CSS elector, you have to remove all the spaces and join all the words by dots. So if a class name is the following like these, you seen html a button with with a class named like this Bataan Space Super Space style then building a CSS selector in a short form, you'd have to se this by CSS selector button dot btm dot super dot style. Like this, Of course, in double quotes, be aware that you should do this Onley in case off a short form of the selector, if you use the full form than you shouldn't remove spaces and insert dots. Okay, then if you want to search for all the elements with a specific CSS glass, but then you can write the following a selector. For example, if you want to search for all the elements all with class equals by CSS selector all the elements with these class name button class, I would expect to see many elements as the result of such a query off course. In this particular case, I believe that there is only one element which has these class name. But in reality, I believe that the result off searching for the elements with the selector would result in having more than one element found on a page s o okay to search for analogue mint by i d. You can either write a CSS selector in its full form or a short form. Here is the full form far by I d equals driver don't find element by CSS selector and the full form is the filing button. I d equals equals idea example like this done and the short form starts with the sharp character I bought I d i d. Example. Just like this. I'll put a break point here and around the up debugging it And there is a problem with yes , off course. There is no button with this ideas. I said it's not a button, it's off tag a not a button. It looks like a button. So sorry. I'll right here A okay. Lets debug it once again. Half Tim. And you can see that all the buttons have been found. All the buttons have bean found successfully. Actually, this in tax off CSS selectors is more reach. For example, you can search for elements by sub strings off their attribute values and many other things to learn more about success, electors follow the links I attached to these lecture. 45. 04 Selenium Fundamentals 07 Input, CheckBox, RadiButton, DropDown Menu: I'm not going to demonstrate you how to interact with all the possible elements. Since the court technique is always roughly the same, you inspect an element. Build a query in one form or another located and click on it in case it's clickable or send some taxed in case that element is capable off getting some input. Sometimes you might want to check the displayed, enabled and selected properties, and that's basically all the magic. There are some peculiar cases, like a polluting files handling pope ups and so on. As I said that the number off possible problems you'll face using selenium is so big that there is no meaning to even try to cover all of them. However, we look into some problems like files a polluting. For example, in this lecture, I just want to have some practice interacting with input elements, check boxes, radio buttons and drop down menus. These elements are the basic ones, so let's look at how to interact with them. As usual, we have here a Web page for practice aisles crawl a little bit down and here are through your radio buttons. First, selecting gender. I'll inspect the 1st 1 okay, and you can see that they are the same in their declarations. The difference is there actual values. The tag here is input, and the type here is radio name equals gender. All these facts will be used together as a criterion for searching the radio buttons. Let's inspect one of the check boxes. We have to check boxes here to reduce the number of switches between visual studio and a Web browser. So I'll inspected. And you can see here that both check boxes are the same in their declaration as well, except their values as well. It's in case of radio buttons. Check boxes are defined as input off check box type with name equal to ah vehicle. Keeping all these in mind, let's get back to visual studio and build a couple off CSS selectors. I will create a separate function for clicking on the radio, Buttons stated. Avoid click on radio buttons so over genders equals driver. I don't find elements by CSS selector tag input type equals radio and name equals gender. Oops. When we want to combine attributes, weaken, just ride them sequentially in square brackets like I did. It works like there is a logical end between square brackets. This selector will return the least afraid your buttons. So if you want to get a specific one, you can use an indexer. For example, of our male equals genders at zero and the 1st 1 there is female and second father having a collection off elements. You can do what you want. Of course, you can iterating over it and find a selected button or find a specific button by its value or the text. In other words, I'm going to just reiterate over the collection and click on all of them logging the selected property. So for each gender's gender, gender, not Khaliq. If gender is selected now, it should be selected. Then I want to console right line. I want to say gender gender dot text displaying the current text off a radio button off selected radio button is selected, and after that I want to sleep for two seconds. The sleep here will help us to see how we select one button after another. Otherwise it would be too fast, and we would not notice how buttons get selected. Absolutely the same thing I want to make with check boxes. So ST ick void. Click on check boxes lank of this and, uh, call these math it from the main method. Okay? And I'll save our vehicles. It rules. Driver, dog. Find elements by CSS selector and let's build assists a selector input type equals check box and name equals vehicle like so is everything right here? Looks like everything is right. Okay, so of course you can access specific elements by index. No problems with that. There are only two items to check boxes in this case, bike and car. So I showed these just for the sake of demonstration. We don't need it. Weaken. Of course, we can command these lines out. They do nothing. This is just for the sake of demonstration s o l around the for each loop over the vehicle's collection vehicle. And to check the check box, you need to click on it. And if vehicle he's selected, then I want to say the vehicle vehicle don't text is selected and I want to sleep here for two seconds s well and by the way, toe insulate a check box toe on select click ones again on that check box, and it will be insulated. Everything is pretty simple here, all the things or work the same way. The only difference is that to un select the specific check box, you have to click on it once again before running this cold. Let's get back to the browser and inspect a couple of text input elements. Okay, here we have to text input fields for feeling in the Logan and email and a button for submitting this info. Let's inspect these elements. I'll inspect the name. The U logging input element defines an I D. And this simplifies everything very much. It's ideas equal to ET underscore. PB underscore. Contact. Underscore Name underscore one. What about the email address field have inspected? It defines an idea Swell, which is equal to E T. Pby. Contact. Email one with Underscores. And what about this? Submit button. The submarine button doesn't define an I D. So we will have to search for it by tag type and class. Okay, then let's get back to visual studio in search for thes elements. So I'll right here another method feel in or Logue Logan yet doesn't matter from the learning perspective. How we will name this method. So to find text elements weaken just use their ideas So far, love are logging equals driver dot find element Um by I d e t Oops, e t underscore PB underscore Contact. Contact ponders Core name Underscore one. That's it and to feeling and input by text and input element. I mean by text. We need to call the send keys math. Passing a string like this log in sand keys Hopes Sand KIIS, which accepts a string, for example. John Snow. Everything is simple. Yes, indeed. In most cases, selenium is a very friendly framework with very convenient A P I and the same code will work for the email field. So of our email equals driver find element by i d. And he's of the same. It is almost in the same, but it says contact email instead of name email. One and email sent Keyes Jon Snow at game off throws dot com. Okay. And ah, at last we need to find the submit button. Were sub meat equals driver find element by CSS selector button time equals submit over the class with a cumbersome name a T PB contact submit, submit their Is there a space. I'm just a second. Let me look. Yes, there is a space. And since we have here since we right here the full form off CSS selector than we don't need to remove that space and insert the dog, we should write it. Yes to this. So 18. So submit 18 PB and, of course, submit. Click. So here we are, searching for a button with types of meat and the specifics. Issa's glass finally would click on it done. So I'll run the app after calling the log in, Of course. So I'll around the up and you can see that radio buttons get selected check boxes this well get selected and text boxes get field in and the button is clicked at last. So everything works as expected. And if we look at the console window, we will see that select property return to after selection. Okay, I want to talk about the drop down menus separately. Not because the interaction process with drop down is very complex. It's just a little bit different. To interact with a drop down menu. We need to use an additional class. Okay, so we're here in the browser and Let's find a drop down me new Here it is. So it lies between tabs and check boxes. By the way, to click on the tab, you can just search for it end as usual, called the Click Method, So I'm not going to show how to do that. I'll inspect the drop down menu with a drop down element, and you can see here that this element is off the select tag I D. Name or any other attributes are not sat. There is only one select element on this page, so we can find it just by its tag. However, just in case, I would think off searching for its ancestor dif element and then dig to the select. But this while for this day, if I think it would be a little bit more reliable now, look at the definition off the select element. It contains four elements. Each element implicitly has an index starting from zero. We just do not see that index. So Volver is it zero index and so on. Each element is off option tag. Is it optional tag and defines the value tag and the tax displayed on the page. So we have three ways off selecting an option by index, by value and by displayed text. If you want to select the first element by value, then we need to call a special method that you'll see in a second passing vulva string with all characters in a lower case. If you need to select the first element by text, then you need to pass Evolve a string, which starts from the uppercase V. Okay, let's get to visuals to you and that. First, let's search for these select element on the page. I'll create a method here, so let's search for the select element on the page. Car brands equals driver Dodd Find element. Bye. See Assess Selector. Do you have a T PB blurb description Akopian pasted Select. To dig down the hierarchy in a CSS elector, you need to use the right arrow character. I prefer to select options through any index because it's a more reliable way. In most cases, it will fail only in case items have been reordered on the page. What happens? Extremely rarely. But of course, if you expect that in Texas may change, then prefer selecting by value if values are defined the worst way is to rely on the displayed taxed. Okay, If I want to select by index, then I would implement and inhuman oration To select an option from the drop down element, you need to have the Cellini, um, supper package installed and use a class named select Element for that. So you need to se select element. You select element passing are element. So select Element is a special rapper, and we do not have ah, the required Newgate package inst old here. So I'll go to managing you get packages and install the supper package psyllium, um, supper Package Island's Tallet. And now we can import this type. So after wrapping the select element by these select element object, you can call select by index by text or by value methods like this selector dot select by index Car brand Audie. Let's sleep here for three seconds. Ah, we can off course select by by value. Sam Last sleep for three seconds and of course, week. Oh no t selling but select select by text, for example. Open surrendered sleep for three seconds. So the C's house electing works. Let's run the EP and make sure that everything works s expected OD ssab and up. Okay. Indeed. The first element being selected was already than SAB and then apple Great. Everything works as expected. Let's move further. 46. 04 Selenium Fundamentals 08 Dynamic Nature of Modern Web Sites: all the previous examples were fairly trivial. Modern, complex websites such as Amazon are far from being a simple s. Our Web page for practicing Cellini, Um, their complexity from the perspective off automation with selenium takes its roots from the fact that modern pages are very dynamic. It means that after navigating to page, elements do not appear immediately different techniques of building web you wise lead to a very complex graph off states concerning you are elements, so you can imagine what problems that can cause for selenium. For example, you navigate to a page, try to find an element, and you get an exception, since there is no such an element on the page because you ran of the searching process too early, there are different reasons, or for why you can face exceptions while searching for elements. Apart from that code, off webpages can dynamically change declaration off elements, so you may write a selector foran element, and it will fail sometimes due to dynamic changes. In declaration of that element, Sometimes custom elements behave in very strange ways, for example, of their clickable by mouse in a browser, but un clickable programmatically or a T least force you to apply some slick techniques to click on it programmatically if you want to perform that click anyway, when you automate a website which doesn't belong to you or your company that is called scraping and you can face main difficulties on the road off scraping. You'll face situations when it's hard to explain why an element behaves itself in a so strange way. So in many cases, using Selina becomes the art when you should try different ways for achieving what you want . 47. 04 Selenium Fundamentals 09 Explicit and Implicit Timeouts: one of the major ways off dealing with dynamic nature off modern websites is using time outs. Generally speaking, we need time outs to get in sync, the testings creeped and the application under test or a U. T. In short, a U. T. Is, in other words, a website on the test in case of selenium. Since Selena works with Web pages as creeped rounds much faster than the AU T reacts to commands so very often before issuing the next command, you have to wait until the 80 will reach a particular state. There are two types of time outs in Salina, implicit and explicit. Actually, timeouts are called weightings in selenium. Implicit weight configures the Web driver in a way that it will be tryingto find an element on the page during a period of time, determined as a time out, in case that element cannot be found right away from the first query. If the time out best buy and the element is still not found, then an exception will be thrown to set an implicit time out. You should make the following call in this case, I said 25 seconds s an implicit time out. So a Web driver will always have 25 seconds at its disposal to try to find an element on the page. After 25 seconds, it will throw the exception. There is also a specific, implicit time out for waiting a page to be completely loaded, which can be sent via the following a p I. So in both cases, we call Manage and Time Mouse and then said a specific property, the default and police had time outs are equal to zero. The problem of time outs is pretty old and controversial. The first thing you need to understand is that actually, browser drivers can manage in police it timeouts better than you, and this is the first consideration. Yes, indeed. Most of the time you'll see that these time outs are actually equal to zero. However, no one knows how later newer versions will behave themselves. At the same time, implicit time outs that have been set may nearly to some pretty big values. Such a stone or 15 seconds sold 95% off timeouts related problems. However, one day because off mixing explicit and implicit timeouts, you may observe strange, undetermined behavior as I said. Implicit timeouts are actually under control of certain drivers, so you are able to manage them. But these can be only the illusion. One day your code might be broken for a completely unexpected reason. The choice is yours. Jim Evans, one of the seminal contributors, said that you shouldn't be experiencing hangs when an element cannot be found. If you are not using implicit waits, the driver should throw the no such element exception immediately. Here's a quick rundown on the differences between explicit and implicit. Wait so explicit weight is documented and defined Behaviour runs in the local part off. Psyllium in the language of your code, works on any condition you can think off. Returns either success or time out. Error can define absence off Element s success Condition Cal Customized delay between re tries and exceptions to ignore. And what about implicit? Wait, it's undocumented and practically has an undefined behaviour runs in the remote part of selenium. The part controlling the browser only works on find elements. Methods returns either element found or after time out, not found. You've checking for absence if element must always wait until time out and cannot be customized other than global time out. Okay, then I hope now you understand more about implicit timeouts. So what is about explicit timeouts? Explicit waiters are the pieces of code, which wait for a specific event on the server side before running the script further. So these weightings work on the client side, despite they wait for an event on the server, they are under clients control. The worst example of such a waiting would be using off threats lead directly. But off course selenium provides more elegant ways of specifying explicit timeouts. For that, you can use a pie from two selenia muted packages called selenium Support and .net psyllium extras dot wait Helpers Here is an example of searching for an element with an explicit time out. Being set Web driver Wait is an object which specifies a time out and then to method called him. That object will search for an element using that time out. In this case, the until method except a condition which says that we're going toe wait until an element with a specific I D becomes visible. Another condition that can be pasties, for example, element is clickable, which is different in most cases is visible is enough. In the next section, we're going to use explicit timeouts so you'll see everything in practice. 48. 04 Selenium Fundamentals 10 Locators Priority: you learned several types of locators till this moment. Let's talk a little bit about the priority off locators that you should bear in mind while thinking off which locator to use insurance. Here's the officially recommended priority off locators i. D. Name, link, text marshalling taxed tech name, class, name CSS and expect this least requires some explanation. I d. For each and every element is always unique, so easy to access for us and fast for Web driver. Mostly we should prefer ideas first priority to find element. If by idea is not okay, for example, there is no i d. Then we should look at name. Unfortunately, it's not uncommon to see the same names being used as names for different elements on the same page, so you should be careful with that. And of course, in any cases when there is no I d, try to combine several attributes. Increasing the possibility to find the element that you are really looking for by link text and by partial in text are also great ways to find elements. If all links have uniquely taxed, that's not always the case again, so you may need to combine attributes in the search inquiry. Tech name is a good choice for filtering the whole page, and then you can feel her further. The resulting collection of elements off a specific tag, even element is unique bites tag, then this is a great option to find one. But be aware that new elements off that tag can appear in the future. On that page by class. Name is a rare way to find elements because most off websites use the same class names for multiple elements on the same page. But sure you can use it for unique class names. If you need speed up locating off complex elements, then kindly use the CSS selector to find an element. When I said Combine attributes previously off course Simon combining them in a CSS query. CSS and Ex Path are in the end of the least because they represent special cases. They allow to use all the previous options, incorporating them in a query. So if you need to find an element by more than one criteria, then prefer, say, assess selector over X Path, Ex Path is the last option that in 99% of time should be avoided 49. 04 Selenium Fundamentals 11 Scenarios to Test: And now the practical question is, Which scenarios should you cover when writing you I automation tests. Do you need to cover all the possible cases? In most cases, that would be impractical. Onley 1% off projects require such a high level of confidence in how you I works, so basically I would recommend you to go where the profit is. Cover the cases, which protect reputation off organization. Protect from data corruption. Make sure in having security and privacy protected. Cover the most used features. Cover the killer features, which differentiate your project from competitors considered to add minimum one smoke test per page. A smoke test is a test, which makes sure that the major features were correctly like buttons are clickable and so on. 50. 04 Selenium Fundamentals 12 SpecFlow and UI Testing Frameworks: Now you fully understand how spec flow and selenium work separately, but how they work in conjunction. Actually, we can combine spec flow with, anyway testing framework. In this section. I dedicated much time to selenium, and I'm going to demonstrate how to combine spec flow with tested quite instead of selenium in one of the following sections. But it doesn't make a difference. Silly name could be used just as I'm going to use Destec wide. So in general, when you want to ride business readable tests and implement them through a Y framework such as selenium, artistic wife that will look like this. Let's assume that we have a spectral scenario cold, adding a statement in this case, assuming that I'm trying to implement this scenario through a your eye testing framework, it will work as follows. When the runner kicks off the given step, it calls Web Driver a P I or tests take quite a B I to litigate to a specific page when the runner kicks off the when step in the implementation, we call either Web driver a guy or tested quite a by to feel in the input element and click on the submit button in this pseudo code. I assume that calls toe Web driver, FBI or test A quite a p. I are hidden in the page aid statement method. And finally, when the rather kicks off the then step in the implementation, we call either with driver repair or tested quite repair. It doesn't matter, actually, to navigate back to the previous statement by clicking on the navigation button and a read the taxed from a specific element which should contain the previously added statement and that this step, the assertion will be verified. If the assertion is true, then the test passes. Otherwise it fails. As I said in one of the following sections, you'll see how that works in the reality and you'll see on your own that it doesn't matter which you are testing framer to use in conjunction with spec flow, you can use any you a testing framework that suits your needs. So this is how basically works backflow in conjunction with literally anywhere testing framework. The differences in which he pie will be used in the implementation of scenarios. Just that nothing more. I say this to those who want toe which house back for work specifically with Silene IAM Not with tastic wide. Believe me. After watching my session with dusty quiet, you'll replace the stick white by selenium in your scenarios on your own easily. 51. 04 Selenium Fundamentals 13 Conclusion: congratulations. You learn the fundamentals off Selena. Let's briefly recap what you learned. Selenium consists off three main components. That browser that browser driver and selenium. A P I ceiling him relies on locators to search for elements. There are several locators i d. Name, class, name, tag, link taxed, partial link, taxed CSS and expect motor and websites are dynamic. You need to specify timeouts and rely on every tries to search for elements in a more reliable fashion. There are two types of timeouts implicit and explicit. Try to rely on explicit timeouts, since in police, it time outs can be managed by browsers without worrying you. You can use spec flow in conjunction with selenium to ride high level tests. Let's move to the next section, where we will try toe automate a live website. 52. 05 Selenium: Hi. This is Engineer Spark from engineer spark dot com and we continue our tour and see medium in this section. We're going to try to scrape an existing live website. In other words, that site is not under our control, but I need to automate a simple process. I need to automatically upload my courses to that side. In short, we're going to have a brief look at the website to understand how it looks like and what we need to do more precisely, we will set up a new project, automate the signing in process. Apply the page object design pattern for improving the maintain ability, and we will enhance that page object design pattern by creating a base class for common actions. We will automate the files. Uploading process will automate the process of feeling in the information about course, and we will learn about the page object factory approach so we have plenty of things for practice. Let's kick off of these section by over viewing the website were going toe automate 53. 05 Selenium: in this section, we're not going to write tests. Instead of that, we're going to just automate one of the real world websites solving aerial problem. I am a teacher, and my courses are selling not only on the unit platform, for example, we can find them on skill share dot com. When I release the course, I have to manually upload files to different online learning platforms. This is very tedious. So why not to write a program which will do all the things automatically isn't. It's a bright idea. Off course City is one little secret this first. I know automation off websites without permission breaks the law at least sometimes. But you're not going to tell anyone. Aren't you? Okay, I knew you are a good student. Let's open up that site and look at what I need to automate the site I'm talking about. He's skill share dot com. So where are on skill share dot com And the first thing we need to do here is to sign in for that. When you took leak on the right off button, and if we click on it, a pop up window for logging appears while we can handle even pop up windows. It's much easier to work with regular windows and by trial. And there I inferred to the fact that there is a logon page with a specific your L I'll never get to, and this page is much easier to handle. We need to feeling the log in and password here and click on signing. I'll do that manually. Right now I have a fake Logan just for our purposes. Signing Great. I'll click on my classes, and here we have a menu which allows to create a new course or a class in terms of skill share to navigate to the current page. After signing in, we can just use the currently displayed year al this one, Alka Legal Teach and click on Create a glass, and that click leads to a page with the girl you see on the screen automating a website. You don't have to always critical elements. Sometimes you can avoid it by direct navigation, too specific Urals, and that will simplify your life. In many cases, all this page will need to click on the start a class button, and this action we will really need to perform as a result of Page opens up which loves to set up in your course, I noticed that your AL has a unique I. D. And here we should have a button for uploading videos. And sometimes you can see there is kind of a bug. We see this circle of progress which doesn't stop, and we will also have to come up with some kind off a work around. We can navigate to another page and go back, and the button appears for uploading videos. It allows to upload videos from a local drive. And apart from uploading videos, we need to feeling some data about the course. For that, we need to go to class info and here have some fields for feeling in the class title class description and that class description. I'm not going to feeling automatically because it's easier to do manually. It's easier to fill in the class Project description Manual s well and below weaken Select for items from drop down menus, class, category, subcategory, class type and level and class skewers are also easier to set manually. This one I'm not going to automate these element s well, okay, everything seems pretty simple. So yep, that's everything we need to automate. Basically, let's do all the things step by step 54. 05 Selenium: before diving into inspecting elements on skill share. Let's set up a solution. The first thing I'm going to do is to add a project which already written. I'll attach an existing project, which is called a video course filed manager and what this project is about. The thing is that my video courses are stored on a local disk and video files and folders are named in a specific format. I'll open up one of the folders to demonstrate you. So here on top, you can see a few folders named in a specific format. At first the number of the section ghosts than a hyphen and then the name off a section. So I'll double click on a folder, and all the lectures are named in the same format as sections are named. So the video course File Manager Project is a project where parsing off sections and lecture names is implemented, where some useful extensions air implemented for managing the video files. In short, this is an infrastructural code, which doesn't matter from the learning perspectives. I'll explain the meaning off functions were going to call from the project when needed. Okay, so let's create a separate project where we're going to ride the automation code. By the way, let's rebuild the solution. Build succeeded. Okay, let's create a separate project where we're going to ride the automation code. So I'll add in your project. And that's going to be a consul application. And I'll call it skill Share. OK, and let's add all the packages we will need right away. So I'll go to manage you get packages and I'll install psyllium Web driver. Okay. Island stole psyllium support. I will stall selling him with driver, chrome driver and islands. Told Cellini Um, extras dot net selenium extras Wade helpers. Exactly. This one. Okay. And I believe that we need to add a reference to video course file manager s. Well, okay, that's great. Let's rebuild the solution. Bill succeeded. Great. So all the basic preparations are done. We will set up all the required things on the go in case any problems, who will arise 55. 05 Selenium: So let's start from the signing page. Let's inspect the logging. Our element. The email address element. Inspect it. Wow. It has a pretty good name. Logan. Form square brackets, Mail square brackets. Seems like such a name will stay unique on this page. So the name is looking form email. Okay, I believe this criteria is enough to find the Logan element. Let's inspect the password element. And thanks to God's, this element also has a pretty good name, which is London form square brackets, password square brackets. And what about the signing button I'll inspected. Unfortunately, it doesn't define an I d or a good, unique name. Since this page is pretty simple, I would try to find it by its type. It seems that this page contains on the one button off submit type. The only thing I would notice here is that websites such as you to me or skill share are smart enough to turn on the so called capture, which tries to verify you as a human being, asking to select correct images. I bet you've seen capture on your own. It's almost impossible to defeat good capture automatically, so sometimes you need to manually verify that you are a human being and then continue testing your code things. God's capture appears pretty rarely, at least on skill share. Okay, then let's get back to visual studio and write some code at first. How created here and class, We shall name photo skill share. OK, uh, and oh, craned here a field off my Web driver type like so and island still shaded in the constructor by creating the crime driver instance. And we also need to expose Le Guin method. So at first we will maximize the browser's window, then never gate to a specific you. Errol. Http s w w w skill share don't com slash Logan And now we need to search for elements so I'll save our email equals driver and dot find element by name by name, and the name was lugging form email in square brackets. Let's fill it in by calling sent Keyes. So I'm sending here the email. Let's find the element for feeling in the password. Find element by name, lugging form and password square brackets. And I'll send here the password like so and we need to click on the submit button so it's find it a swell driver. Find element and I will Right here. CSS elector I want to find and input element was type, Attributes equals submit like this And now we can click on our button Click okay and I'll move these class to a separate file. Let's get back to programmed on C s. Let's install She ate here. Oh, are onto skill share class And let's call here the lugging method And let's call come Sola read line. Okay, let's reveal the app. Okay, I'll move the visual studio window to another monitor and then I'll or on the application I was said it. Yes, start a project now visual studio will disappear and I'll around the application close here everything So they log in and password were fielding and we successfully logged in clicking on the submit button with the signing in Process goes well and everything works as expected . So let's move further 56. 05 Selenium: Let's write several lines of gold which allow us to create a new course for that we need to navigate to specific you're out and then click on a start New class button. Let me open up. Have page by this your l and let's inspect the start A glass button. In this case, there is no I d or a good name. So I'm going to find a form with the specific CSS this world and then dig to the first button off submit type. Let's get back to cold on Dried the CSS selector. So at first I need to navigate to specific page. I'll say for that driver, have a gate Go to your URL http s three w skill share dot Come teach of I teach drop down And now I'll ride the CSS selector for the start to class a button. For that, I'll save our start class equals driver find element by CSS selector form Don't start class creation form right narrow the body both submit type and now we can click on it. That's right. Look at what we have written here. While this code works pretty well, it's a mess All the things are inter tangled. If we continue to write automation code in this boggy style, we will end up with a big bowl of mud. What means that we'll have completely un maintainable code to remove the smell from this yet not so big bowl of mud we need to harness the power off object oriented languages. The reason. Established best practice to abstract away whole pages. So we need to create a separate class for each page, and that glass will contain all the properties and methods for working with elements on that particular page. This approach allows toe order all the things. So we will easy to understand where particular things are implemented and our changes in the future will be isolated. So I'll create elegant page class, public class log in page. I'll use the stated factory pattern here to create the speech. This pattern is suitable here, since the creation process off a page implies that we never get to the base somehow, and navigation is a long running process, and it would be against the established best practices to cram a long grinding operation into a constructor. So I'll expose the ST Ick factor method public ST Ick Logan Page Litigate hoops Navy Gate to I will require here an instance off. I would driver. I'll create here a private to read only field or five world driver type like so And I will declare here and private constructor because I exposed the ST ick factor method. I don't need to expose a constructor. I need to close it like so. And let's navigate here to a specific girl. Http s three w skilled share dot call Logan and let's to return you lugging page, passing the driver like this and for the client's side, I would expose a high level method cold something like Sign in. And this method is not going to be a stated one, of course, is going to be public void signed in. And I dont create here to methods, fuel credentials and click Sign in was generated. This methods these is feel credentials. So I'll extracted here that this is a click on the sign in button and the same manufacturing process. I would apply to the class page so I'll create another class here, which I'll name class Page, and it will contain my private read only. I would driver field with the same constructor. Only the name is different. And I'll expose a ST ick factor method here. Yes, well, public stated class page. I'll name it new class, which requests to the island driver. So we need here to navigate to a specific you, Earl. And by the way, here's this year. L Okay. And we also need here, too. Yeah, I can just I can just copy and paste it here like so. And let's return you class page passing the driver. I remove this from here. Okay, So what's going on and decline side in the auto skill share class, So I I would expose a high level method here called upload Course. I think I learned. Name the old Logan method Soil. Name it. Ah, pooled. Course. Upload Course. And I'll say, Here you are. Logan. Page equals Logan Page navigate to passing the driver. Logan page dot Signed in. And then var class page equals class page dot New class, passing the driver Same class, class page. Um, yeah, for now, that's all we did. And that's okay. I'm not going to do anything else here. Let's go to program C s was going on here. Winston shared the photo skill Share class upload course, Red line. Everything is fine, actually. Yeah, for now, we have only one high level method here. Upload course. But in the future Ah, maybe I led other methods such as, you know, collect statistics. So but, yeah, that's out off the scope of this course, but anyway, I just wanted to notice that this class will not be hanging with a single, meaningful method upload course. In such a case, we could just remove the entire class and use page objects directly. But almost always, there is some kind off an orchestrator like the auto skill share class, which exposes high level methods which encapsulate some automation steps, like in this case. 57. 05 Selenium: If we continue writing code in this way, we will end up with many pages, all of which have a field off the Web driver type. All the methods will call the find element and then click in Seoul and so on with the same constructor. And, of course, this is a boilerplate code, and we even haven't introduced interaction with elements with explicit timeouts as soon as we introduce explicit timeouts and re tries. But the code will get even more complex, and this the result will write even more boilerplate coat. We can enhance our page object design pattern, introducing explicit time out century tries and at the same time preserve good level off maintain ability. It's not so simple to simulate the case when a dynamic element appears too late and you're cold fails because of that, raising the element not found exception. Believe me, you anyway have to interact with all the elements in the reliable fashion. What means that you have to try to find an element several times specifying explicit time out. Let's look at how we can simplify our lives with the page object design pattern, since older page object types will share the same code. It's meaningful to create apparent class, so I'll create in a public class which alcohol, Web page and the parent class will contain the Web driver. So let's define a corresponding field and the constructor and the field is going to be protected, since we want to provide access from inheritors two of these field Iowa driver, driver like so and another class I would. Instant shade here is called actions. It allows to perform some advanced things, like interaction with the so called hover elements. Sometimes when you hover an element, the cold changes something dynamically, even a hyperlink attached to a particular button, you know. So, as I said earlier, automating websites, especially which do not belong to you, you'll face many strange things. So here it is. I'll create here. Private read only actions. It sits in open Curie selenium interactions, by the way, So actions call it actions, and it's going to be private. It will be used within the Web page class and let's created here actions he calls new actions passing the driver. It requires the instance off a driver, So my practice shows that you need to try to find an element three times. You know the cold, which three times Iran's the searching process is general soil implemented function, which takes an action. It's an argument and calls it three times. I like the functional programming style. So this function will return a result moment from the sea shop for election extensions. Newgate Package Islands told this package I'll go to manage and you get packages. Um Ah. Search for C sharp Functional extensions by Vladimir Cork off island Stolen. Actually, my higher level functions are not under are not written in functional style. But anyway, I want my low level classes to be written in a functional style so insured I want to use the result class. From this on, you could package which is an object which defines the successful less often operation eso . Now I'll implemented try execute function. Look at this. Um Private resolved. Yep, This one. Thank you. And I'll call it Try Execute, which takes in action. Okay. And I'm going to try to run that action three times. So I define a constant here. I will define a result here. I'll call it the last fail er and I'll around for loop and in the try block, I'll call the action. If no exceptions, have a cured. I'll return the result. Okay, and I'll catch here. The Web driver exception Last fail ER calls result dot fail He acts to string like so return The last failure here. Okay, so we three times try to run a delegate. The action we keep in mammary the last failure cured. And finally we return either success in case there were no exceptions or a failure. So if older tries failed, F failure will be returned. As a result. Notice that I catch the Web driver exception, which is the top level exception type defined in selenium. We catch it to catch different exceptions which inherit from their Web driver. Exceptions such as stale element exception and element not found exception. The most commonly used interactions are clicks, sending keys and selecting by indexer value. So at first I'll allowed the click on method, which allows to click directly and by hovering an element so the signature will be the following protected, protected Um, a result. Click on by searcher. We need to locate her here, move toe element, which by default musical to false you'll see. What is this? In a second eso, we can call the try execute method passing the action, which searches for an element with an explicit time out. For that, I'll use the Web driver. Wait. And by the way, there is a conflict between some types. So I'll, uh, defined here in Alice. Using support equals a web driver Weight where it seats Web driver, wait open. Curious Sydney. Um support ey open Q A. Cellini? Um, support You are. Let's try this. So I'll say support dog. Well, im driver, wait. Okay, wait Equals And you who have driver Wait passing the driver here and the time out using time span, let's say from seconds five seconds. If not move element more motor element. Then I'll do these var clickable element. We need to find that element. And we do that by calling. Wait until until expected conditions expected Conditions dot element to be clickable passing the locator. And finally we click on the element. Otherwise we will use the actions Class eso at the first of our visible element equals Wait until and another condition here expected conditions element. He's visible. Passing the locator. Of course and using the actions, I we'll do the falling move to element visible element Click perform. Yeah, a slick trick. So I said here five seconds as a time out. So I said here five seconds as a time out. So if we try to search for an element three times, then in total, we have a time out equal to 15 seconds and the same way we can implement the sent Keyes method. Yeah, off course. And by the way, we need to a wrap these method in try, execute like this. Okay. And as I said now, we can try to implement the send keys a method. So I'll say protected result sand keys, which also requires Allocator for a searching for an element. And the text that we're going to send to the element and I'll se return. Try executed, wrapping our function. And okay, I'll say support Web driver. Wait. We used the waiter us well here, So I'll instant shaded passing the driver and a time out. Send keys. Okay, five seconds at the same time out. And let's try to search for an element Elland equals. Wait until expected conditions is visible. Passing the locator like so and if we find the element, we can send keys passing the text like this great. And finally we can implement the select by index method. Since in this course I'm going to select options by index, Let's do that and no other method. Another commonly used method result select by index by locator. Everything is very similar, but we require here of the index. So let's return the result of calling the try execute method. The's line of gold should be similar on, and I'll call here. Wait until passing element to be clickable, of course, passing a locator and I need to instant sheet here, of course, the select element glass select in closing you so we will wrap our elements here. Let's rename it, by the way, element is a little bit more beautiful, so and we can select by index Select bind ex passing the index done. Ah yep. Seems like everything is fine. And another method which can be helpful, just checks. Even Element is clickable without performing any actions I'll implemented, but maybe I am not going to use it in this course, but anyway, I'll expose it, since it can be very helpful. Protected Bull is element clickable, which takes a locator, and I'll implemented here directly with the opinion. Try execute methods because it's a little bit different. So try lack of the same here, but it returns to so in Thailand is not equal to know and I'll catch here. The Web driver exception. No, let's hear debunk bright line lugging for the error on the return falls here in the end. Actually, we could write this function using they try execute method as well, Even if I want to return here a bowline, we could convert a result in tow, Bullen. But okay, I'm not going to riff actor this method. I believe it's written only once, and I don't think that I'll Spohn any other similar methods. Okay, so we implemented a base class here, which is very helpful. And now we can manufacture our page object classes using and based class, and you'll see how we can improve maintaining Billy team by using the Web page glass 58. 05 Selenium: So the base Web page class is done, and now we can reflect her existing pages, inheriting them from the newly created webpage. Let's start from the Class beach. Here it is I'll inherited from the Web page. Okay, now we should pass the driver to the base class constructor calling base driver and remove the existing field like so we don't need to do this anymore. And we can use Click on Method to click on the Start New Class button. I'll implement another method, since we don't have access to base class from a static method. Unfortunately, I'll define here a proper teen. We cheer returns, locator like this, and I'll name it up a little course, since we actually upload course from the class page now have access to driver in the base class so we can affect her this out by, um calling. Click on Passing the Locator and I'll set Move to Element to True seems by the trial in there. I inferred the fact that it's better to click this button by using the actions place exposed by selenium. I don't see the reason why this works as it works, but as I said earlier. When you scrape a website which is not under your control, it's always some kind of magic. You know, the art? Not always, but quite often. Okay, then. Great. Look at how clean the code looks like. Lucas, This marvelous. Great. And now we can re factor the logon page, so I'll do the same at first. Tyler affect her. The constructor and the field. I'm inheriting from the Web page, Of course. So ATS pass here being driver and remove the unused a field. But we don't need it anymore. And we can expose elements as properties saying, private by password. A beautiful scene, tax off expression bodied members. Oh, I love this. Ah. So where is the password? Here, Here, 80 years and the locator for of the log in for email Yet where it is? Here it is. Okay. And the U locator for sign in. But here it is. Elko peed and paste. Okay. And now we can defector the field credentials method we can call sent Keyes, Logan, like of these, and we can call sent Keyes passing password, passing password. How nice. How concise eyes And we can call. Hear the click on method passing the signing button. And that's all we don't need here anymore. Look at this. How beautiful. How nice. And let's two week, the auto skill share class a little bit, so we can instance she ate here a class page. Now, that's great. New class page class, page upload course. That's great. And by the way off course, we should do this. Not here, but in the upload course method off course. What have I done? Of course. We need to do this here. And, of course, through the stated factory method. Yeah, Yeah, like we did actually. Sorry. Yeah. Okay. Done. And now we can run the app and check if it works. Okay, so I ran the application, and it seems like I unintentionally removed the code which maximizes the window we loved in . Now we are clicking on the start class button and oops, skills share redirects us back to sign in. Um, actually, when I click, that button started starting you class by mouse. Then everything goes fine, but somehow maybe skill share detects that where a robot and they re direct us to the sign in page. I don't know how this happens. and why. But it happens 100% of time. So we have to logging once again after that. And after looking in here signing in, we immediately get into the, uh, uploading videos page. So I'll close for now This I'll get back to visual studio and we really need here to signing once again. That's just magic. Okay, I'll move the visual student back to another, uh, monitor another screen and I'll around it once again and you'll see what will happen. Everything should be fine. Okay, we're signing in. We started class and we're signing in once again and everything is fine. And where in the video lessons page and by the way, we need to and get back to revert back the changes when we removed the maximizing off the window and by the way of the same bug, you can see ah, which happens quite often, even even if I use my mouse even when I am not a row. But I mean not a program Graydon in selenium in C sharp. So OK, let's move further 59. 05 Selenium: When we get redirected to this page, the progress circles sometimes doesn't stop to spin, and the upload videos doesn't show up. Aside already said, I came up with a work around to overcome this problem. That only thing we need to do is to navigate to the class in four sub page and then get back. Ah, the sub page has specific your l. We can calculate these year else easily. The only thing we need to do is to add project guide or video lessons to then off the Ural . You'll see the corresponding cold a little bit later. For now, take a look at upload videos button, but first I'll inspected. Whoa. It has a pretty long definition. We have several ways of locating this element, but for some reason I had problems with locating Inter via its name. So I'm going to locate it via the Why are the a tag with a specific CSS class? Most likely, you'll face two ways of a blooming files on the Web sites. One case is when you can find a submit ah, videos button and by using the send keys method, pass paths to local files and just by doing these files will upload successfully without the necessity to big files from a pop up window, which gets opened by the operating system. The second case is when the first case doesn't work and you need to click on the input button and then pass baths to local files through a special script. Unfortunately, we face here the second case. If we click on the upload videos button, the funds browser built in the Windows operating system pops up, and we somehow have to deal with it one way off. Dealing with it is to use the auto eat, which is a basic like scripting language designed for automating the windows. Gooey and general scripting. I already downloaded older required components I attached to this lecture the link for deluding the required components eso to upload. Each file will have to build a script file at run time and passed that file as an argument to the interpreter. You'll seem cold how to do all that stuff. Let's move to the class in for Stop page here and inspect all the required uh, elements. I don't want to automate feeling off class description, class project and class skills this one, this one and this one. I only want to fill in the class title and select category subcategory, class, type of level. So let's inspect the class title and the title element is defined pretty well since it has an I D. And deterring it works. I tried it. So what about selectors? Um, category defines an idea. Swell. That's good. Let's expand the element and write down all the available options. So business, creative, lifestyle and technology. Okay, I'll select technology. And now we can inspect sub categories. This element is also defined with an idea. And if I expanded, we see all the available options. Okay, I have already written down all the options. What about class type? Class? Stab defines an idea swell. And it has two options free and premium. And what about the level element? And the level element is also defined with an I D. And it defines for possible options. Okay, Now we're ready for writing that automation code. Let's do that 60. 05 Selenium: before moving further. Let manufacture, and it will be what we have done here. So I'll move all the glasses. Two separate files. So now we can continue to goad the auto process off video's uploading. So for that at first, let me create a separate folder for holding all the stated data, such as in Yuma rations for selecting options and such. So I'll go here. I had a new folder stating Data are just data its name and just data. And let's said a glass here. Actually, it's going to be an in, um, course type. So actually, I have already prepared for animals. I'll copy them and paste. I don't think you need to watch how a type of this code they're nothing. There's nothing to explain. I'll just move these items to separate files. Yes, well, just for the sake of ordering and I'll close this files so course category, subcategory type are pretty find. They're always in the technology category. In my case, Web development, subcategory in their old premium on the two pieces of data, should be passed from the client's level title and class level. Of course, if I had to create this application for all the skill share and structures. I would request all the data. So in my case I'll just create a class which holds glass level and title. I'm talking about a supplementary class for holding that information about the course. So let me create a class I limit skill share course in full, and it's going to hold the course title and of the course level in, um, oration. And let's add a constructor here and generated the constructor with the power off every sharper. Let's move these glass to a separate file. And now let's go to the class page. What's going on here? I think we need to request here this skill sharing for course in full instance on Let's introduce the property. Or it could be even a field, actually. And let's request of the same instance here. So we will pass it here to the constructor, okay? And we need to calculate the class info and lessen uploading your else and before retreating the your els let me reflector this cold a little bit. Actually, I did some debugging behind the scenes, and I added these silly threats sleep. We don't need it. Actually, so I can remove it. Um, and you know, I don't like that. After uploading the course after calling the upload course method, we called a sign in here, Uh, it breaks of the floor, the execution floor. So I would, uh, and here, at least in action, which I would call, I mean, I would add it here, which I would call something like Logan, and I would call it here like this. And we need to pass here and information about the course it's going to be master encoding in the course level is going to be o levels. Okay, Actually, we will need to pass in a path to a local folder, but okay, we will do that a little bit later, so let's get back to course. Uploading. So after lugging in once again, we can calculated the classing for unless and uploading your else. Let's ride the corresponding code at first tile and define here class in full year l property and lesson Uriel properties. And let's calculate them here to get the current you are ill. You can call driver your l and calling this property. You'll get the currently displayed your el in the Web browser, and I will remove here. Driver Eurail. Either remove the question mark Last index off. I believe we can do this much simpler, especially using some kind of third party library suited for manipulating your Ailes. I believe it should exist. Oh yeah, and we can't make these properties Astrid only properties which cannot be modified within any methods except a constructor. So I lead here private centres. But that's not a problem. That's not a big deal. Let's do hear the same with. The only thing is that we need to adhere VDO lessons. I would a factor this out to a separate method, which I would call said sub page euros. Yes, and we need to require here that the list off videophiles videophile is a class from my infrastructural code. Do not pay too much attention to it, and actually we need to solve one problem, Asai said. Sometimes when we get to the page of files, uploading the Progress Circle doesn't stop to speed, so we can navigate to the class info at first, feeling everything there and then get back for uploading video files. Eso it first. Let's define properties which refer to elements that we need to interact with. So don't go here and now define several properties category. These are going to be the locators by I. D. I can locate catch a very but I D. It's going to be parent glasses category. Underscore i D and subcategory parent classes, subcategory Dean in the rolling type parent classes. - Okay and last, let's create a feeling classing from method, so I'll call a feeling class info here and let's implemented. At first we need to navigate here. Dr. Driver, um, never gained. Go to your L to the class scene for your URL and let's feeling follow the drop down menus here, so I'll call select by index passing category. All of my video courses belong to the technology course category and course, subcategory. It belongs to Web development. And finally, let's get to the most complex part where we need to upload videos. So after feeling in class info, lattes call upload files so uploading and course consists of two major steps feeling in the class in fluent, uploading files. Let's create this method, and that first we need to navigate to lessen secluding sub page. For that, I'll cold, dry driver navigate, Go to your L passing how I named it Lesson euro. Okay, lesson, euro And now lads, get the bath to a script that we're going to build it wrong time. So I'll say string script bath equals and I'll create a method here right away like these, and I'll generated get script path. We need to dig to a local path. I'm going to create our scripts in the local folder. For that I will do the following sub string local path musical, too. You your I birth in Cease Tamayo Get directory name assembling assembly which seats in the reflection Get executing, assembling code base And we need to get the local path like so And let's return here the path combined local death and the name off the script I'm going to generate. I'll call it file upload. The extension is a U three and let's get back. We have a script bath here that's a full path to script that we're going to generate and save a local disk. Now let's construct the process. Start in for object to feed the script to the interpreter a little bit later. For that, I'll say of R. P s, I equals new process. Starting foe Passing parents seen string See on a dark but column program files x 86. I need to pass the bath to the interpreter. I need to Ron it and it seats in this folder in program files, Auto eat three dot e vaccine and let's and the argument of the argument is going to be our script path. So this is how we will feed the interpreter. Auto Eat three Accent pude script is a command is a command that would issue for running a script, of course, a space here in the script path. Okay, and now we can run a for loop Iterating over video files were going to build a script for each file individually. Yes, indeed. For each file in division, I'll say, try finally and let's run a for loop. By the way, we need to request here the files and we need to fast them down from the apple, of course method. So now we can say here, files count before uploading files, I'm going to copy them into a temporary folder Andren name in a specific way to keep lessons Well named on skill share. The logic of this copying and renaming is not relevant from the perspective off learning selenium, so don't pay much attention to it. So in the final block, I'm going to remove the temporary folder, which will be created within the for loop. So in the finally block, I'll say videophiles, Melander, delete temporary directory bursting to birth again. Directorial name, first full file path. This is because the temporary directory and by the way, I think we will have to reconsider this way off dealing with a temporary directory. Okay, It doesn't matter from the learning perspective, so I'll just commanded out for now. Okay, And skill share doesn't like when you upload too many files simultaneously. So let's sleep for sometime after uploading the number of files which is divisible by Tim. So I'll do hear something like this waiting our weight giving time for upload, and I'll pass here. The generator. Well, call the argument it arranger, and it's going to be very simple if needs a razor. He is divisible by 10 and it is not equal to zero because we don't want to sleep before uploading the first videophile. Okay? Actually, we're going to upload more than 10 files in the score scenes. We learn selenium here. Why would we want to wait for five minutes yet? So we don't need this code in this course, but we need it in the real world. And now let's implement the build script method, which, except at Bath, two of the current file private. It's going to return a string, a script build scraped, and it takes a video file, which is also a class from the infrastructural code. You know, I'm not an expert in writing this. These auto it scripts. So I just found an existing solution on the Internet. We have the body off this creeped we need to run, and the only thing we need to do is to pass the path to a file we're going to upload. And because of that, I'll just copy and paste implementation off. But these method I'm using a string builder here. Look at this. And as I said, we have body off this script, and the only thing I do is that I create a temporary direct touring. Uh, and I copy their files and renamed them. You don't see the this process because it is encapsulated in my infrastructural code. So the only thing you need to understand is that we, uh the only thing we do here is that we feed. They screamed by the baths to files that were uploading right here one by one. So one such a script is for uploading only one file. So at each step, we're going to rebuild this creep and every round it as many titles as we need to upload all the files. So okay, and ah, now we need to write this group to a file on disk. For that, I'll say, Right old text script Birth Onda. Let's called a build script passing the current videophile. Now it's click on the upload videos bottle, like so and after clicking the pop up window should appear and we need to run the script. So our process equals process dot start and we're on the also IT process, which will execute our script. And we need to wait for this process for until it exits. And let's sleep here for one second. It's an I fix for motile and I look present exception. Yeah, it's an idiotic fix. I know But this is how the things work. And so we're on here, the interpreter, feeding it by our script file and finally will sleep here for a second. And that's a recommendation for running this script When the dialogue is involved from the Internet Explorer as it seems to be, I decided to leave this cold as it was recommended, just in case. So let's check that all the methods are called from upper level, just in case the top level should call the upload course, bypassing the path to a local folder, which contains a course and the skill share course in full. So where is auto skill share in full? Yeah, actually, I think that we need to shift the passing off skill share course in full to the upper level right here. So I would request, with the skill share core scene for here, and and I would request here and path to him course course brut birth. So I'll extract these code Best hearing food. I'll pass it from here, and we need to pass full bath to a root folder of the course Al Copy and paste. Such a path like this. Okay. And in the upload course. We need to collect all the files from the folder. Let's do that right here of our filed Sequels. Videophiles, manager, alcohol collect, too. Yeah, I know it's a method with an idiotic suffix, but I just heaven riff actor that code yet so I would be remove. The collect are the first collect method That was a temporarily decision YouTube into bugging. So I'll pass here the course road path and I'll pass here the files. So old arguments are passed. Tests required. Let's rebuild the application. And so now we're ready to run our program. So I ran there. I forgot to maximize the window again. And we're signing in, Okay, we're starting a class and we got redirected and we're signing in. Once again, we're feeling in the class info. Oh, and actual notice that we're just adding master con coding to the default Mike. Last name. We forgot to remove the existing default name. Actually, it's pretty simple to, uh, fix our cold, of course, and all the options have Bean selected properly, and we're in the video lessons and you can see how everything works. That's great. Everything runs automatically. I do nothing. That's not the magic off her video editing. So everything works s expected. That's great. That's great. So I'll stop the recording, since everything works as expected. 61. 05 Selenium: congratulations. We scraped our first website. That was a pretty interesting undertaking, which was fraught with peril. While automating that website, I was at the verge of getting banned because that means noticed strange activity. I did everything through VPN, so they didn't find my aerial account where I uploaded my courses. Otherwise, my real account could get bent easily. So be careful with scraping websites. Let's for kept what you learned in this section. Ah, you learned how to apply theoretical knowledge. In practice, we automated many things, including the not so simple process off files, uploading files. Uploading is not always a simple ascending strings to an element and then clicking on submit. Sometimes you need to write a special script for manipulating a pop up window like we did page Object Pattern is used for organizing the automation code base by splitting it on pages so pages get abstracted away and everything get much more organized. Otherwise, you'll end up with a big bowl of mud. You can inherit your page objects from a base class, which implements all the most common operations, running them with timeouts. Andriy tries Okay, let's look at a couple off additional features supported by selenium in the next section. See you 62. 06 Selenium Extras 01 Outline: Hi, this is engineers bark from engineer spoke dot com, and in this section, we're going to briefly look at how to manage a browser itself. Indeed, sometimes you need to manipulate the taps and windows in addition to manipulating the elements on pages. So in this section you'll learn how to write tests for different browsers and what you need for that. How to change the location and size of a browser. How toe open you tabs and windows and how to switch between tabs and windows and how to close them. Okay, let's kick off the section by talking about communication with different browsers. 63. 06 Selenium Extras 02 Writing Tests for Different Browsers: in the previous section. We didn't write tests. We tried to scrape her live website, which was not under our control. When you write tests for your own website, you might want to run tests in different browsers such as Firefox, Opara and even Edge. I'm not going to mention Internet Explorer since it's dying, said that horse. You may want to run tests in all the browsers because your website can behave itself differently. In different Brothers and Theron tests in a specific browser, you need to have the browser installed. At first, I have Firefox, okra and edge installed on my machine and chrome. Of course I'll open. You get package manager for this project. Here it is. So the second thing you have to do to run tests in a specific browser is that you need to install the corresponding with driver, and that's why we're here. So I'll search here for selenium, and you can see that I can install the driver for chrome and for Internet Explorer and for where is Firefox? I don't see it in the list. It should be somewhere around here. Okay, lets say Seaney, um, fire folks here it is island stole it to find the edge driver, you can search for psyllium edge and you will see here the Cellini, um, Web driver. Microsoft driver. Here it is Thesis for the edge. If I want to install the Opara driver, you have to visit the link I attached to these lecture. You'll have to delude the driver and attach to a project. And you have to set it up in a way that it should be copied to director where it can be found by the Opara driver class. And I'm talking about the execute herbal for Opara off course for the Oprah driver. And concerning Opara, if I go to program CS, you can see that I instant shade here the chrome driver. But surprisingly, I can say driver you open and driver. And at the same time you saw that I didn't install any. You get packages for Oprah? Yep. Surprisingly, the Chrome driver package defines the Opara driver Since opener driver is built on top off the same browser engine. So we can just instant instant shaded Yes, you can see here but s I said. But the only thing you need to do is to provide the path to the Opara driver that you don't loot it from the link attached to this lecture. You can avoid passing a path here too. The open a driver here. This constructor takes a path to in execute a ble, but only in case you copied the opera driver xy to a path defined by the operating system Environment path. For example, if you cooperated to system 32 folder, you know So anyway, I'm not going to set it up here. It's a technical detail. You'll do that on your own easily if you need to. I'll show you that we can create here the fire for his driver and everything will work is expected. I installed. And then you get package for ah, Firefox and that you get package carry zone the execute herbal needed for the driver so I can create here fire from the driver like so And let's around application to make sure that this change doesn't crash everything and Firefox opens up and it navigates toe Ultimate Q A . So everything works fine. Okay, electorally stopped everything great. It works if you know that something does work in one browser but doesn't work in another one. Then you can write a method which detects which driver is used right now and drawn a specific piece of gold suited for that specific browser. Here's how you can do that roughly so roughly you can do that like this ST ick void. It is just a synthetic example around specific code which takes and why I Web driver, driver and to actions. Action. I went driver for Firefox and Action. All right, What driver For for let's say chrome okay. And IV driver, he's chrome driver. Then we can call for crow passing the driver. End of driver is for our folks driver. Then for Firefox. We called for Firefox Passing the driver? Yes. Well, yeah, I'm writing a silly example here, but I bet you understand what I mean. I'm talking about complex code That depends on the specific behave er off a certain browser . Of course, we don't need such complications if we just want to navigate somewhere or perform the simplest operations which work the same way in all the browsers. So my example is silicon, Of course. Uh, and for example, Einstein sheet here, fire folks, but of course you can imagine that you can write a piece of court where you are. You are unaware off which implementation of the eye web driver was passed to your code eso . In such a case, you can called Iran specific code, passing the driver and passing to actions. So in first case, I want to navigate to http firefox dot cole And in another case I want to navigate to go to your l http. Chrome chrome dot com. Okay, And now if we around the code, we will navigate to the firefox dot com because we instance shaded fire for his driver here . But pretend that we're all aware of which implementation off the I Web driver was instance shaded, so I'll I would hear a break point color on the app on the Firefox opens up. Really? Yes. The, uh, Firefox that come and redirected us to Mozilla redirected me to Mansilla dot org's. Ah, and that's okay, that's correct. And he finds done shade here. The chrome driver and we're on the app. We get to chrome dot com, and we've got redirected to google dot com. Okay, that's let's find that So Cain. So this is how you can work with different browsers. Don't forget that you need a browser to be installed. You need its driver to be installed. I mean, it's execute herbal and create a corresponding object in your code and that corresponding object such a scrum driver or Oprah driver. They should have access to the underlying execute herbal on which the driver is based. 64. 06 Selenium Extras 03 Managing Window Size and Location: Sometimes you may face the necessity to change browser, window position and its size and selling them support such manipulations, and you can change position and size easily. I'll demonstrate you how to do that right away. So we create a driver here and now, through the manage method and window property. Weaken. Do what we want. For example, I can say driver dot manage dot window Dark position equals a new point, but let's say 203 100. What does it mean? So position is off point type. Yeah, he's off point type, and the point defines the shift in pixels from the left upper corner off the screen. Okay, and I can manage the size of the window by writing by calling the manage dot window dot sighs. We choose off size time. I'll say 306 100 on size is off size type, which is a structure as well as point, and it defines the width and height off a window in pixels. So we navigate to specific page here, and let's say what I want to change the width. Once again, let's, um, ask for a user to to enter and you width and Let's say that we want to keep it in memory. In a way. In wigs equals ing bars without any sophisticated checks. Of course. Uh, console and I mean exceptions handling Onda. We can change the window size once again, it cools and use size. You woods 600 and let's run the up and look at how it works. Um, put here a break point. Let's from the up. Okay. Oh, the window size has been changed entering you. Witt's let's say I know 500. Okay. And seems like it didn't work. Ah, let me try to move the visual studio to, uh, the other screen. Uh, other monitor. And I'll run the application once again. Let me do that. And I'll move the console application also to the other screen, and I'll say 800. Yeah. And now you can see that. But the actual size has changed. Yeah. Now you could see that. Okay, so everything works s expected. The with has been changed, and the position was also manipulated. Okay, then let's move further. 65. 06 Selenium Extras 04 Open new Tabs and Windows: Sometimes you may face the necessity to open you tabs or windows. While this is possible in general, I have to warn you that there is no a reliable way of managing tabs and Windows by writing code, which works in a cross browser fashion. I'll explain it shortly. There are several ways of managing the tabs. I prepared several methods which in theory, open new temps. Why in theory? But the thing is that something has changed in the Web drivers recently. And for now, I see that, for example, in Kroll, only two methods work as expected. Uh, let me co p and paste two methods that high have prepared for managing the tabs. Here they are. So I was talking about the open your l in your tab method, which is based on the tricky JavaScript code it creates here. It creates, um, an element in the document object model, which says to a browser that it should open a new blank tab. Of course, we need to click on that element for opening in you tab. And another method that should work is gold open window, which is based on JavaScript s. Well, here it is on, and you can see that it actually tries to open a new window. However, there is no guarantee that a browser will open a new window election. For example, the Web driver I'm using right now with the chrome off version I'm using right now I mean, opens up in you tab instead off window. So, as I said earlier, there are no guarantees regarding the approaches to managing Windows and taps. Unfortunately, we have to be very careful writing this kind of gold. So I would recommend you to test every version off Web driver and the browser because all the components depend on each other. The other method that had to work, but for some reason you do not work for now. When I record this course, I don't know why. So I googled for the problem, and it seems like problems with opening new taps lasts about a year from 2017 anyway. I'll demonstrate that it's possible to open a new tab in chrome, at least using tricky JavaScript code. So the other ways that had to work, but they do not work right now, Asai said. Here they are ill create here. ST Ick avoid method. Had to work, but do not. I don't know why. So these are the approaches, the 1st 1 second one and the 3rd 1 that had to work and they worked previously. But they do not work right now when I'm recording this course. So I'll demonstrate you how to open in new tab in chrome using JavaScript. So we're here. Never gate to some your L and let's say I'll open your Ellen you tab passing and driver Onda. Let's say I'll pass here. Http slash slash three W um skill share. Not come and let's call open, uh, open window. And let's never get to my own site, injuring year spark dot com. Or, by the way, let's just open and you window here without navigating by your l. So let's run the code to check if it works, so new tabs should be open. The 1st 1 The skill share I run open window. It makes the current tab blank. So Essay said, everything works quite strange regarding managing tabs and windows. Let's run once again to make sure that skill share will open, actually without opening your window. Yeah, and skill shared opens up so it indeed works. So this is the most reliable way I have found on the Internet. Which laws to open in you tab and navigate to ah, specific you, Carol. Okay, let's look at how to switch between tabs windows and close them. 66. 06 Selenium Extras 05 Close Tabs and Windows: If you can open new tabs and Windows, you off course should be able to switch between them and close them. Let's look at how to do that. Eso less time learned how to open in your taps and to switch between tabs and windows. You should build a call chain by calling switch to and window methods. So let's, for example, switch to the first tab for that. For that, we can build a cold chain switch to, uh, we know driver window handles dot first on and you can see here that I pass a handle to the window method and I get that handled from the window handles collection, calling first link extension method. And now, well, sleep for three seconds just for the sake of having some timeto watch the switch that has actually happened. That has to happen. So I'll sleep here for three seconds, and, uh, after that, l switch back to the last Tim under hours. Which to window, Actually, the same line off gold will copy it and paste and coal here, there last method. Okay, so I bet you got the idea. And to close the tab you need to at first switch to that tab and then call the clothes method directly on the driver. Eso Here's how you can do that. So the least of tabs. You can take it from the driver window handles. So let's say Ive tamps. Um, that count is greater than the one Let's say they're nice switch to else which to window, um, Tim's 1st 1 and I want to close it like so. And then I want to switch two of the 1st 1 uh, the first temp like this great and Lance Luke it how this cold works. So I'll around the up. New taps should open skill share. And again the same bug. Let's stop. And so I believe we need to introduce the time out for waiting until the page gets alluded entirely. S. O. I believe that if I sleep here for, let's say 10 seconds, that of course, it's not a good way to go. It seems that we need to introduce a time out, uh, for waiting until the page gets looted. For that, you can used the A P. I call that we discussed previously when we talked about time outs. There is a specific time out for waiting until a page gets loaded. And by the way, there is a trick with JavaScript. Ah, for checking the status off the current page. So let's try once again. And here's Here's the third timpte and the 2nd 1 was closed, so everything works s expected. Indeed. We opened up three taps and then we closed one of them. So everything works fine. That's great. This is how you can manage tabs and windows. Let's move to the conclusion. 67. 06 Selenium Extras 06 Conclusion: congratulations. You're each then of the section where you learned that to write tests for different browsers, you need to have older required browsers installed, their drivers installed, and instead she ate a corresponding driver. Classiness creeped. You also need to be sure. Instance she ating that driver that it can find the excusable which implements the driver. And not all the drivers are available s new get packages. You can manipulate the location and size of a browser by calling driver manage window size and window location. There is no a reliable weight off opening new tabs and windows in the cross browser fashion . At the moment I'm recording these scores. For example, I found only two ways off opening new taps and windows that are based on pure JavaScript. For switching between tabs and windows, you can call the switch to method and to use the window handles property toe work with tabs and windows. For closing a tab, you need to switch to that tab and call close directly on the driver