jeudi 30 novembre 2017

Return variable from Test class to conftest

In my task i need to return a value from my test class to conftest file. is it possible ? if yes than how to do it ?

suppose that i need to return 'element_2' variable from testcase file. if possible, please help.

This is my conftest file..

import pytest
import time
from selenium import webdriver


@pytest.yield_fixture(scope="function")
def oneTimeSetUp(request):

    print "__CONFTEST ONE TIME SETUP BEGIN__"
    driver=webdriver.Chrome()
    driver.maximize_window()    
    yield driver

    print "__CONFTEST YIELD BEGIN__"

    #print "ELEMENT_2 TEXT IS------>",element_2.text
    time.sleep(5)
    driver.close()

This is my testcase file

import pytest


@pytest.mark.usefixtures("oneTimeSetUp")

class TestHomePage():

    @pytest.fixture(autouse=True)
    def setup(self,oneTimeSetUp):
        self.webdriver = oneTimeSetUp            

    def test_run(self):

        print "____ TEST START ____"

    self.webdriver.get("http://ift.tt/Rvp0MX")
    element_1 = self.webdriver.find_element_by_css_selector('input[name="btnI"]')
    print "CLICK ON 'I AM FEELING LUCKY'"   
    element_1.click()
    element_2 = self.webdriver.find_element_by_css_selector('a[href="/doodles/about"]') 
    print "ELEMENT_2 TEXT IS------>",element_2.text
    print "CLICK ON 'ABOUT' "
    #element_2.click()
    #return element_2   

        print "____ TEST END ____"

The above code is example of google home page than click on "I am feeling lucky" on that option i need to return the variable 'element_2' which is the element of "about" option which is present on the top left corner of that page

Aucun commentaire:

Enregistrer un commentaire