Discussion:
[Cucumber] Using modules from different classes in same scenario Please help
Add Reply
Sowjanya Karumuri
2018-04-19 13:53:24 UTC
Reply
Permalink
Raw Message
Hi
I have a scenarios where in I will be needing functions from different
classes.
One class is Main Page. Other class is Popup Page.

Situation is: Main page has a button. When I click on this button then a
new pop up opens and then perform some activities and go back to the main
page again.

I'm unable to understand how I can call functions as I feel that my control
is not going back to the main page from pop-up.

Here is my code:

Scenario:
Given Open the main page
Then Click on the button
Then Perform actions on popup
And On the main page variable changes based on popup actions.

Glue File:(Please ignore the syntax.)

public void Open_the main_page() throws Throwable {
mainPage.onMainPage(days);
}
public void Click_on_the_button() throws Throwable {
mainPage.selectVacationDate(sdate);
}
public void Perform_actions_on_popup() throws Throwable {
popupPage.selectFullorHalfDay();
}
public void On_the_main_page_variable_changes_based_on_popup_actions()
throws Throwable {
mainPage.verifyVariable();
}


Now Class onMainPage:

*onMainPage: perform some actions on main page.*

protected WebDriver switchToChildWindow(String mainWindow) {
log.info("Main window value is:" + mainWindow);
try {
WebDriver popupDriver;
new
WebDriverWait(driver,Integer.parseInt(configProvider.get("popWindow.wait.timeout"))).until(ExpectedConditions.numberOfWindowsToBe(2));
List<String> browserWindows = new ArrayList<String>
(driver.getWindowHandles());
log.info("No of windows open: " + browserWindows.size());
if(browserWindows.size() == 2){
//log.info("Main window value is:" + browserWindows.get(0));
//log.info("Child window value is:" + browserWindows.get(1));
if(!mainWindow.equals(browserWindows.get(1))){
childWindow = browserWindows.get(1);
log.info("Child window value is:" + childWindow);
log.info("Found child window and switched to it.");
}else{
Assert.fail("Unable to switch to popup window");
}
}else{
Assert.fail("ChildWindow is not found.");
}
popupDriver = driver.switchTo().window(childWindow);
//log.info("Switched to Child window with value:" + childWindow);
//log.info("Now the main window will be child window with the value as: " +
popupDriver.getWindowHandle());
answerChildCert();
log.info(popupDriver.getTitle());
return popupDriver;
} catch (NumberFormatException e) {
Assert.fail("Number format exception is seen: " + e);
} catch (NullPointerException e){
Assert.fail("Null pointer exception is seen: " + e);
}
return driver;
}

public popupPage selectVacationDate(String date) throws
InterruptedException, IOException {
// click on popup

Actions open_popup = new Actions(driver);
open_popup.click(datetoclick).build().perform();

WebDriver childDriver = switchToChildWindow(mainWindow);
*return new popupPage(childDriver,configProvider);*
}


*2nd class Popup Page;*

public void onMainPage() throws IOException{

// perform some actions
clickSafely(Element.btn_Continue.locator);
clickSafely(Element.btn_Submit.locator);

log.info("Clicked on save and done button");
log.info("Closed popup.");

*return new onMainPage(driver,configProvider);*
}


Now my question is:
Should I be using "return new onMainPage(driver,configProvider);" to get
back to the main page or not?
When I run this test with multiple examples then the new page starts
opening in the popup itself.
At time while I try to access the popup it keeps giving me null pointer
exception while opening the popup
Sometimes it finds 2 windows but fails to switch to the popup
is it something in the glue file that is wrongly done?

Will all these issues I'm so much struck :( I have been trying to fix for
the past 3 weeks but could not manage fixing it.

Please help Any questions please let me know.

