PopUP open while automating http://in.rediff.com/ | Selenium Forum
M
Posted on 20/07/2016
Hello,
I am doing Module 20 Release Year 2015 part 10 working for LoginTest.
When it opens firefox or chrome, it opens pop up. and I tried using closePopupIfPresent() but it does not work.
The popup screen shot is attached
-----------------------------------------------------------------------------------------------------------------
LoginTest.java
-----------------------------------------------------------------------------------------------------------------
package com.selenium.framework.datadriven.portfolio;

import java.util.Hashtable;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.selenium.framework.datadriven.TestBase;
import com.selenium.framework.datadriven.TestBase;
import com.selenium.framework.datadriven.util.Constants;
import com.selenium.framework.datadriven.util.TestDataProvider;
import com.selenium.framework.datadriven.util.Utility;
import com.selenium.framework.datadriven.util.Xls_Reader;

public class LoginTest extends TestBase {

@Test(dataProviderClass = TestDataProvider.class, dataProvider="PortfolioDataProvider")
public void loginTest(Hashtable<String,String> table) throws InterruptedException{
APPLICATION_LOG.debug("Executing test1");
validateRunmodes("loginTest", Constants.PORTFOLIO_SUITE, table.get(Constants.RUNMODE_COL));

openBrowser(table.get(Constants.BROWSER_COL));
Thread.sleep(5000);
closePopupIfPresent();
Thread.sleep(5000);
navigate("testSiteURL");
click("moneyLink_xpath");
click("myPortfolio_xpath");


}

}
-------------------------------------------------------------------------------------------------------------------
TestBase.java //with closepopup function
------------------------------------------------------------------------------------------------------------------
package com.selenium.framework.datadriven;

import java.io.FileInputStream;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.SkipException;

import com.gargoylesoftware.htmlunit.javascript.host.ApplicationCache;
import com.selenium.framework.datadriven.util.Constants;
import com.selenium.framework.datadriven.util.Utility;
import com.selenium.framework.datadriven.util.Xls_Reader;

public class TestBase {

public static Properties prop;
public static Logger APPLICATION_LOG = Logger.getLogger("devpinoyLogger");
WebDriver driver;
public static void init(){
if(prop == null){
String path=System.getProperty("user.dir")+"\\src\\test\\resources\\project.properties";

prop = new Properties();
try {
FileInputStream fs = new FileInputStream(path);
prop.load(fs);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void validateRunmodes(String testName,String suiteName,String dataRunmode){
APPLICATION_LOG.debug("Validating runmode for " + testName + " in suite " + suiteName);
init();
//suite runmode
boolean suiteRunmode=Utility.isSuiteRunnable(suiteName, new Xls_Reader(prop.getProperty("xlsFileLocation")+"Suite.xlsx"));
boolean testRunmode=Utility.isTestCaseRunnable(testName, new Xls_Reader(prop.getProperty("xlsFileLocation")+ suiteName +".xlsx"));
boolean dataSetRunmode=false;
if(dataRunmode.equals(Constants.RUNMODE_YES))
dataSetRunmode=true;

if(!(suiteRunmode && testRunmode && dataSetRunmode)){
APPLICATION_LOG.debug("Skipping the test "+testName+" inside the suite "+ suiteName);
throw new SkipException("Skipping the test "+testName+" inside the suite "+ suiteName);

}
}

public void closePopupIfPresent(){

Set<String> winIds = driver.getWindowHandles();
System.out.println("Total windows -> "+ winIds.size());

if(winIds.size() == 2){
Iterator<String> iter = winIds.iterator();
String mainWinID = iter.next();
String popupWinID = iter.next();
driver.switchTo().window(popupWinID);
driver.close();
driver.switchTo().window(mainWinID);
}
}
/*******************************Generic functions***************************************/
public void openBrowser(String browserName){
if(browserName.equals("Mozilla")){
driver = new FirefoxDriver();
}else if(browserName.equals("Chrome")){
System.setProperty("webdriver.chrome.driver", prop.getProperty("chromedriverexe"));
driver= new ChromeDriver();
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

}
public void navigate(String URLKey){
driver.get(prop.getProperty(URLKey));

}
public void click(String identifier){
if(identifier.endsWith("_xpath"))
driver.findElement(By.xpath(identifier)).click();
else if(identifier.endsWith("id"))
driver.findElement(By.id(identifier)).click();
else if(identifier.endsWith("name"))
driver.findElement(By.name(identifier)).click();


}
public void input(String identifier, String data){

}

}

M
Replied on 21/07/2016

watch latest 2016 videos of module 20.


M
Replied on 21/07/2016

I am confused here.

So you mean I should start watching latest videos of 2016 instead of videos of 2015?


M
Replied on 21/07/2016

[quote="bhavesh3189@gmail.com":1qd46cmd]I am confused here.

So you mean I should start watching latest videos of 2016 instead of videos of 2015?[/quote:1qd46cmd]

handling pop up is a little difficult. but if you want to here are some resources.
http://stackoverflow.com/questions/19403949/how-to-handle-pop-up-in-selenium-webdriver-using-java
https://www.seleniumeasy.com/selenium-tutorials/how-to-handle-windows-popups-using-selenium-webdriver

watch TRAINING VIDEO - 14
SELENIUM WEBDRIVER - 4

[color=#FF0000:1qd46cmd]OR
[/color:1qd46cmd]
you can watch new videos. where you won't encounter unexpected problem.


M
Replied on 13/11/2017

in Chrome it opens a new blank tab too in main browser other than popup. i tried clicking in a text box in rediff page in test, which passes fine with focus on blank tab instead of rediff.com

In chrome after tests run, focus is on main browser and not popup but in main browser new tab is open as shown in shreenshot

Responsive image

M
Replied on 14/11/2017

can you come on skype?