qmetry / qaf

Quality Automation Framework for web, mobileweb, mobile native and rest web-service using Selenium, webdrier, TestNG and Java Jersey
https://qmetry.github.io/qaf
MIT License
250 stars 136 forks source link

I am facing issue like session id is null. #362

Closed Dakshesh123 closed 2 years ago

Dakshesh123 commented 3 years ago

I am facing issue like session id is null. Browser is launched successfully for second scenario but not able to find elements. Getting error like: Session ID is null, Using Webdriver after calling quite()??

Originally posted by @Dakshesh123 in https://github.com/qmetry/qaf/issues/135#issuecomment-772713827

cjayswal commented 3 years ago

Please provide details about your current implementation and steps to reproduce the issue.

Dakshesh123 commented 3 years ago

Getting driver instance from cusalaunchURL() in HomePage class: getTestBase().getDriver().get(pageProps.getPropertyValue("env.baseurl")); driver.manage().window().maximize();

public class HomePage extends WFBaseTestPage {

static final Log logger = LogFactory.getLog(CreateEventStep.class);
static CreateEventPage createEvent = new CreateEventPage();
static DBMethods dbMethods = new DBMethods();
static EventDetailsPage eventDetails = new EventDetailsPage();
static EventHistoryPage eventHistory = new EventHistoryPage();
static CommonMethods commonMethods = new CommonMethods();
static HomePage homePage = new HomePage();
static CCDREventPage ccdrEvent= new CCDREventPage();
static SubmitForReview submitForReview = new SubmitForReview();
static ObjectMethods obj = new ObjectMethods();
static ReportMethods report = new ReportMethods();

public void  cusalaunchURL() {

    getTestBase().getDriver().get(pageProps.getPropertyValue("env.baseurl")); 
    driver.manage().window().maximize();
    waitForPageToLoad();
    obj.wait(1000);
    Reporter.log(getPageName().concat("Url Entered"));

}

}

TestSteps:

@QAFTestStepProvider public class CreateEventStep extends WFBaseTestCase {

static final Log logger = LogFactory.getLog(CreateEventStep.class);
static CreateEventPage createEvent = new CreateEventPage();
static DBMethods dbMethods = new DBMethods();
static ReportMethods report = new ReportMethods();
static EventDetailsPage eventDetails = new EventDetailsPage();
static EventHistoryPage eventHistory = new EventHistoryPage();
static CommonMethods commonMethods = new CommonMethods();
static HomePage homePage = new HomePage();
static CCDREventPage ccdrEvent= new CCDREventPage();
static SubmitForReview submitForReview = new SubmitForReview();
static ObjectMethods obj = new ObjectMethods();
static AddPage addPage = new AddPage();

@QAFTestStep(description="Navigate to Customer Accomodation application and Create New event through CCDR Event {0}")
public void navigateToCustomerAccomodationApplicationAndCreateNewEventThroughCCDREvent(String str0){
    homePage.cusalaunchURL();
    homePage.clickonmainmenu();
        homePage.clickonccdrevent();
        ccdrEvent.clickoneventid(str0);
        ccdrEvent.ClickOnCreateNewEvent();
}

}

======================================================== This is the test execution config: TestExecutionConfig

======================================================== application.properties

this is where to start the browser before navigating to the test instance.

#[resources]  
env.resources= resources/cusa-pcf
#env.resources= resources/full;resources/common
resources.load.subdirs=1
#To support mutliple locales
#load.locales=en
#default.locale=en

#set from where to load bdd step

#[driver]
#remote.server=localhost
#remote.port=4444
driver.name=chromeDriver

webdriver.chrome.driver=./server/chromedriver.exe
#system.webdriver.ie.driver=./server/IEDriverServer.exe
#system.webdriver.edge.driver=./server/MicrosoftWebDriver.exe
#system.webdriver.gecko.driver=./server/geckodriver.exe

# Allow configuration of chrome capabilities, ex:
#chrome.additional.capabilities={"chromeOptions":{"args":["--user-agent=Mozilla/5.0 (Windows NT 6.1\\; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36 "]}}
#iexplorer.additional.capabilities={"ignoreProtectedModeSettings":true,"ignoreZoomSetting":true}
#chrome.additional.capabilities={"chromeOptions":{"args":["--start-maximized"]}}

#############ALM Integration #################

#############QC Update properties #################

#Default wait timeout for checkpoint (assert/verify) and wait methods as well as for find element
selenium.wait.timeout=2000

selenium.success.screenshots=1
#set 1 to suppress success log, when 0 it will also show verification success message
report.log.skip.success=1

selenium.singletone=Methods

#This configuration is set to retry of test execution
retry.count=0

#[listener] qaf listeners (inclucing driver, element, step listeners) to be registered

