Firefox Browser is opening Twice on executing Test_Login test case in Page Object Model Framework | Selenium Python Forum
A
Arvind C Posted on 03/09/2021

Test_Login Code:

from testresources.readingexcel import getcelldata
from testresources.readingexcel import isRunnable
import testresources.constants as constants
import pytest
from page.LandingPage import Landingpage
from page.Base import BasePage
import conftest
from conftest import objlist


@pytest.mark.usefixture("base_fixture")
class TestLogin:
@pytest.mark.parametrize("argvals",getcelldata("LoginTest", constants.XLS_FILEPATH))
def test_login(self,argvals):
testrunmode = isRunnable("LoginTest", constants.XLS_FILEPATH)
datarunmode = argvals[constants.RUNMODE]
if testrunmode:
if datarunmode == constants.RUNMODE_Y:
for i in range(0,len(objlist)):
#print(objlist[i])
driver = objlist[i].openbrowser(argvals[constants.BROWSERNAME])
# print(driver.name())
# web_driver = driver.openbrowser(constants.FIREFOX)
# landingpage = Landingpage(web_driver)
# login = landingpage.landingpage()
# username = login.login()
# username.enterusername()
else:
pytest.skip("test case is not executed due to run mode is set no no in datasheet")
else:
pytest.skip("test case is not executed due to run mode is set no no in testcase")

 

OpenBrowser: 

def openbrowser(self,browser):
with allure.step("Opening "+ browser):
if(browser==constants.CHROME):
self.driver = webdriver.Chrome(ChromeDriverManager().install())
elif(browser==constants.FIREFOX):
self.driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
elif(browser==constants.EDGE):
self.driver = webdriver.Edge(r"msedgedriver.exe")
else:
self.driver = webdriver.Ie()

Conftest Code:

from pyjavaproperties import Properties
import testresources.constants as constants
import pytest
from page.Base import BasePage

prod = Properties()
#set up and tear down-fxture
objlist = []
@pytest.yield_fixture(scope ='function', autouse=True)
def base_fixture():
try:
prodpath = open(constants.ENVIRONMENT_PROPERTIES)
prod.load(prodpath)
#prod.list()
base = BasePage()
objlist.append(base)
except Exception:
pass

yield locals()
base.quit()

 

TestCase:

DataSheet


0
09914040666 Replied on 03/09/2021

Hey, 

Please share the project.


M
Replied on 03/09/2021

Hello,

I have attached the Project. I have used Eclipse as Development environment.

Thanks,

Arvind


0
09914040666 Replied on 14/09/2021

Hey, 

The reason why two firefox browser are opening in your code is that in the test file you are running the code inside the loop. It is not to be executed in the loop because the execution will be performed as many times the for loop range is valid. Replace the attached file and check the execution.


Related Posts