I have a small Python script that logs in to my company's Mantis Bug Tracking system. I surfed around for ways to search based on the Summary field or create a new Mantis bug, but nothing helped me so far. Can someone please steer me to the correct direction?
FYI The log-in code I tried is the following
import argparse
import re
import logging
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from datetime import datetime, timedelta
logging.basicConfig(level=logging.INFO)
def mantisLogin(baseURL, fsa_user, fsa_pwd):
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options)
driver.get(baseURL)
WebDriverWait(driver, 5).until(EC.url_contains("login"))
username = driver.find_element("id", "id_username")
password = driver.find_element("id", "id_password")
username.clear()
password.clear()
username.send_keys(fsa_user)
password.send_keys(fsa_pwd)
driver.find_element(By.CLASS_NAME, "submit").click()
WebDriverWait(driver, 5).until(EC.url_contains("main_page.php"))
return driver
def main(args):
credentials_file = "credentials.txt"
try:
username = args.username
password = args.password
except Exception as e:
print(f"Failed to read credentials: {e}")
return
mantisURL = "http://mantis-dev.*********.com/"
try:
driver = mantisLogin(mantisURL, username, password)
except Exception as e:
print(f"Failed to login: {e}")
return
print(str(driver))
driver.quit()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("username")
parser.add_argument("password")
main(parser.parse_args())
Thank you
After a lot of searching and trial and error, I found the solution that worked for my case. I do not think there is "one solution, works for all", because it depends on the Mantis Bug HTML (code behind) for the dropdown menus used. In my case the dropdown is a <div class that has a <ul class and it contains a number of <li class. The code I used to create anew Mantis Bug is listed below:
(It requires your own Mantis Login code to create the "driver" which is a from selenium import webdriver)
The following code retrieves the just created Mantis Bug ID number. It could be used later on for an Update function:
I hope my code above can help anyone who is looking for similar answers :)