#[web-services]
#To deal with certificate issues - do not use if required certificate authontication
#https.accept.all.cert=true

#for certificate authentication

############# driver name reference #########

#firefoxDriver
#iExplorerDriver
#chromeDriver
#operaDriver
#androidDriver
#iPhoneDriver
## required to set driveClass capability
#appiumDriver

## remote driver
#firefoxRemoteDriver
#iExplorerRemoteDriver
#chromeRemoteDriver
#operaRemoteDriver
#androidRemoteDriver
#iPhoneRemotDriver
## no need to set driveClass capability
#appiumRemoteDriver

#Custom styling CSS for testNG
system.org.uncommons.reportng.stylesheet==./resources/customreportng.css

chrome.additional.capabilities={"goog:chromeOptions":{"args":[], "useAutomationExtension":false}} 

Please check this details and let me know if you want other information.

cjayswal commented 3 years ago

Looks like problem is because of static variable declaration in testcase. Avoid class variable in class for testcase/teststep unless it's constants or doesn't have any state. Try to keep test case as independent as possible. Tobe brief, remove all static page declaration from you test class and initialize page class as and when required. For example,

public class CreateEventStep{

private static final Log logger = LogFactory.getLog(CreateEventStep.class);

@QAFTestStep(description="Navigate to Customer Accomodation application and Create New event through CCDR Event {eventId}")
public static void navigateToCustomerAccomodationApplicationAndCreateNewEventThroughCCDREvent(String eventId){
        HomePage homePage = new HomePage();
    homePage.cusalaunchURL();
    homePage.clickonmainmenu();
    homePage.clickonccdrevent();

        CCDREventPage ccdrEvent= new CCDREventPage();
    ccdrEvent.clickoneventid(str0);
    ccdrEvent.ClickOnCreateNewEvent();
}

I am not sure why you have all other page objects created in the home page. It should have code/ implementation specific to one page, if required don't declare as static. Your page should look like below:

public class HomePage extends WFBaseTestPage {
//page specific elements

   public void  cusalaunchURL() {
    driver.get("/"); 
    driver.manage().window().maximize();
    waitForPageToLoad();
    obj.wait(1000);
    Reporter.log(getPageName().concat("Url Entered"));
   }
}

Furthermore you can leverage page design features available only with QAF. Above page implementation can be enhanced as below:


public class HomePage extends WebDriverBaseTestPage<WebDriverTestPage> {
    //page elements those are identifier for the page will be used by wait for page to load.
    @PageIdentifier
    @FindBy(locator = HOME_PAGE_UNIQUE_ELE_LOC)
    private QAFWebElement homepageIdentifier;

   //other page specific elements
    @FindBy(locator = MAIN_MENU_LOC)
    private QAFWebElement mainMenu;
    @FindBy(locator = CCDREVENT_LOC)
    private QAFWebElement  ccdrevent;

//other page specific elements

    @Override
    protected void openPage(PageLocator arg0, Object... arg1) {
        driver.get("/");
    }
    public QAFWebElement getMainMenu() {
        return mainMenu;
    }
}

public class CCDREventPage extends WebDriverBaseTestPage<HomePage> {
//page elements those are identifier for the page will be used by wait for page to load.
    @PageIdentifier
    @FindBy(locator = HOME_PAGE_UNIQUE_ELE_LOC)
    private QAFWebElement homepageIdentifier;

   //other page specific elements
    @FindBy(locator = MAIN_MENU_LOC)
    private QAFWebElement mainMenu;
    @FindBy(locator = CCDREVENT_LOC)
    private QAFWebElement  ccdrevent;

    @Override
    protected void openPage(PageLocator arg0, Object... arg1) {
        parent.getMainMenu().click();
    parent.getCcdrevent().click();
    }

}

use launch page to launch the page.

        CCDREventPage ccdrEvent= new CCDREventPage();
        ccdrEvent.launchPage(null);
Dakshesh123 commented 3 years ago

Now I am getting the error like: /**

But the Step is already implemented in the respective step class.

cjayswal commented 3 years ago

This looks more related to step and step provide package configuration. Check and ensure you have correct configuration of step provider package. Right place to post "how to" question or discussions is users group or stackoverflow with qaf tag.

SelHet commented 2 years ago

I am also having same problem, while executing more than one tests. All tests execute fine, if ran individually. But when executing all tests together only first test gets executed and the in the second test driver gives up the browser Session ID after "get" command of CommonStep while try to locate a webelement on the page. I observed this behavior only when I extend "WebDriverTestCase" class in my test class. FYI : I am not using BDD. Its all java classes and methods. Versions: Qmetry : 3.1.0 & Selenium 4

cjayswal commented 2 years ago

closing inactive issue. Please post your questions in users group if required further help.