Skip to content

Documentation for the Code

Sven Herrmann edited this page Jun 19, 2023 · 1 revision

Main.py

This is the documentation for the Main.py script.

Dependencies

  • selenium.webdriver.support (imported as EC)
  • webdriver_manager.chrome (imported as ChromeDriverManager)
  • selenium.webdriver.support.ui (imported as WebDriverWait and Select)
  • selenium.webdriver.chrome.options (imported as Options)
  • selenium.webdriver.chrome.service (imported as Service)
  • selenium.webdriver (imported as ActionChains)
  • selenium.webdriver.common.by (imported as By)
  • email.mime.multipart (imported as MIMEMultipart)
  • email.mime.text (imported as MIMEText)
  • selenium (imported as webdriver)
  • datetime (imported as datetime and date)
  • configparser (imported as configparser)
  • smtplib (imported as smtplib)
  • sys
  • csv
  • os

Global Variables

  • config: An instance of ConfigParser class.
  • errorNotFound: A string variable holding the value "Not found!".
  • exceptionNoInputElements: A string variable holding the value "No input elements found!".
  • exceptionNoArgsProvided: A string variable holding the value "No args provided!".
  • salden: A string variable holding the value "salden".
  • logout: A string variable holding the value "out".
  • login: A string variable holding the value "in".

Functions

waitUnitElementIsVisible(by = By.ID, element = '')

Waits until the specified element is visible on the page.

  • by: (Optional) The locator strategy. Defaults to By.ID.
  • element: (Optional) The element to wait for. Defaults to an empty string.

Returns the visible element.

waitUnitElementsAreVisible(by = By.ID, elements = '')

Waits until all the specified elements are visible on the page.

  • by: (Optional) The locator strategy. Defaults to By.ID.
  • elements: (Optional) The elements to wait for. Defaults to an empty string.

Returns a list of visible elements.

connect()

Connects to the webpage using Chrome WebDriver.

switchToIframe()

Switches the WebDriver's focus to an iframe.

setInputElements()

Sets the input elements on the page.

insertAccoutNumber()

Inserts the account number into the first input element.

insertPw()

Inserts the password into the second input element.

setSelectElements()

Sets the select elements on the page.

setBookingTypeFromArgs()

Sets the booking type based on the command-line argument.

setBookingType()

Sets the booking type in the select element.

setButtonElements()

Sets the button elements on the page.

clickSaldenButton()

Clicks the "Salden" button.

clickAcceptButton()

Clicks the accept button.

getBookedTime()

Gets the booked time from the page.

getFlexTimeLabelName()

Gets the label name for flex time from the page.

getFlexTime()

Gets the flex time from the page.

getVacationDaysLabelName()

Gets the label name for vacation days from the page.

getVacationDays()

Gets the vacation days from the page.

getOldVacationDaysLabelName()

Gets the label name for old vacation days from the page.

getOldVacationDays()

Gets the old vacation days from the page.

fileExists()

Checks if the log file exists.

Returns True if the file exists, otherwise False.

storeTimeToCSV()

Stores the time information to a CSV file.

quit()

Quits the WebDriver.

sendMail(subject, body)

Sends an email with the specified subject and body.

  • subject: The subject of the email.
  • body: The body of the email.

Main

The main execution of the script.

  1. Parses the command-line arguments.
  2. Connects to the webpage.
  3. Switches to the iframe.
  4. Sets the input elements.
  5. Inserts the account number.
  6. Inserts the password.
  7. Sets the select elements.
  8. Sets the booking type from the command-line argument.
  9. Sets the booking type in the select element.
  10. Sets the button elements.
  11. Performs the appropriate action based on the command-line argument (e.g., click "Salden" button or accept button).
  12. Gets the booked time.
  13. Prints the booked time.
  14. Stores the time information to the CSV file (if enabled).
  15. Sends an email with the time information (if enabled).
  16. Quits the WebDriver.
  17. Exits the script.