 Okay, come on. Let's get started. Hi everyone, my name is Oren and I'll talk about statistical element locators and Why what I think is currently missing in Selenium or why I think This should be added to the Selenium So in the last 20 years I've done a lot to help developers Tests to write their code. I've done how to overifications I've worked at up to two sides that you almost might know and I'm working on Having better selectors that can speed up no more flaky tasks. That's my goal for the next a year or two You have no more flaky tasks. So I want in this session. I want to talk about Why am I why am I building what exactly are we building and how does it how do how will it help? every tester and developer out there to do his job much better and and and we're gonna focus on one thing Which is which is the stimuli which is usually you set up for before any test you set up some data You do some actions and then you assert so we're gonna focus about mostly on the stimuli part and And that's the user interaction. That's what you guys know and this is something that unlike unit testing This is the part that the API which is actually the UI it keeps changing and Because it keeps changing We get tests that fail those false positives We want to reduce them to zero. So this is what we're gonna talk about. So On the stimuli side, we're gonna focus we're gonna drill down even more about how locators are building every click You find an element, then you click it. So you have to find it first. So we're gonna look at that. We're gonna start Very softly. I know there's few that They're just beginners, so we're gonna talk about few for a few minutes about how the browser and actually how selenium how they Operate how they find elements and then we'll move on and see how we can improve that so So wait a second Technical problems and update the select as well So so it's not just about Record playback what what you have what we want to do is actually think about it when the application changes You want the selector to update automatically? Just as well as as you did it and that's not simple First of all what I've noticed that most record playback tools Actually do is they only record once The only record at the minute when you show them So it's weird. How do you know when you're recording right now that these ideas random generator or not? You can't you can never know I can I can add a random generated I can do it. I can take that number that was in the random generated and Make it fix so you won't never change There's companies like Google and you see every time they release every six weeks They change the ideas everything has been compiled so you actually you don't know and you can't count on on that being Steady or not steady unless you know the application So the question is what happened if you do write something that looks at the application and that's exactly a Bit of the work that you really want to hate to do is look every time at the application See what's different and update the select those for you. So that's so that's what we try to do The different you can you can have you'll have the slides there. So How browsers with what their optimizations are finding? They're just finding different Properties that's what I know how to do and they have a better understanding of their shortcuts for ideas in class And of course you can do The logical of and you want something that has this and this We'll see everything how it comes in handy something that CSS Selectors are only adding right now in the spec for the last year the W3 set spec is actually Using the parent. How do I want to find something based on its child not its parent usually until now CSS selectors You might know You can find an element based on okay, find me the parent and I want to find some some Inner element inside inside that one So but what happens if you want to take if you want to find something Relative find out the parent that has some text inside of it You can see those kind of examples even a bit more complicated when you have you want to select a checkbox But the checkbox has doesn't have the text There's another label next to it. So you want to check something You want to find someone relative to its parent and actually find that one Relative to his child that has that text. So you have three leaves and one has that text I want to find it get that parent and get Get the one that's relative to it And of course you you'd prefer using CSS electors because that's very super optimized And every course I'd write yourself it has bugs trust me. I've been in so much code so many bugs So So CSS but everyone knows CSS I guess people who here usually in their code uses CSS electos Who uses X path So there's a there's still a huge advantage to X path that's because of the parallel locators and the text But it's closing up. It's CSS will probably in the future. That's my guess to continue to evolve and they'll have all the features of X path So how do you choose? Okay, so the first one we're ready to do it We already done that so you have an element and you want to find that element again the next time As I said, it doesn't has to be with the record playback But this is usually what happens when you use run code back back He says you run and leave you record an ID and then you play it back and it goes where? and So you have to find out What happened? So you just run it again and you say you said random ideas. That's that happens a lot Second thing is what happens when you someone when you didn't change but there's a new version and that's that we talked about when actually When so the code changed it means that there's a lot of cases you didn't change the code Someone else change the code application didn't tell you why because it's separated There's a lot of cases where the who's have been in charge of the app is not in charge of the testing advice versa So because it's aspect oriented programming There's one thing that goes without having letting the other person know that something affected Well, you if you couldn't find it using jQuery then Usually then you say there's a new version those those hash killers the cash killers that they would check finding those iFrame Yeah, it's not as that simple What happens when you find you find something you see that you see the helmet when you see the helmet with ID And you use jQuery to find it That's how you find another element. That's weird. I've noticed that too. It seems that a lot of people use the same idea twice Oh, thank you So so it seems that the browser don't enforce of using the same ID only unique ID and There and there's a lot of acts that actually people use that I don't know why but I've seen so many apps And usually when you find an element, it's it's not fine elements plural. It's fine element So it gives you the first one. So sometimes it's not gonna find your elements It's gonna find something else, but at least it's deterministic It was always returned the first one and then you'll you'll see that it's returned something else That was a bit trickier. I had something that actually works 50% of the time You can find that I did that was weird and that was two bodies There was things that generate HTML. There were a lot of Bad things past then that actually generate two bodies. So you had two bodies in the same HTML I didn't think it's possible, but it seems that it is And this is just when we were talking about ideas A lot of people say, okay, so we have reusable components. Let's use classes And when we talk about class, it's the same. You have the same thing when someone changes The application you probably do some UI refactor and then You the test breaks again And then usually when you have a lot of selector you have a component Which selector is that's gonna find you the first one? You don't want to use the end child. That's the worst one you can That's the worst thing that you can do. Please don't use the end child which is which usually gives you something like this in record playback tools and How can you debug this? It means that every Everything that's gonna change every small change is gonna break this and it's sort of be not debuggable I'm person some people like functional programming OOP aspect oriented. I'm DOP debug oriented programming You have to write for me. You have to write the code so you can debug it as fast as possible. That's that's the fastest way So there's a lot of people see who are used text or inner text or private links or partial links We we give you all the browser gives us all that and of course the name does do But they all tend to be agile and the problem is that the application keeps changing and they change a lot so So who here is familiar with page objects? Oh That's great. That's where we're not gonna talk about page object That's great. I Put a link here. I did the same Talk about page out with two years ago. There's it's on video. So I have everything in it But I what I'm gonna say is that it does help with locators as well because it helps with the separation It forces you to separation of concerns to have first find the gallery And there's another component that's in charge of the specific gallery and then of course the Locators are actually you have to split the locators You have a locator to find you the gallery and the locator inside the gallery that has the next and the previous So that's why I really like the page object. How it helps with finding so usually gets It gets the locator some either string locators or the element itself we're and then of course in the later on we're gonna use it to actually Find the element inside of it. So there's two options. I'm showing as I shown here There's one option, which is just concat the strings and if you're using web driver, which is what makes sense You usually gonna find the inner element inside of it and click So Who here uses locators and who here uses a web element? So let's start web elements Who here are concats locators? Okay, so a lot of people don't use locators And that's great. There's only there's one advantage of using the locators Is that you do the search from actually when you look you're concatting the strings when you find something We were searching for something. He actually does the entire search again That helps just a bit when There's to be a cases with People's players familiar with Angular so people wrote along bad code in Angular which you had a list and when every time they change something They've rendered the list again. It was re-rendering and sometimes it had if you have a reference to the least and now There's another list You get a stale exception. Are the people not familiar with stale exception? So you need you have a reference to a DOM element that but then it that dominant is gone There's a new DOM element and that's what you have to do. You have to do a breach right So if you're using locators and always try to find your way back to that element from From the roots So that always find even though there's that the element was refreshed you can still find it and And no stale exception. So that's the only thing That it has advantage I I personally recommend using web elements as as often as you can unless you have that problem So so it seems that record playback can't work. That's what I always always told people try to convince people that it doesn't work We don't have much time So I'm gonna so record play back is hard There's a lot of people that tried and I'm gonna show we're gonna skip a lot of things I'm gonna show you what we've done So So I'm gonna show you We took a different approach in in seeing how how to do this So how can I do this full screen? Okay, it seems So what I've written is that something that It's a chrome extension just as every record playback tool does Which of course I Wanted to get to the Interesting part because recording elements that's finding what's being clicked in this in it's really easy So you have those elements But I wanted to show you first of all, there's a huge advantage of more research to record playback there's It has a lot of advantages Writing this kind of test if it was possible in three seconds to give you enormous coverage that would be awesome But record playback doesn't work for a lot of reason Not just that the elements keep breaking. How do you use reuse? So there's a lot of things For example, I always miss this kind of thing when you can group things together Just give them a name and have a reusable component I hated that record playback tools don't doesn't have reusable component and the second thing is that In the record playback you can actually do the validations. It's not just about the stimuli. You can do the validation very fast You just pointed something It's really easy to do almost everything This is now I'm showing up litur's up litur's eyes It's the same thing you have to point at something, but then you know you have visual validation instead of text validations Everything is related to finding an element. So that's why I'm So that's why I wanted to show here Sorry, I'm sorry just Recording that I had and not I wanted to show you something differently live So even even when you're writing code, it would be great if you can if you can just point at something and and have it and When you're writing code says, okay, I don't care about how you find it you find it But I want to use it in the In my application. I just want to give it a name and and and you deal with finding it Usually you have to deal with page moving from page a to page b adjax Those are those all the properties that keeps breaking so So what you really care about is your own business logic and separating the two would be great And now I'm going to show you exactly how we did that So so let me come on. Let's move forward. Okay, so looking at a simple click we look at the properties and Talk about how this could be done differently. Come on. Let's show this. Okay, so it has a lot of attributes so my suggestion was That first of all if you're using one path to find an element then you're doomed then You're not doing right now, but what I mean is that This property can change unless you can you can you can know for certain 100% those properties can't change then I would I would say that you have to you have to have more than one element that means that That how which one of the properties that single element right here. It has a lot of properties at an ID I don't know if it's Random generated or not it has a lot on key press values tax it has tag names He has an index. He has so much properties, but how do I know which one are actually? Better to use or not so what we're saying is what I am is Actually, don't choose right now Actually use all the different properties to find an element and actually find them and using a statistical analysis What do you mean by that is that? Statistically, you don't change all the properties at once what you do is you change one of them or two of them every number of application Facebook gets Features out every day everyone keeps changing their application, but nobody changes it so dramatically overnight and What it means here? That's me. It says try all the different locators try all of them and and then when every time you run them You can actually get see scoring of which one is good and which one is bad How often something changes that can give you an estimation how good it is if it's if it didn't change for the last six months You should probably give it a bit better scoring So I mean so I'm saying to think there one is don't don't you use or trust just one use a few But then you want to know who to choose the weights who do who do I pick who's better? And and this is this is something that you can do the from actually from run to run That's actually something that nobody actually did was Look at every time you ran. Did you find it or not? It's very simple fine And then when we find the element and test pass I can I can look at there I can look post-mortem and say oh, so it passed those old those five said it's pointing down one and the last one Said it's pointing the other element So I trusted them because their weights were stronger and then when I and it worked so I know I can even make them even stronger And it's more than that. It's not just a specific property either That would be simple if it's just one property usually it depends on other elements So for example the in the index and child it depends on first finding the parent element If you're looking at an ID you have a lot of elements that he That is my depend on the strength of Of the ID is actually if you remove one of the elements one of the parent elements you can still find it So you have to keep a close not just about Properties and how you find the specific properties actually There's a there's a connection between this element right here and this property and to its parent elements So you have to figure out How the relationship between each property and other elements in the system? And this is something that you should want to do Almost every time you run it the more the more you run The more it gets smarter and it knows your application So when you change some property you still find it and the computer learns and you get better and better So I guess it's something that So it's something that really really helps Well, we don't have to see that it with that it's working usually you want to see that then locators Locators the way that it's changing after you run it. That's what usually if I go back Where's the properties? Usually you have you have a way here you have a way to To improve Of course you have reassigned but every element you want to improve it and tell it to improve it I want to say oh, no, no, no, this was wrong. This is not this is not that element You're wrong at the first time. This is the element that I wanted and then you have to You can manually train and says run it again and then say improve This is it. This is something that you can do the first few times and Then we added something that actually every time you run it improves automatically Given that the test fail of fast So so so the reason I added a lot of those Different type of text validation image validation Custom some custom validation that depends because everything depends on locators if we solve I think that if we dissolve the locators problem, we're gonna it's gonna boost Development time in 50% and the maintenance in about 80% We've done We're gonna get a get in a few months a case study out that we did with net up trying to did We they tried with both regular salinium vengular And the tractor and we tried this and see how it works in the improvement. I was so a huge huge improvement in development time and in automation time maintenance time So that's very important So and of course that's And Everything you have salinium and once you use salinium nice part is I always I always tell people Use salinium whatever product you're building use a linear and that's because you get the support of all the browsers and remote Salinium grids as well here. I'm showing them and adding labels to that specific test and then I'm actually I'm gonna run it You can run it Using in the remote browser because you have a command line interface You're opening a browser somewhere and you just run it in the command line And then the same thing just runs remotely So I run it there remotely and then The nice thing is that you can of course whatever but it's running remotely you can you can see it you can see that it's running and You can actually open it and see it see it running in their remote in the remote server So of course I change it to be slower. I made the test fail When everything we have salinium you can get screenshots so that means you know on the fly What's happening in the remote remote browser? You know exactly what you got? This is why I love salinium more than everything the fact that it's a standout It means now everything that everyone's building if it's sauce labs or bars of stack everyone's building with the same standout So that's the important thing of having Everyone using the same tool means that everyone now complying to it and now it becomes a Becoming The standard whether a de facto standard now w3 standard So same with mobile and and Before I get to questions But I do want to show you and of course you can pass arguments and different arguments and doing if and everything you wanted Something else that we're actually trying to build right now So I this is something that is not out yet. I hope that you'll get get feedback from you guys Well, we're actually the only the big advantage of this it would be And I think that I'm gonna show I found the bug so one plus one usually is free when I come from one plus One is free But I found a bug and it says on the Google calculator It says that it's two and I want to I want to report that bug. So what we're trying to do is add something so you can Yeah, you can happen that you can record the scenario and then Send it to your developer you can export it to G rock you see or Trello, whatever you guys are using I hope you're using not what who's using Excel? Okay, thank you so So you can have exported that that scenario so people can When you have an open a bug the only K good case would be if you have a reproducible scenario So that's what I wanted to show you I wanted to someone to show this is the scenario I want you to give me from now on the developer. I want Actually always give me a reproducible scenario So you start recording with those smart locators, then you say what's wrong? You say you specify this is wrong and the value shouldn't be too as it is right now I want you to give me what is the expected for example the expected text we didn't add Opportunities there or other visual validations. So we just started with the text well and now we actually it creates a test what you have right now is It exports to Jira or whatever it exports So you have the textual validation the textual representation of what was the bug of what happened? You see it's exactly you have the extra presentation you have screenshots for every step You have a video and you actually have a test which you can click play and reproduce So we're not perfect yet. So we're adding a lot of things for the expected value. That should be automatically I would think And then you just you just publish it. I configure that one do to Jira someone people use here Jira Okay, okay, so So this created a ticket automatically with all those steps that are reproducible scenarios that you wanted and And you have those small locators so he can it will still work on his machine. So that's that's something that It's not out yet, so if someone wants to play with this let me know Alright, I'll show my email So it's not out so So may that's my email or Twitter and And I think now it's time for questions. Yes Hey, thank you Question yes, yes What I did there was actually you have a retry mechanism. You try to find that element. That's what I said with the locator So I'll repeat the question a Specific element that probably looks the same kind of the same, but it keeps refreshing and generating as well again and again So so using sodium I would probably use those in here I will try to find it again before acting on it or try to find it using the select or not the web element the locator And then act on it and if there's an exception I would try to do a retry But this is that means that you have to write though this code on every element So I would probably even wrap the web element. I would create my your own web element that has that has the locators and Ask from then and then does the retry for you. That's what I did When I when I showed you that would probably work because we try again again until until it finds that element Okay, okay. Thanks. Thank you question more. Yes sorry In that case, how do you distinguish between an actual application bug and as well as your script bug actually? Just just to continue with his answer No, no, I said you said that we have to retry again and again, right? So how do we distinguish that it's an application bug or we just it's a selenium So you mean that if there is a bug How do we distinguish between a couldn't find it so it depends on you have to give it usually a timeout even selenium has the implicit Wait, yeah, that's true. So you have to if it didn't load for 30 seconds That means a bug but but you said we if the element is not available. You just have to retry you have to retry So let us say for the first retry it was not there and again We try to do something else and we retry by highlighting it again, but if they're after 30 seconds It doesn't work then you then you say, okay, so it doesn't it's not there for 30 seconds. That's a lot Eventually it has to you have to find yes What the audience this is been recorded so This is my scenario. So in one of my Applications, I don't find any locator. So the problem here is the left side I'll be having some text and corresponding value will be given in the right side in the same page so currently how I am handling it using Contains text followed by following sibling that way. I'm finding the next element to whatever it is talking about the parent and the siblings actually so So, yeah, of course, this is this is something that As I said, it's not trivial using CSS vocators or yeah, you're doing it this in two stages You find the element the parent and then Using contains I'm going with the following sibling if it is child I'd be traveling to that and if I wanted to go to parent so I'm going to parent if it is ancestor So that's some whole identifying but the question here is I don't know whether to rely on this technique for me to Continue with the future. So is there any alternative way to identify the text without any locators also? No, so in your case, there's not There's no other way other you ask people you ask developers to add more That the text maybe is some kind of metadata and some attributes on your selector on the element that you have to click on That's the only option. The second option is Wait for those kind of tools that actually does that for you and know that you have to find the element that has the text And then use the parent and so I'm sorry Yeah, you have to wait for those kind of tools. Oh, thank you Have a solution for that. So you can let us see No, you can use a single X path and you can put a condition in the X path to find the sibling of the parent or other siblings based on the siblings Yeah, so Apart from that, suppose if you check there will be some either attributes will be depend on that say example The classy here may be depend on some other attributes like a data tracking data if you just open your Flipkart so in the flipkart the top menus will be having the submenu the submenus will be in separate tag And the top menus will be in separate one There will be a relationship between these two by using either attributes of those two. So you have to relate that So I'm gonna leave you in a private room So we have time for one less question so but of course afterwards you come here and tomorrow So everyone can ask me so many questions. Yes. So how long does it take for your statistical locators to be? Yeah, really good basically It up the first of all this As I said, it's just the first one is actually works will well works 90% of the time on the first try because we're trying all the different different parameters So if you have a lot of attributes if you have more than more than two then it's gonna work Most likely it's gonna work on the first try The problem the only problem is when you don't have any of them and you only have things like and child That's the problem. I mean considering doing like a visual Like a visual Alerts that actually if you have only ends child if the selectors this if the scoring is very low and it will probably fail in the future then Then I'm like a visual something that's gonna say be where you have to change that property you have to add more more So thank you everyone for coming I'm gonna be outside ask your more questions. Thank you