How to publish results in Testrail with pytestrail in Python Selenium

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật