How to close the First Webpage Opened | Selenium Forum
M
Posted on 28/11/2016
Hello Ashish,

I am following your 2016 TestNg Hybrid FW model. I see that in the FW desing you have taught us how to close the window after execution of each test. In my case, i need ot login to 2 webpages applicaitions and after i finish the test, the 2nd webpage applicaiton is closed (taken care by the FW ) but the 1st webpage is still left open. How do i close this?

2nd Question...


I have a lot of variables i ahve to use in the applicaition. these variables store values from 2 applications, and which i use it later to compare. Any smart way to organise all these variable in one class and access them? As i am new to java i dont have any idea how i can organise this .

M
Replied on 29/11/2016

Hello Ashish,

I have this implementation in Close Browser.
public String closeBrowser() {
System.out.println("Closing Browser from closeBrowser() Generic Keywords");
//Switch to main/parent window
test.log(LogStatus.INFO,"Closing Browser from closeBrowser() Generic Keywords"+driver.getTitle());
System.out.println("Closing Browser from closeBrowser() Generic Keywords "+driver.getTitle());
tabs=driver.getWindowHandles();

System.out.println("Initial size of tabs: " + tabs.size());
System.out.println("Set List Size after adding handles "+tabs.size());
Iterator<String> it= tabs.iterator();
while(it.hasNext())
{
System.out.println(it.next());
driver.quit();
}

return Constants.PASS;
}


I am using Set Handles, but even if i open 2 windows, this handles returns me a size of 1 and always closes the 2nd window and the first window is left open. And I am calling the close browser from my test like this,

@AfterMethod

public void quitBrowser(){

System.out.println("After Method Calling quitBrowser");
test.log(LogStatus.INFO, "After Method Calling quitBrowser , Closing Browser from quitBrowser()");

if(app!=null)
app.getGenericKeywords().closeBrowser();
}


Please help.


M
Replied on 30/11/2016

[quote:tssgc0ox]I am following your 2016 TestNg Hybrid FW model. I see that in the FW desing you have taught us how to close the window after execution of each test. In my case, i need ot login to 2 webpages applicaitions and after i finish the test, the 2nd webpage applicaiton is closed (taken care by the FW ) but the 1st webpage is still left open. How do i close this?[/quote:tssgc0ox]

use @aftertest or @aftermethod.



[quote:tssgc0ox]
I have a lot of variables i ahve to use in the applicaition. these variables store values from 2 applications, and which i use it later to compare. Any smart way to organise all these variable in one class and access them? As i am new to java i dont have any idea how i can organise this .[/quote:tssgc0ox]

you can use hash tables.