We all hate to fill in those meaningless timesheet reports. What if there would be a way to automate this? Since Germanium is a web automation API, it becomes quite simple.
I personally hate all the things I need to manually do over, and over, and over again. For example at the end of the day, I need to log whatever is that I done. In order to do that, I need to:
- Login into the Outlook 365 account,
- create the first part of the day (in Austria where I live is forbidden to work more than 6 hours without a 30 minute break in between),
- pick the starting and end times,
- pick the project from a combo box with 100 entries, even if I work on the same project all the time,
- write the description, on what is that I did that day,
- create the entry,
- select the second part of the day,
- pick the starting and end times,
- pick the project from the endless combo box,
- write the description.
What I actually want to do:
- Write the description.
So without further due, I wrote a small script that allows me to literally do all the steps automatically:
timesheet "IE9 Fixes, integration testing; Create docker images."
The core of the script looks like this:
Obviously there is some parsing first going on of the input data. This is straightforward. First I go and
open_browser_and_login(), then I create the first timesheet entry, then the second.
Since we do need to open a browser, I decided to open
Chrome, and just maximize the window. Since
maximize_window() is not a Germanium function, it will be transparently sent to the underlying WebDriver object.
Then we just load the page.
After the page is loaded, the focus is already set in the user section, so I just start typing my user.
Outlook then starts doing some AJAX magic validating the login server and if they know about the server, so the more esoteric line:
wait(Css('div.progress').not_exists) # wait for the domain check
is just doing that, waiting for the div with the
progress class to not exist or be visible. Of course then I type the password, and a big
<cr>. Germanium has amazing typing support, so we can just do things like
<cr> with ease.
Finally we wait for the
'Calendars in View' text to appear, that signals the completion of the loading of the calendars. Now we can start adding entries.
In order to create the entry we just double click the first editable cell from the calendar to fire up the adding of the dialog.
But here is where things start getting a bit interesting. The dialog itself is actually just a container for an
<iframe> where the Dialog will reside. So in order to do things in the Dialog, we need to wait not only for the action (double click) to complete, or for the dialog to open, but also for the content of the dialog to load:
All the code does is waiting for the text
"user.name - New Item" to appear, that signifies the dialog is how shown, then switch to the iframe of the dialog, using the iframe decorator, and wait in that context for the text
'Project name' to appear, that tells us the content of the iframe is there.
When all this is done, we can fill in the form inside the iframe of the dialog:
This is in a sense a lot like what we’ve seen previously, except that now we also use the positional filtering capabilities of Germanium.
The IFrame Selector that was used is really straightforward:
def iframe_selector(germanium, iframe_name):
and so is the
The launcher shell script just reads the current date, and starting and the current time, in order to get the time entries.
It’s also possible to call the
timesheet.py manually for custom dates an times:
python timesheet.py 2016-05-11 09:02 18:14 "IE9 Fixes, integration testing; Create docker images."