--
Sowji
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Koen Prins
2018-04-23 09:36:56 UTC
Reply
Permalink
Raw Message
Would you say this is a cucumber issue or a Selenium Webdriver problem? It
seems to be Webdriver related more than anything else.
But to be fair, I have a hard time understanding why you would return a
driver in a testing method, so it could be me.
Post by Sowjanya Karumuri
Hi
I have a scenarios where in I will be needing functions from different
classes.
One class is Main Page. Other class is Popup Page.
Situation is: Main page has a button. When I click on this button then a
new pop up opens and then perform some activities and go back to the main
page again.
I'm unable to understand how I can call functions as I feel that my
control is not going back to the main page from pop-up.
Given Open the main page
Then Click on the button
Then Perform actions on popup
And On the main page variable changes based on popup actions.
Glue File:(Please ignore the syntax.)
public void Open_the main_page() throws Throwable {
mainPage.onMainPage(days);
}
public void Click_on_the_button() throws Throwable {
mainPage.selectVacationDate(sdate);
}
public void Perform_actions_on_popup() throws Throwable {
popupPage.selectFullorHalfDay();
}
public void On_the_main_page_variable_changes_based_on_popup_actions()
throws Throwable {
mainPage.verifyVariable();
}
*onMainPage: perform some actions on main page.*
protected WebDriver switchToChildWindow(String mainWindow) {
log.info("Main window value is:" + mainWindow);
try {
WebDriver popupDriver;
new WebDriverWait(driver,Integer.parseInt(configProvider.get("
popWindow.wait.timeout"))).until(ExpectedConditions.
numberOfWindowsToBe(2));
List<String> browserWindows = new ArrayList<String>
(driver.getWindowHandles());
log.info("No of windows open: " + browserWindows.size());
if(browserWindows.size() == 2){
//log.info("Main window value is:" + browserWindows.get(0));
//log.info("Child window value is:" + browserWindows.get(1));
if(!mainWindow.equals(browserWindows.get(1))){
childWindow = browserWindows.get(1);
log.info("Child window value is:" + childWindow);
log.info("Found child window and switched to it.");
}else{
Assert.fail("Unable to switch to popup window");
}
}else{
Assert.fail("ChildWindow is not found.");
}
popupDriver = driver.switchTo().window(childWindow);
//log.info("Switched to Child window with value:" + childWindow);
//log.info("Now the main window will be child window with the value as: "
+ popupDriver.getWindowHandle());
answerChildCert();
log.info(popupDriver.getTitle());
return popupDriver;
} catch (NumberFormatException e) {
Assert.fail("Number format exception is seen: " + e);
} catch (NullPointerException e){
Assert.fail("Null pointer exception is seen: " + e);
}
return driver;
}
public popupPage selectVacationDate(String date) throws
InterruptedException, IOException {
// click on popup
Actions open_popup = new Actions(driver);
open_popup.click(datetoclick).build().perform();
WebDriver childDriver = switchToChildWindow(mainWindow);
*return new popupPage(childDriver,configProvider);*
}
*2nd class Popup Page;*
public void onMainPage() throws IOException{
// perform some actions
clickSafely(Element.btn_Continue.locator);
clickSafely(Element.btn_Submit.locator);
log.info("Clicked on save and done button");
log.info("Closed popup.");
*return new onMainPage(driver,configProvider);*
}
Should I be using "return new onMainPage(driver,configProvider);" to get
back to the main page or not?
When I run this test with multiple examples then the new page starts
opening in the popup itself.
At time while I try to access the popup it keeps giving me null pointer
exception while opening the popup
Sometimes it finds 2 windows but fails to switch to the popup
is it something in the glue file that is wrongly done?
Will all these issues I'm so much struck :( I have been trying to fix for
the past 3 weeks but could not manage fixing it.
Please help Any questions please let me know.
--
Sowji
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
George Dinwiddie
2018-04-24 08:40:24 UTC
Reply
Permalink
Raw Message
Sowji,

I have more advice for you than I feel like putting into an email.
Perhaps you'd like to see https://github.com/gdinwiddie/EquineHoroscope
for some examples that might help you arrange your test code in a more
useful way.

- George
Post by Sowjanya Karumuri
Hi
I have a scenarios where in I will be needing functions from different
classes.
One class is Main Page. Other class is Popup Page.
Situation is: Main page has a button. When I click on this button then a
new pop up opens and then perform some activities and go back to the
main page again.
I'm unable to understand how I can call functions as I feel that my
control is not going back to the main page from pop-up.
Given Open the main page
Then Click on the button
Then Perform actions on popup
And On the main page variable changes based on popup actions.
Glue File:(Please ignore the syntax.)
public void Open_the main_page() throws Throwable {
mainPage.onMainPage(days);
}
public void Click_on_the_button() throws Throwable {
mainPage.selectVacationDate(sdate);
}
public void Perform_actions_on_popup() throws Throwable {
popupPage.selectFullorHalfDay();
}
public void On_the_main_page_variable_changes_based_on_popup_actions()
throws Throwable {
mainPage.verifyVariable();
}
_onMainPage: perform some actions on main page._
protected WebDriver switchToChildWindow(String mainWindow) {
log.info("Main window value is:" + mainWindow);
try {
WebDriver popupDriver;
new
WebDriverWait(driver,Integer.parseInt(configProvider.get("popWindow.wait.timeout"))).until(ExpectedConditions.numberOfWindowsToBe(2));
List<String> browserWindows = new ArrayList<String>
(driver.getWindowHandles());
            log.info("No of windows open: " + browserWindows.size());
if(browserWindows.size() == 2){
//log.info("Main window value is:" + browserWindows.get(0));
//log.info("Child window value is:" + browserWindows.get(1));
if(!mainWindow.equals(browserWindows.get(1))){
childWindow = browserWindows.get(1);
log.info("Child window value is:" + childWindow);
log.info("Found child window and switched to it.");
}else{
Assert.fail("Unable to switch to popup window");
}
}else{
Assert.fail("ChildWindow is not found.");
}
popupDriver = driver.switchTo().window(childWindow);
//log.info("Switched to Child window with value:" + childWindow);
" + popupDriver.getWindowHandle());
answerChildCert();
log.info(popupDriver.getTitle());
return popupDriver;
} catch (NumberFormatException e) {
Assert.fail("Number format exception is seen: " + e);
} catch (NullPointerException e){
Assert.fail("Null pointer exception is seen: " + e);
}
return driver;
}
    public popupPage selectVacationDate(String date) throws
InterruptedException, IOException {
      // click on popup
Actions open_popup = new Actions(driver);
open_popup.click(datetoclick).build().perform();
WebDriver childDriver = switchToChildWindow(mainWindow);
*return new popupPage(childDriver,configProvider);*
    }
_2nd class Popup Page;_
    public void onMainPage() throws IOException{
       // perform some actions
clickSafely(Element.btn_Continue.locator);
clickSafely(Element.btn_Submit.locator);
log.info("Clicked on save and done button");
log.info("Closed popup.");
*return new onMainPage(driver,configProvider);*
    }
Should I be using "return new onMainPage(driver,configProvider);" to get
back to the main page or not?
When I run this test with multiple examples then the new page starts
opening in the popup itself.
At time while I try to access the popup it keeps giving me null pointer
exception while opening the popup
Sometimes it finds 2 windows but fails to switch to the popup
is it something in the glue file that is wrongly done?
Will all these issues I'm so much struck :( I have been trying to fix
for the past 3 weeks but could not manage fixing it.
Please help Any questions please let me know.
--
Sowji
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sowjanya Karumuri
2018-05-01 18:15:32 UTC
Reply
Permalink
Raw Message
@Koen: Thanks for responding. reason I want to return the webdriver is to
make sure the driver is popup handler and when it goes to the popup and
comes back to main page it will be back to the main page driver. If I do
not return the webdriver then my test hangs up and fails. Also when I do
this for multiple examples then before one test finishes next test (means
the next example input) is running and not waiting for the 1st one to
finish.

@George: Thanks for responding. I looked at the code you pointed to and it
more like calling the functions. But issue for me is that the control is
moving to the popup which is a different driver and this popup is in a new
class. I'm not sure if I should be able to put the popup code in a new
class or no...

Please ask me more questions if I'm still now clear and I can clarify my
doubt.

Otherwise just assume you have a main page and popup page and their classes
are different then how would you handle the webdriver in that situation?

Thanks
Sowji
Post by Sowjanya Karumuri
Hi
I have a scenarios where in I will be needing functions from different
classes.
One class is Main Page. Other class is Popup Page.
Situation is: Main page has a button. When I click on this button then a
new pop up opens and then perform some activities and go back to the main
page again.
I'm unable to understand how I can call functions as I feel that my
control is not going back to the main page from pop-up.
Given Open the main page
Then Click on the button
Then Perform actions on popup
And On the main page variable changes based on popup actions.
Glue File:(Please ignore the syntax.)
public void Open_the main_page() throws Throwable {
mainPage.onMainPage(days);
}
public void Click_on_the_button() throws Throwable {
mainPage.selectVacationDate(sdate);
}
public void Perform_actions_on_popup() throws Throwable {
popupPage.selectFullorHalfDay();
}
public void On_the_main_page_variable_changes_based_on_popup_actions()
throws Throwable {
mainPage.verifyVariable();
}
*onMainPage: perform some actions on main page.*
protected WebDriver switchToChildWindow(String mainWindow) {
log.info("Main window value is:" + mainWindow);
try {
WebDriver popupDriver;
new
WebDriverWait(driver,Integer.parseInt(configProvider.get("popWindow.wait.timeout"))).until(ExpectedConditions.numberOfWindowsToBe(2));
List<String> browserWindows = new ArrayList<String>
(driver.getWindowHandles());
log.info("No of windows open: " + browserWindows.size());
if(browserWindows.size() == 2){
//log.info("Main window value is:" + browserWindows.get(0));
//log.info("Child window value is:" + browserWindows.get(1));
if(!mainWindow.equals(browserWindows.get(1))){
childWindow = browserWindows.get(1);
log.info("Child window value is:" + childWindow);
log.info("Found child window and switched to it.");
}else{
Assert.fail("Unable to switch to popup window");
}
}else{
Assert.fail("ChildWindow is not found.");
}
popupDriver = driver.switchTo().window(childWindow);
//log.info("Switched to Child window with value:" + childWindow);
//log.info("Now the main window will be child window with the value as: "
+ popupDriver.getWindowHandle());
answerChildCert();
log.info(popupDriver.getTitle());
return popupDriver;
} catch (NumberFormatException e) {
Assert.fail("Number format exception is seen: " + e);
} catch (NullPointerException e){
Assert.fail("Null pointer exception is seen: " + e);
}
return driver;
}
public popupPage selectVacationDate(String date) throws
InterruptedException, IOException {
// click on popup
Actions open_popup = new Actions(driver);
open_popup.click(datetoclick).build().perform();
WebDriver childDriver = switchToChildWindow(mainWindow);
*return new popupPage(childDriver,configProvider);*
}
*2nd class Popup Page;*
public void onMainPage() throws IOException{
// perform some actions
clickSafely(Element.btn_Continue.locator);
clickSafely(Element.btn_Submit.locator);
log.info("Clicked on save and done button");
log.info("Closed popup.");
*return new onMainPage(driver,configProvider);*
}
Should I be using "return new onMainPage(driver,configProvider);" to get
back to the main page or not?
When I run this test with multiple examples then the new page starts
opening in the popup itself.
At time while I try to access the popup it keeps giving me null pointer
exception while opening the popup
Sometimes it finds 2 windows but fails to switch to the popup
is it something in the glue file that is wrongly done?
Will all these issues I'm so much struck :( I have been trying to fix for
the past 3 weeks but could not manage fixing it.
Please help Any questions please let me know.
--
Sowji
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
George Dinwiddie
2018-05-01 19:19:36 UTC
Reply
Permalink
Raw Message
Sowji,
Post by Sowjanya Karumuri
@Koen: Thanks for responding. reason I want to return the webdriver is
to make sure the driver is popup handler and when it goes to the popup
and comes back to main page it will be back to the main page driver. If
I do not return the webdriver then my test hangs up and fails. Also when
I do this for multiple examples then before one test finishes next test
(means the next example input) is running and not waiting for the 1st
one to finish.
@George: Thanks for responding. I looked at the code you pointed to and
it more like calling the functions. But issue for me is that the control
is moving to the popup which is a different driver and this popup is in
a new class. I'm not sure if I should be able to put the popup code in a
new class or no...
Notice that I have a page object class, PurchasePage, that takes a
reference to the WebDriver in the constructor. If I were to have
multiple pages (and popups), I would pass the same WebDriver instance to
each one. The WebDriver class is tied to the browser, not the page. You
only need one browser to visit multiple pages.

