Recently I started a project – as a beginner – to automate the manual testing for a small web application, and after a lot of work I reached the point where I’m stuck when I want to publish the test results in Testrail. I’ve searched a lot on the internet, but I found some code examples written only for specific context that I don’t understand.
So I’ve installed the pytestrail, I have a testrail.cfg file, but after the test is finished, the results are not published in the Testrail, and I don’ know what I’m missing and what I need more in order to publish the results in Testrail as Pass/Fail.
In Testrail I have the testcases, the test plan and the testrun already created.
The configuration file for the testrail named testrail.cfg:
url = https://testrail.jaas.ea.com/testrail
email = [email protected]
password = testrailPassword
<code>[API]
url = https://testrail.jaas.ea.com/testrail
email = [email protected]
password = testrailPassword
[TESTRUN]
assignedto_id = 3342
project_id = 102
plan_id = 486383
</code>
[API]
url = https://testrail.jaas.ea.com/testrail
email = [email protected]
password = testrailPassword
[TESTRUN]
assignedto_id = 3342
project_id = 102
plan_id = 486383
The code I’m running (the script is run with a parameter, ex: testscript.py username8):
<code>from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException
from pytest_testrail.plugin import testrail, pytestrail
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
ServiceObj = Service('C:Pythonchrome_driverchromedriver.exe')
driver = webdriver.Chrome(service = ServiceObj, options = chrome_options)
@pytestrail.case('C24965591')
if g_access.arg_c in g_access.user_dict:
driver.get(g_access.SttHomePage); time.sleep(3)
driver.find_element(By.XPATH, g_access.username_field).send_keys(g_access.user_dict[g_access.arg_c][0]); time.sleep(1)
driver.find_element(By.XPATH, g_access.MicrosoftNext).click(); time.sleep(5)
driver.find_element(By.XPATH, g_access.keep_signed_in).click; time.sleep(1)
driver.find_element(By.XPATH, g_access.EANext).click(); time.sleep(18)
driver.find_element(By.XPATH, g_access.password_field).send_keys(g_access.user_dict[g_access.arg_c][1]); time.sleep(1)
driver.find_element(By.XPATH, g_access.EAVerify).click(); time.sleep(7)
expected_elm = driver.find_element(By.XPATH, g_access.homepage_msg)
assert expected_elm.text == "Wellcome!"; print("Assertion Passed")
print("Assertion Failed")
<code>from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException
from pytest_testrail.plugin import testrail, pytestrail
from selenium.webdriver.common.by import By
from . import g_access
import time
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
ServiceObj = Service('C:Pythonchrome_driverchromedriver.exe')
driver = webdriver.Chrome(service = ServiceObj, options = chrome_options)
driver.maximize_window()
@pytestrail.case('C24965591')
def login_func():
if g_access.arg_c in g_access.user_dict:
driver.get(g_access.SttHomePage); time.sleep(3)
driver.find_element(By.XPATH, g_access.username_field).send_keys(g_access.user_dict[g_access.arg_c][0]); time.sleep(1)
driver.find_element(By.XPATH, g_access.MicrosoftNext).click(); time.sleep(5)
driver.find_element(By.XPATH, g_access.keep_signed_in).click; time.sleep(1)
driver.find_element(By.XPATH, g_access.EANext).click(); time.sleep(18)
driver.find_element(By.XPATH, g_access.password_field).send_keys(g_access.user_dict[g_access.arg_c][1]); time.sleep(1)
driver.find_element(By.XPATH, g_access.EAVerify).click(); time.sleep(7)
expected_elm = driver.find_element(By.XPATH, g_access.homepage_msg)
try:
assert expected_elm.text == "Wellcome!"; print("Assertion Passed")
except AssertionError:
print("Assertion Failed")
pass
</code>
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException
from pytest_testrail.plugin import testrail, pytestrail
from selenium.webdriver.common.by import By
from . import g_access
import time
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
ServiceObj = Service('C:Pythonchrome_driverchromedriver.exe')
driver = webdriver.Chrome(service = ServiceObj, options = chrome_options)
driver.maximize_window()
@pytestrail.case('C24965591')
def login_func():
if g_access.arg_c in g_access.user_dict:
driver.get(g_access.SttHomePage); time.sleep(3)
driver.find_element(By.XPATH, g_access.username_field).send_keys(g_access.user_dict[g_access.arg_c][0]); time.sleep(1)
driver.find_element(By.XPATH, g_access.MicrosoftNext).click(); time.sleep(5)
driver.find_element(By.XPATH, g_access.keep_signed_in).click; time.sleep(1)
driver.find_element(By.XPATH, g_access.EANext).click(); time.sleep(18)
driver.find_element(By.XPATH, g_access.password_field).send_keys(g_access.user_dict[g_access.arg_c][1]); time.sleep(1)
driver.find_element(By.XPATH, g_access.EAVerify).click(); time.sleep(7)
expected_elm = driver.find_element(By.XPATH, g_access.homepage_msg)
try:
assert expected_elm.text == "Wellcome!"; print("Assertion Passed")
except AssertionError:
print("Assertion Failed")
pass
The issue is that I don’t know exactly how to bind the function within pytestrail in order to publish successfully the Pass or Fail results to testcases in the testrun