So we're getting started if you look here in the source control repository I
have - I'm using - git which there is also I will post here in a little bit a link to a
github so you guys can pull down all of this info and see the kind of process
that I went through step by step. But the main thing we did here at first is
setting up just basic our basic structure we have our scripts which is
going to house all of our framework scripts so we have actions, data,
event handlers, different utilities, and verification scripts. We have templates
that we create a project template and that adds all of our scripts and our
name mapping files as existing items so you can then go in and clone the
template and it copies all these references so this allows you to update
only one script unit and have it propagate to all of your tests and then
some basic utilities nothing in here yet so the first step that I was talking
about is to get familiar with the application. So for my example I'm using
today I'm using notepad and then later I'll be using notepad plus plus to show
you how easy it is to switch between different versions and environments of
the application. So for today let's just assume the only requirement we have is
that you can pull test data, type it in, verify that what is on screen matches
what you typed in, that you can open and close the application, or you can save
what you typed in. And so we're gonna walk through process to create these
utilities that we need to make this happen. As you can see the first part
just kind of getting familiar with the application, I went through and just did
a straight record of all of the different elements that we're gonna be
interacting with just so I can kind of get an idea of what we're gonna be
working with here. So you know we can see how our menus are set up we can see that
we actually have a window edit the process name for notepad so on and so
forth. So let me go ahead and check out the branch where we have a little bit more
stuff going on a little more meat in our project here. So you can see here now we
have a smoke test project like I was saying that'll probably be one of the
first sets of tests that you want to create. We have a few more things in our
utilities now and we still have the same scripts that we had earlier. So in this
part you can see that we still don't have anything in action so we're not
even to on-screen actions yet but we do have some eventhandler stubbed out, we
have nothing else in the script genius yet. So we do have a name mapping
and what I've gone through is mapped the different elements of the test you can
see they're still hard-coded to very specific areas. The problem with this is if
we ever decided to run in a new environment or a you know different
version of the application and they put some different elements in between our
main window and our edit fields this test it's going to fail because it's
hard-coded to expect a certain way. So moving on to the next part we'll get
into the really fun stuff and that's setting up your data and prepping for
your environment so for the sake of time I'm going to skip through the first
couple parts of it and just get it to where we have some stuff working.
So you can see here now the name mapping that we had before we actually have
project variables set for the identification properties of some of
these. And this comes into play because the next part is setting up our
environment so you'll see I've used event handlers here. TestComplete's built
in a vest event handlers for starting the test and stopping the test and these
will fire off from a minute you could play until the test is from how many you
play it'll call the start start notepad test and when it stops it'll called the
stop notepad test. There's nothing in here right now what you do see we have
something in our utilities and it's called set up environment and so
basically what we have is a script here that will pull our environment data
based on two different versions of the application dev and test so I have pass
to our config files and we actually I'm using a Windows environment variables so
you can set this remotely you can set it to dev or test and then when you do that
it will open up or it will assign project variables to things like our
main app path the process we're expecting main window so on and so forth.
You don't have to use a config file the way I did you can pull it from database.
There's several different ways you can go about it but the main
important thing is to make sure that your tests can switch between
environments easily inside actions we have our open Notepad and close notepad
and what I did here is actually made both of these have an optional parameter
it's called verify so what this does is you'll see when we add test items later
the first one we're going to run first no custom verify the app can be open and
closed if it fails at any point in that then we'll stop the project log and say
hey there's no point running the rest of these tests because we can't even open
the application now. The thing is once you've ran that test you verify opens
you're not necessarily going to want to have to run those checkpoints every
single time it adds more time to the test it's really unneeded so that's why this
can be set to false and then it will just open the application and not try to
verify its existence. Down here you can see I've already started stubbing out
some actions for our main menu and so the like I said earlier our requirements
for this test for this application is just that you can open the application,
you can exit the application, and you can save. And the reason I set it up
with a JavaScript class for the properties for like the menu options and
everything like that it's so that your test can just call the, "hey, I want to do
the navigation option to save my document" well if that ever changes or
moves to a different menu or there's another dialog that pops up in there as
you're going through that process all you've got to do is update this one area.
Your logging stays consistent, you can now have your new path set up to
navigate to that part of the application and all of your tests are working again
without ever having to go touch an individual test.
Like I said, routine building blocks for tests here not the project for the tests
themselves so you can see we haven't added anything else to any of our other
tests yet except our data so we're gonna be inputting data and again here you
want to make sure your tests aren't responsible for the logic of getting
data all they need to be able to do is call a utility that returns the data
that you're expecting. I used classes here again and I'm setting I've set it
up to connect to an excel sheet as a database that's why you have the
different select statements here when the main reason I do it as an object or
a class in here as opposed to just referencing the data itself is you know
what happens if they decide they need to change a column name or what happens if
they say hey we need another column in our data in our environment
well the nice thing is if that happens all you have to do is just go modify
this one spot and it'll look through all the columns that you're inputting
without having to model by the tests themselves. I'll show a
little bit more about that here in a minute so that's kind of a basic set up
for our data and environment setup
Không có nhận xét nào:
Đăng nhận xét