Since EquineHoroscope is a one-page app, the WebDriver is created when
the page is opened. You can see this in EquineHoroscopeRetailWebAdapter.
If it had multiple pages, it would be created when the first page was
opened and then cached as a singleton to be reused when other pages were
opened.

Does that help?

- George
Post by Sowjanya Karumuri
Please ask me more questions if I'm still now clear and I can clarify my
doubt.
Otherwise just assume you have a main page and popup page and their
classes are different then how would you handle the webdriver in that
situation?
Thanks
Sowji
Hi
I have a scenarios where in I will be needing functions from
different classes.
One class is Main Page. Other class is Popup Page.
Situation is: Main page has a button. When I click on this button
then a new pop up opens and then perform some activities and go back
to the main page again.
I'm unable to understand how I can call functions as I feel that my
control is not going back to the main page from pop-up.
Given Open the main page
Then Click on the button
Then Perform actions on popup
And On the main page variable changes based on popup actions.
Glue File:(Please ignore the syntax.)
public void Open_the main_page() throws Throwable {
mainPage.onMainPage(days);
}
public void Click_on_the_button() throws Throwable {
mainPage.selectVacationDate(sdate);
}
public void Perform_actions_on_popup() throws Throwable {
popupPage.selectFullorHalfDay();
}
public void
On_the_main_page_variable_changes_based_on_popup_actions() throws
Throwable {
mainPage.verifyVariable();
}
_onMainPage: perform some actions on main page._
protected WebDriver switchToChildWindow(String mainWindow) {
log.info <http://log.info>("Main window value is:" + mainWindow);
try {
WebDriver popupDriver;
new
WebDriverWait(driver,Integer.parseInt(configProvider.get("popWindow.wait.timeout"))).until(ExpectedConditions.numberOfWindowsToBe(2));
List<String> browserWindows = new ArrayList<String>
(driver.getWindowHandles());
log.info <http://log.info>("No of windows open: " +
browserWindows.size());
if(browserWindows.size() == 2){
//log.info <http://log.info>("Main window value is:" +
browserWindows.get(0));
//log.info <http://log.info>("Child window value is:" +
browserWindows.get(1));
if(!mainWindow.equals(browserWindows.get(1))){
childWindow = browserWindows.get(1);
log.info <http://log.info>("Child window value is:" + childWindow);
log.info <http://log.info>("Found child window and switched to it.");
}else{
Assert.fail("Unable to switch to popup window");
}
}else{
Assert.fail("ChildWindow is not found.");
}
popupDriver = driver.switchTo().window(childWindow);
//log.info <http://log.info>("Switched to Child window with value:"
+ childWindow);
//log.info <http://log.info>("Now the main window will be child
window with the value as: " + popupDriver.getWindowHandle());
answerChildCert();
log.info <http://log.info>(popupDriver.getTitle());
return popupDriver;
} catch (NumberFormatException e) {
Assert.fail("Number format exception is seen: " + e);
} catch (NullPointerException e){
Assert.fail("Null pointer exception is seen: " + e);
}
return driver;
}
    public popupPage selectVacationDate(String date) throws
