CDI Can't inject FirefoxDriver (Selenium) - selenium

I'm trying to use CDI to inject firefox when i need it (Avoiding to always configure the driver). But i'm always getting NullPointer.
I created a producer for the firefox driver
#ApplicationScoped
public class FirefoxDriverProducer {
#Produces #RequestScoped
public FirefoxDriver getDriver() {
// Inicia o Firefox pelo Selenium
String caminhoFirefox = "/usr/bin/firefox";
String profileFirefox = "Selenium";
// Aponta o caminho para o firefox
File pathToBinary = new File(caminhoFirefox);
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
// Profile que precisa ser criado no firefox
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile(profileFirefox);
// Proxy
String PROXY = "companyproxy:8080";
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY).setFtpProxy(PROXY).setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
FirefoxDriver driver = new FirefoxDriver(ffBinary, myprofile, cap);
return driver;
}
public void close(#Disposes FirefoxDriver driver) {
driver.quit();
}
}
And when i want to use it i call it like this:
#Inject
private FirefoxDriver driver;
Like any other object i would like to inject.
But i'm always getting NullPointer, when i try to debug the driver it is always null, by placing a breakpoint inside the producer method getDriver() it's not even being called...
On the same project i've already done something similar, with FacesContext and NavigationHandler, they both worked fine.
ps: I'm running Wildfly 8, and beans.xml is on my web-inf.
ps2: The reason why i'm doing this is because i need to access another company site and download some information from time to time, since they don't provide no web service or anything else, only through web browser.
ps3: If i don't use CDI and take all the code from the producer and put it on the class i'm calling it works fine. So i'm assuming that it's not a problem with Selenium
The stack tracer:
16:48:29,632 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-43) #{testeBean.teste()}: java.lang.NullPointerException: javax.faces.FacesException: #{testeBean.teste()}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) [jsf-impl-2.2.8-jbossorg-1.jar:]
at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.2.8-jbossorg-1.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.8-jbossorg-1.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [jsf-impl-2.2.8-jbossorg-1.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.2.8-jbossorg-1.jar:]
... 33 more
Caused by: java.lang.NullPointerException
at br.com.timbrasil.bluemonster.csr.DownloadCsr.<init>(DownloadCsr.java:49) [classes:]
at br.com.timbrasil.bluemonster.csr.TesteBean.teste(TesteBean.java:24) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_25]
at javax.el.ELUtil.invokeMethod(ELUtil.java:308) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
at javax.el.BeanELResolver.invoke(BeanELResolver.java:537) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
at com.sun.el.parser.AstValue.invoke(AstValue.java:286) [javax.el-3.0.1-b05.jar:]
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304) [javax.el-3.0.1-b05.jar:]
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.2.8-jbossorg-1.jar:]
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8]
... 34 more
16:48:29,642 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-43) javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at br.com.timbrasil.bluemonster.csr.DownloadCsr.<init>(DownloadCsr.java:49)
at br.com.timbrasil.bluemonster.csr.TesteBean.teste(TesteBean.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at javax.el.ELUtil.invokeMethod(ELUtil.java:308)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
at com.sun.el.parser.AstValue.invoke(AstValue.java:286)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 34 more
#Edit
My Download class, where i have the FireFoxDriver injected:
public class DownloadCsr {
#Inject
private FirefoxDriver driver;
public DownloadCsr(String usuario, String senha, LocalDateTime dataInicial,
LocalDateTime dataFinal) throws LoginException {
driver.get("https://companysite.net");
// Encontra o elemento para inserir o usuario
WebElement webUsuario = getElementByLocator(By.name("USER"), driver);
// Insere o usuario
webUsuario.sendKeys(usuario);
// Encontra o elemento para inserir a senha
WebElement webSenha = getElementByLocator(By.name("PASSWORD"), driver);
// Insere a senha
webSenha.sendKeys(senha);
// Acha o bot�o de login e clica
WebElement button = getElementByLocator(By.name("IMAGE1"), driver);
button.click();
// Confere se logou na pagina verificando o titulo dela, do contrario
// lança a exceção
if (!driver.getTitle().equals("Business Home")) {
throw new LoginException("Can't reach the loged-in page");
}
}
For testing i'm using the following.
#Named
#RequestScoped
public class TesteBean implements Serializable {
public void teste() {
LocalDateTime dataInicial = LocalDateTime.now().minusDays(1);
LocalDateTime dataFinal = LocalDateTime.now();
try {
new DownloadCsr("login", "password",
dataInicial, dataFinal);
} catch (LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Your problem comes from the fact that DownloadCsr is not a bean. It has a constructor with parameters and you instantiate it in your class TesteBean. To get the CDI feature you have to let the CDI container instantiate the beans for you and provide all needed information as other injectable bean. In other word : using new give you an unmanaged an uninjected instance.
It's also a bad practice to put business code in a constructor. Constructor should contains only initialisation code. During constructor none of the field are injected yet so even if your DownloadCsr met requirement to be bean you would have a NPE in your constructor.
What you could do is something like that:
#Named
#RequestScoped
public class TesteBean implements Serializable {
#Inject
private DownloadCsr dcsr;
public void teste() {
LocalDateTime dataInicial = LocalDateTime.now().minusDays(1);
LocalDateTime dataFinal = LocalDateTime.now();
try {
dcsr.crawl("login","password", dataInicial, dataFinal);
} catch (LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
with the following DownloadCsr
public class DownloadCsr {
#Inject
private FirefoxDriver driver;
public void crawl(String usuario, String senha, LocalDateTime dataInicial,
LocalDateTime dataFinal) throws LoginException {
driver.get("https://companysite.net");
// Encontra o elemento para inserir o usuario
WebElement webUsuario = getElementByLocator(By.name("USER"), driver);
// Insere o usuario
webUsuario.sendKeys(usuario);
// Encontra o elemento para inserir a senha
WebElement webSenha = getElementByLocator(By.name("PASSWORD"), driver);
// Insere a senha
webSenha.sendKeys(senha);
// Acha o boto de login e clica
WebElement button = getElementByLocator(By.name("IMAGE1"), driver);
button.click();
// Confere se logou na pagina verificando o titulo dela, do contrario
// lança a exceção
if (!driver.getTitle().equals("Business Home")) {
throw new LoginException("Can't reach the loged-in page");
}
}
}

Related

Cucumber failed to instantiate class, steps undefined

I keep getting these errors every time I try to run my test using cucumber with selenium:
cucumber.runtime.CucumberException: Failed to instantiate class br.gov.pb.receita.atfbdd.steps.arrecadacao.ConsultarLancamentoARR001 - this class doesn't have an empty or a page enabled constructor"
at cucumber.runtime.SerenityObjectFactory.newInstance(SerenityObjectFactory.java:66)
at cucumber.runtime.SerenityObjectFactory.cacheNewInstance(SerenityObjectFactory.java:51)
at cucumber.runtime.SerenityObjectFactory.getInstance(SerenityObjectFactory.java:41)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)
at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)
at cucumber.runner.TestStep.executeStep(TestStep.java:55)
at cucumber.runner.TestStep.run(TestStep.java:42)
at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:53)
at cucumber.runner.TestCase.run(TestCase.java:47)
at cucumber.runner.Runner.runPickle(Runner.java:44)
at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:140)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73)
at net.serenitybdd.cucumber.CucumberWithSerenity.runChild(CucumberWithSerenity.java:144)
at net.serenitybdd.cucumber.CucumberWithSerenity.runChild(CucumberWithSerenity.java:45)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at net.serenitybdd.cucumber.CucumberWithSerenity$1.evaluate(CucumberWithSerenity.java:153)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at cucumber.runtime.SerenityObjectFactory.newInstance(SerenityObjectFactory.java:63)
... 36 more
Caused by: java.lang.NullPointerException
at br.gov.pb.receita.atfbdd.steps.arrecadacao.ConsultarLancamentoARR001.<init>(ConsultarLancamentoARR001.java:34)
... 41 more
cucumber.runtime.junit.UndefinedThrowable: The step "Eu solicito a funcionalidade Consultar Lan�amento" is undefined
cucumber.runtime.junit.UndefinedThrowable: The step "Eu informar os dados para consulta" is undefined
cucumber.runtime.junit.UndefinedThrowable: The step "O sistema valida as informa��es e executa a consulta" is undefined
cucumber.runtime.junit.UndefinedThrowable: The step "O sistema exibe uma lista contendo os lan�amentos obtidos" is undefined
I've tried to run my step class whith and whitout ScenarioSteps and, as you can see, it does have an empty constructor.
But, even extending ScenarioSteps in my step class, I'm keep getting these errors "cucumber.runtime.junit.UndefinedThrowable: The step is undefined", as shown above.
Here's my step class:
#CucumberOptions(features = "classpath:features/arrecadacao/")
public class ConsultarLancamentoARR001 extends ScenarioSteps {
Selenium selenium;
public ConsultarLancamentoARR001() {
}
ConsultarLancamentoPage consultarLancamento = new ConsultarLancamentoPage(selenium.getDriver());
LoginPage loginPage = new LoginPage(selenium.getDriver());
#Step
#Given("^Eu desejo acessar o sistema ATF$")
public void euDesejoAcessarAtf() throws Exception {
selenium.getDriver().navigate().to(ConfiguracaoATF.URL_ADDRESS_DES);
}
#Step
#When("^Eu informo as credenciais de login$")
public void euInformoCredenciaisLogin() throws Exception {
loginPage.logarSistemaViaCredenciaisUsuario(DadosConfigARR.USUARIO_ADMIN_DES, DadosConfigARR.SENHA_ADMIN_DES);
}
#Step
#Then("^Eu devo logar no sistema com sucesso$")
public void euLogoComSucesso() throws Exception {
assertEquals("Lotação:", selenium.getDriver().findElement(By.xpath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[3]/td[1]")));
}
#Step
#Given("^Eu solicito a funcionalidade Consultar Lançamento$")
public void euSolicitoConsultarLancamento() throws Exception {
consultarLancamento.acessarFuncionalidadeARR_001();
}
#Step
#When("^Eu informar os dados para consulta$")
public void euInformoDadosConsulta() throws Throwable {
consultarLancamento.informarNumeroLancamento(DadosConfigARR.NOSSO_NUMERO_REG1);
consultarLancamento.descerBarraDeRolagemCompletamente();
consultarLancamento.clicarBotaoConsultarLancamento();
Thread.sleep(2000);
}
#Step
#Then("^O sistema valida as informações e executa a consulta$")
public void oSistemaValidaInformacoes() throws Throwable {
consultarLancamento.naoSelecionarNenhumItem();
Thread.sleep(2000);
assertEquals("Selecione um item", consultarLancamento.capturarPopupAlerta());
consultarLancamento.detalharLancamento();
Thread.sleep(5000);
}
#Step
#And("^O sistema exibe uma lista contendo os lançamentos obtidos$")
public void oSistemaExibeLancamentos() throws Throwable {
consultarLancamento.detalharLancamento();
Thread.sleep(5000);
}
}
Here's my runner:
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(
features = "src/test/resources/features/arrecadacao/",
glue = "classpath:br.gov.pb.receita.atfbdd.steps.arrecadacao")
public class CucumberRunnerARR {
protected static WebDriver driver;
#BeforeClass
public static void beforeClass() throws Exception {
driver = Selenium.getInstance().getDriver();
driver.manage().window().maximize();
// LoginPage loginPage = new LoginPage(driver);
// loginPage.logarSistemaViaCredenciaisUsuario(DadosConfigARR.USUARIO_ADMIN_DES, DadosConfigARR.SENHA_ADMIN_DES);
}
#AfterClass
public static void afterClass() throws Exception {
driver.quit();
}
}
Here's my .feature:
Feature: Consultar lançamento
O usuário consulta um lançamento no sistema ATF
Background: O usuário está logado
Given Eu desejo acessar o sistema ATF
When Eu informo as credenciais de login
Then Eu devo logar no sistema com sucesso
#CT015
Scenario: Fluxo básico de eventos
Given Eu solicito a funcionalidade Consultar Lançamento
When Eu informar os dados para consulta
Then O sistema valida as informações e executa a consulta
And O sistema exibe uma lista contendo os lançamentos obtidos
And, if it helps, here's how the project is organized:
project explorer
What am I doing wrong?
Pretty sure i had this issue, below are my package.json files, ensure you are using the same versions of everything, i believe something is too high of a version or too low of a version, i cannot remember which way round it was.
{
"name": "hellocucumber",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cls && cucumber-js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^4.1.2",
"chromedriver": "^2.41.0",
"cucumber": "^4.2.1",
"node-key-sender": "^1.0.10",
"selenium-cucumber-js": "^1.5.13"
},
"dependencies": {
"gherkin": "^5.1.0",
"selenium-webdriver": "^4.0.0-alpha.1"
}
}
I know you're not using a package.json file, however if you use my version numbers to go off, you should be able to figure out if the versions are the same as the ones you have imported into your project.

Utils - ERROR - Error java.lang.NullPointerException in Selenium

Error
[RemoteTestNG] detected TestNG version 6.14.2
Total rows are 5
[Utils] [ERROR] [Error] java.lang.NullPointerException
at appops_main_home.LaunchPortalData.passUNamePwd(LaunchPortalData.java:41)
at appops_main_home.LaunchPortal.TestDataFeed(LaunchPortal.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45)
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:131)
at org.testng.internal.Parameters.handleParameters(Parameters.java:706)
at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:49)
at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:37)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:923)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
SKIPPED: Loginapp
java.lang.RuntimeException: java.lang.NullPointerException
at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:49)
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:131)
at org.testng.internal.Parameters.handleParameters(Parameters.java:706)
at org.testng.internal.ParameterHandler.handleParameters(ParameterHandler.java:49)
at org.testng.internal.ParameterHandler.createParameters(ParameterHandler.java:37)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:923)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.NullPointerException
at appops_main_home.LaunchPortalData.passUNamePwd(LaunchPortalData.java:41)
at appops_main_home.LaunchPortal.TestDataFeed(LaunchPortal.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45)
... 22 more
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
===============================================
This is my code
package appops_main_home;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
//import utility.Constant;
//import excel.input.login.LaunchPortalData;
public class LaunchPortal
{
ChromeDriver driver ;
#Test(dataProvider = "testdata")
public void Loginapp(String W3ID, String W3Pwd) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Users\\KalaivaniBaskaran\\Desktop\\088619\\Selenium\\Jar & drivers\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get("http://testurl");
driver.findElement(By.id("desktop")).sendKeys(W3ID);
driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div/form/input[4]")).sendKeys(W3Pwd);
driver.findElement(By.id("btn_signin")).click();
Assert.assertTrue("Invalid credentials", driver.getTitle().matches("Hybrid Cloud Portal"));
System.out.println("Login successful");
}
#AfterMethod
public void closebrowser()
{
driver.quit();
}
#DataProvider(name="testdata")
public Object[][] TestDataFeed()
{
LaunchPortalData config = new LaunchPortalData("C:\\Users\\KalaivaniBaskaran\\Desktop\\088619\\test excel datas\\Usernamepwd_AppOps.xlsx");
int r = config.Rowcountcalculator();
System.out.println("Total rows are "+r);
Object[][] credentials = new Object[r][2];
for (int i=0; i<r; i++)
{
credentials[i][0] = config.passUNamePwd(0, i, 0);
credentials[i][1] = config.passUNamePwd(0, i, 1);
}
return credentials;
}
}
and this is the data
package appops_main_home;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
public class LaunchPortalData {
XSSFWorkbook wb ;
XSSFSheet sheet0;
public LaunchPortalData(String excelPath) {
try {
File src = new File(excelPath);
FileInputStream fis = new FileInputStream(src);
wb = new XSSFWorkbook(fis);
sheet0 = wb.getSheetAt(0);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int Rowcountcalculator()
{
int Rowcount = sheet0.getLastRowNum();
return Rowcount;
}
public String passUNamePwd(int sheetnumb, int row, int column)
{
String data = wb.getSheetAt(sheetnumb).getRow(row).getCell(column).getStringCellValue();
return data;
}}
Please check by changing your passUNamePwd as below
public String passUNamePwd(int sheetnumb, int rowIndex, int columnIndex)
{
XSSFSheet sheet=wb.getSheetAt(sheetnumb);
String data="";
Row row=sheet.getRow(rowIndex);
Cell c=row.getCell(columnIndex, row.RETURN_BLANK_AS_NULL);
if(c==null){
data="";
}
else{
data=row.getCell(columnIndex).getStringCellValue();
}
return data;
}

Exception while taking screenshot null and FAILED CONFIGURATION: #AfterMethod teardown

I am facing some trouble and got stuck since yesterday; unable to figure out the cause for it. Tried solution of answers here.
I created #Test, with sample of code to login and check dashaboard of application.
and #AfterMethod, for when Assert is false, should capture a screenshot.
If i comment the Aftermethod code it works fine without any issue;
It used to run fine w/o any problem earlier.
Could you please help me in finding some solution. (it may be very small thing for you.. but pls do help me)
(EDITED) Error i am getting is
[TestNG] Running:
C:\Users\Lenovo\AppData\Local\Temp\testng-eclipse--1410131027\testng-customsuite.xml
Exception while taking screenshot null
FAILED CONFIGURATION: #AfterMethod teardown([TestResult name=dashboardSanityTest status=FAILURE method=loginMain.dashboardSanityTest()[pri:0, instance:demotest.loginMain#1bce4f0a] output={null}])
java.lang.NullPointerException
at demotest.loginMain.teardown(loginMain.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:703)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
SKIPPED CONFIGURATION: #AfterMethod teardown
FAILED: dashboardSanityTest
java.lang.NullPointerException
at demotest.loginMain.dashboardSanityTest(loginMain.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
#AfterMethod Code
#AfterMethod
public void teardown(ITestResult result)
{
if (result.getStatus()==ITestResult.FAILURE)
{
String screenshotPath = Utils.captureScreenshot(driver, result.getName());
String image = logger.addScreenCapture(screenshotPath);
}
report.flush();
}
Utils class
public class Utils {
public static String captureScreenshot(WebDriver driver, String ScreenshotName)
{
try
{
TakesScreenshot ts = (TakesScreenshot)driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String dest="./screenshot/"+ScreenshotName+".png";
File snapshotDest =new File(dest);
FileUtils.copyFile(source, snapshotDest);
System.out.println("Screenshot Taken at "+System.currentTimeMillis());
return dest;
}
catch (Exception e)
{
System.out.println("Exception while taking screenshot "+e.getMessage());
return e.getMessage();
}
}
}
Since you have not mentioned complete error stacktrace, it is a bit difficult to identify exact cause of failure. Please check whether driver value is getting null.
I would suggest you to leverage ITestListener instead of using method with #AfterMethod. You simply need to implement ITestListenerwhich will take the screenshot for you on test failure.
public class Listener implements ITestListener {
public WebDriver driver;
#Override
public void onStart(ITestContext arg0) {
Reporter.log("About to begin executing Test " + arg0.getName(), true);
}
#Override
public void onFinish(ITestContext arg0) {
Reporter.log("Completed executing test " + arg0.getName(), true);
}
#Override
public void onTestFailure(ITestResult arg0) {
try {
String fileName = String.format("Screenshot-%s.jpg", Calendar
.getInstance().getTimeInMillis());
driver = (WebDriver) arg0.getTestContext().getAttribute("WebDriver");
TakesScreenshot ts = (TakesScreenshot)driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String dest="./screenshot/"+ fileName;
File snapshotDest =new File(dest);
FileUtils.copyFile(source, snapshotDest);
Reporter.log("Screen Shots file : " + dest);
} catch (Exception e) {
throw new RuntimeException("Failed to take screenshot !", e);
}
}
}
Thanks !

time out error in selenium

This is the code I am trying to run
package com.memoir.client.widgets.memogen;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.DefaultSelenium;
#SuppressWarnings("deprecation")
public class TestHomepage extends SeleneseTestCase {
#Override
#Before
public void setUp() throws Exception {
//selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://64.79.128.233/staging/");
selenium = new DefaultSelenium("localhost", 4444, "*firefox /usr/bin/firefox", "https://64.79.128.233/staging/");
selenium.start();
}
#Test
public void testTesting4() throws Exception {
selenium.setSpeed("2000");
selenium.windowMaximize();
//selenium.open("/memosyn/");
selenium.open("/staging/");
selenium.waitForPageToLoad("60000");
//Checking for page layout in the beginning of the web page
assertEquals("1", selenium.getElementIndex("//*[#id='isc_G']"));
assertEquals("Please contact support#systems.com for questions or comments.", selenium.getText("id=contactText"));
//assertEquals("MemoWeb V3.3.5963M", selenium.getText("//*[#id='isc_WidgetCanvas_1_widget']/div/table/tbody/tr/td[2]"));
assertEquals("14", selenium.getElementHeight("scLocator=//VLayout[ID=\"loginBox\"]/"));
assertEquals("447", selenium.getElementWidth("scLocator=//VLayout[ID=\"loginBox\"]/"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email]/title"));
assertEquals("207", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email]/title"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password]/title"));
assertEquals("207", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password]/title"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe]/textbox"));
assertEquals("203", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe]/textbox"));
assertEquals("22", selenium.getElementHeight("scLocator=//Button[ID=\"submitButton\"]/"));
assertEquals("100", selenium.getElementWidth("scLocator=//Button[ID=\"submitButton\"]/"));
assertEquals("MemoWeb", selenium.getTitle());
assertEquals("Email :", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email||title=Email]/title"));
assertEquals("Password :", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password||title=Password]/title"));
assertEquals("Remember me on this computer", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe||title=Remember%20me%20on%20this%20computer]/textbox"));
}
#Override
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
I get the following error
com.thoughtworks.selenium.SeleniumException: Timed out after 30000ms
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:106)
at com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:369)
at com.memoir.client.widgets.memogen.testlayout.testTesting4(testlayout.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:230)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Why does it time out at 30000ms even when I request for 60000ms with waitForPageToLoad?
You are setting the waitForPageToLoad() after open(), and therefore it uses 30000.
Change the order, and try again..
selenium.waitForPageToLoad("60000");
selenium.open("/staging/");