InterruptedException, IOException {
      // click on popup
Actions open_popup = new Actions(driver);
open_popup.click(datetoclick).build().perform();
WebDriver childDriver = switchToChildWindow(mainWindow);
*return new popupPage(childDriver,configProvider);*
    }
_2nd class Popup Page;_
    public void onMainPage() throws IOException{
       // perform some actions
clickSafely(Element.btn_Continue.locator);
clickSafely(Element.btn_Submit.locator);
log.info <http://log.info>("Clicked on save and done button");
log.info <http://log.info>("Closed popup.");
*return new onMainPage(driver,configProvider);*
    }
Should I be using "return new onMainPage(driver,configProvider);" to
get back to the main page or not?
When I run this test with multiple examples then the new page starts
opening in the popup itself.
At time while I try to access the popup it keeps giving me null
pointer exception while opening the popup
Sometimes it finds 2 windows but fails to switch to the popup
is it something in the glue file that is wrongly done?
Will all these issues I'm so much struck :( I have been trying to
fix for the past 3 weeks but could not manage fixing it.
Please help Any questions please let me know.
--
Sowji
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sowjanya Karumuri
2018-05-07 13:56:58 UTC
Reply
Permalink
Raw Message
@George: Really appreciate your help on this

So yes I have constructors for each class with webdriver as the parameter.

So when I do call mainpage.somefunction in glue file, can I directly call
popuppage.somefunction() immediately and no need to return driver in the
main page like this
*return new onMainPage(driver,configProvider);*

Is this what you are saying, as I see the same in your code example as well.
Post by Sowjanya Karumuri
Hi
I have a scenarios where in I will be needing functions from different
classes.
One class is Main Page. Other class is Popup Page.
Situation is: Main page has a button. When I click on this button then a
new pop up opens and then perform some activities and go back to the main
page again.
I'm unable to understand how I can call functions as I feel that my
control is not going back to the main page from pop-up.
Given Open the main page
Then Click on the button
Then Perform actions on popup
And On the main page variable changes based on popup actions.
Glue File:(Please ignore the syntax.)
public void Open_the main_page() throws Throwable {
mainPage.onMainPage(days);
}
public void Click_on_the_button() throws Throwable {
mainPage.selectVacationDate(sdate);
}
public void Perform_actions_on_popup() throws Throwable {
popupPage.selectFullorHalfDay();
}
public void On_the_main_page_variable_changes_based_on_popup_actions()
throws Throwable {
mainPage.verifyVariable();
}
*onMainPage: perform some actions on main page.*
protected WebDriver switchToChildWindow(String mainWindow) {
log.info("Main window value is:" + mainWindow);
try {
WebDriver popupDriver;
new
WebDriverWait(driver,Integer.parseInt(configProvider.get("popWindow.wait.timeout"))).until(ExpectedConditions.numberOfWindowsToBe(2));
List<String> browserWindows = new ArrayList<String>
(driver.getWindowHandles());
log.info("No of windows open: " + browserWindows.size());
if(browserWindows.size() == 2){
//log.info("Main window value is:" + browserWindows.get(0));
//log.info("Child window value is:" + browserWindows.get(1));
if(!mainWindow.equals(browserWindows.get(1))){
childWindow = browserWindows.get(1);
log.info("Child window value is:" + childWindow);
log.info("Found child window and switched to it.");
}else{
Assert.fail("Unable to switch to popup window");
}
}else{
Assert.fail("ChildWindow is not found.");
}
popupDriver = driver.switchTo().window(childWindow);
//log.info("Switched to Child window with value:" + childWindow);
//log.info("Now the main window will be child window with the value as: "
+ popupDriver.getWindowHandle());
answerChildCert();
log.info(popupDriver.getTitle());
return popupDriver;
} catch (NumberFormatException e) {
Assert.fail("Number format exception is seen: " + e);
} catch (NullPointerException e){
Assert.fail("Null pointer exception is seen: " + e);
}
return driver;
}
public popupPage selectVacationDate(String date) throws
InterruptedException, IOException {
// click on popup
Actions open_popup = new Actions(driver);
open_popup.click(datetoclick).build().perform();
WebDriver childDriver = switchToChildWindow(mainWindow);
*return new popupPage(childDriver,configProvider);*
}
*2nd class Popup Page;*
public void onMainPage() throws IOException{
// perform some actions
clickSafely(Element.btn_Continue.locator);
clickSafely(Element.btn_Submit.locator);
log.info("Clicked on save and done button");
log.info("Closed popup.");
*return new onMainPage(driver,configProvider);*
}
Should I be using "return new onMainPage(driver,configProvider);" to get
back to the main page or not?
When I run this test with multiple examples then the new page starts
opening in the popup itself.
At time while I try to access the popup it keeps giving me null pointer
exception while opening the popup
Sometimes it finds 2 windows but fails to switch to the popup
is it something in the glue file that is wrongly done?
Will all these issues I'm so much struck :( I have been trying to fix for
the past 3 weeks but could not manage fixing it.
Please help Any questions please let me know.
--
Sowji
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
George Dinwiddie
2018-05-07 14:56:16 UTC
Reply
Permalink
Raw Message
Sowji,