WizardDialog.open() throw NullPointerException

I am trying to add NewCSSWizard on the toolbar. For this I used Platform Command Framework, add command and handler extension points. extends WizardHandler but it doesn't work and throws NPE. If in method executeHandler(ExecutionEvent) I create own wizard - it works well.
public class NewCssWizardHandler extends WizardHandler
{
#Override
protected void executeHandler(ExecutionEvent event)
{
try
{
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
WizardDialog wizardDialog = new WizardDialog(window.getShell(), new NewCSSWizard());
wizardDialog.open();
}
catch (ExecutionException e)
{
e.printStackTrace();
}
}
#Override
protected String getWizardIdParameterId()
{
return IWorkbenchCommandConstants.FILE_NEW_PARM_WIZARDID;
}
#Override
protected IWizardRegistry getWizardRegistry()
{
return PlatformUI.getWorkbench().getNewWizardRegistry();
}
}
Stacktrace:
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:212)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:831)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:724)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:708)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:647)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.NullPointerException
at org.eclipse.ui.ide.IDE.computeSelectedResources(IDE.java:1480)
at org.eclipse.wst.css.ui.internal.wizard.NewCSSWizard.addPages(NewCSSWizard.java:48)
at org.eclipse.jface.wizard.WizardDialog.createContents(WizardDialog.java:605)
at org.eclipse.jface.window.Window.create(Window.java:431)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
at org.eclipse.jface.window.Window.open(Window.java:790)
at com.sdad.sdk.ui.actions.NewCssWizardHandler.executeHandler(NewCssWizardHandler.java:27)
at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:279)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
Looks like you passed a null argument to computeSelectedResources. Just do a null check before calling that method. I'm assuming that the code you are working on is NewCSSWizard.java.
public class NewFileHandler extends AbstractHandler implements IHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil
.getActiveWorkbenchWindowChecked(event);
System.out.println("window ok");
NewFileWizard nfw = new NewFileWizard();
nfw.init(PlatformUI.getWorkbench(), new StructuredSelection());
WizardDialog dialog = new WizardDialog(window.getShell(), nfw);
System.out.println("new WizardDialog");
dialog.open();
System.out.println("dialog open");
return null;
}
}