It's very hard for me to understand your code in these emails.

My main point is that a single driver instance should be used for all
interactions in a scenario (unless you're implementing a scenario
involving multiple people).

Page objects should provide you with a convenient API for interacting
with the application through the browser. They share the driver when
doing this. They may receive the driver via constructor injection or get
it from a service locator or singleton.

I think you could also refactor your code so the names of your classes
and methods more closely reflect what they are and do.

- George
Post by Sowjanya Karumuri
@George: Really appreciate your help on this
So yes I have constructors for each class with webdriver as the parameter.
So when I do call mainpage.somefunction in glue file, can I directly
call popuppage.somefunction() immediately and no need to return driver
in the main page like this
*return new onMainPage(driver,configProvider);*
Is this what you are saying, as I see the same in your code example as well.
Hi
I have a scenarios where in I will be needing functions from
different classes.
One class is Main Page. Other class is Popup Page.
Situation is: Main page has a button. When I click on this button
then a new pop up opens and then perform some activities and go back
to the main page again.
I'm unable to understand how I can call functions as I feel that my
control is not going back to the main page from pop-up.
Given Open the main page
Then Click on the button
Then Perform actions on popup
And On the main page variable changes based on popup actions.
Glue File:(Please ignore the syntax.)
public void Open_the main_page() throws Throwable {
mainPage.onMainPage(days);
}
public void Click_on_the_button() throws Throwable {
mainPage.selectVacationDate(sdate);
}
public void Perform_actions_on_popup() throws Throwable {
popupPage.selectFullorHalfDay();
}
public void
On_the_main_page_variable_changes_based_on_popup_actions() throws
Throwable {
mainPage.verifyVariable();
}
_onMainPage: perform some actions on main page._
protected WebDriver switchToChildWindow(String mainWindow) {
log.info <http://log.info>("Main window value is:" + mainWindow);
try {
WebDriver popupDriver;
new
WebDriverWait(driver,Integer.parseInt(configProvider.get("popWindow.wait.timeout"))).until(ExpectedConditions.numberOfWindowsToBe(2));
List<String> browserWindows = new ArrayList<String>
(driver.getWindowHandles());
log.info <http://log.info>("No of windows open: " +
browserWindows.size());
if(browserWindows.size() == 2){
//log.info <http://log.info>("Main window value is:" +
browserWindows.get(0));
//log.info <http://log.info>("Child window value is:" +
browserWindows.get(1));
if(!mainWindow.equals(browserWindows.get(1))){
childWindow = browserWindows.get(1);
log.info <http://log.info>("Child window value is:" + childWindow);
log.info <http://log.info>("Found child window and switched to it.");
}else{
Assert.fail("Unable to switch to popup window");
}
}else{
Assert.fail("ChildWindow is not found.");
}
popupDriver = driver.switchTo().window(childWindow);
//log.info <http://log.info>("Switched to Child window with value:"
+ childWindow);
//log.info <http://log.info>("Now the main window will be child
window with the value as: " + popupDriver.getWindowHandle());
answerChildCert();
log.info <http://log.info>(popupDriver.getTitle());
return popupDriver;
} catch (NumberFormatException e) {
Assert.fail("Number format exception is seen: " + e);
} catch (NullPointerException e){
Assert.fail("Null pointer exception is seen: " + e);
}
return driver;
}
    public popupPage selectVacationDate(String date) throws
InterruptedException, IOException {
      // click on popup
Actions open_popup = new Actions(driver);
open_popup.click(datetoclick).build().perform();
WebDriver childDriver = switchToChildWindow(mainWindow);
*return new popupPage(childDriver,configProvider);*
    }
_2nd class Popup Page;_
    public void onMainPage() throws IOException{
       // perform some actions
clickSafely(Element.btn_Continue.locator);
clickSafely(Element.btn_Submit.locator);
log.info <http://log.info>("Clicked on save and done button");
log.info <http://log.info>("Closed popup.");
*return new onMainPage(driver,configProvider);*
    }
Should I be using "return new onMainPage(driver,configProvider);" to
get back to the main page or not?
When I run this test with multiple examples then the new page starts
opening in the popup itself.
At time while I try to access the popup it keeps giving me null
pointer exception while opening the popup
Sometimes it finds 2 windows but fails to switch to the popup
is it something in the glue file that is wrongly done?
Will all these issues I'm so much struck :( I have been trying to
fix for the past 3 weeks but could not manage fixing it.
Please help Any questions please let me know.
--
Sowji
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...