Unable To Perform Actions In Appium Because PageFactory Not Identified - selenium-webdriver

I want to launch and perform actions like enter username details in application
but my execution is failing again and again because of error
My Code
public class VerifyProjectFromApp {
WebDriver driver;
AppLaunch toDoistAppLaunch;
HomePage homePage;
LoginPage login;
#BeforeMethod
public void startapplication() {
toDoistAppLaunch= new AppLaunch(driver);
this.driver=toDoistAppLaunch.launchApplication();
}
#Test
public void verifyCreatedProjectInApp() {
try{
//-Read create project value from properties file
Properties prop = new Properties();
InputStream input = null;
input = new FileInputStream(System.getProperty("user.dir") +
File.separator +"TodoistInputData.properties");
prop.load(input);
//-Read uuid from properties file
String email_id = prop.getProperty("email_id");
System.out.println("\t" + "email_id =" + email_id + "\r\n");
//-Read project name from properties file
String password = prop.getProperty("password");
System.out.println("\t" + "projectName =" + password + "\r\n");
login = new LoginPage(driver);
homePage = new HomePage(driver);
login.loginInApplication(email_id, password);
Utils.waitForPageLoadingToComplete(driver);
homePage.clickOnSideMenu();
Utils.pauseTestExecution(10);
} catch (Exception e) {
e.printStackTrace();
}
}
===================================================
public class LoginPage {
public static final String packageName = "com.todoist";
AndroidDriver<MobileElement> driver;
public LoginPage(WebDriver driver){
this.driver = (AndroidDriver<MobileElement>)driver;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
#AndroidFindBy(id=packageName+":id/btn_welcome_continue_with_email")
MobileElement continueButtonWithGmail;
#AndroidFindBy(id=packageName+":id/email_exists_input")
MobileElement enterEmailId;
#AndroidFindBy(id=packageName+":id/log_in_password")
MobileElement enterPassword;
#AndroidFindBy(id=packageName+":id/btn_continue_with_email")
MobileElement loginwithGmail;
#AndroidFindBy(id=packageName+":id/btn_log_in")
MobileElement loginButton;
public void clickOnContinueButtonWithGmail() {
continueButtonWithGmail.click();
}
public void enterEmailAddress(String emailId) {
enterEmailId.sendKeys(emailId);
}
public void enterPassword(String pass) {
enterPassword.sendKeys(pass);
}
public void clickOnGmailButton() {
loginwithGmail.click();
}
public void clickOnLoginButton() {
loginButton.click();
}
public void loginInApplication(String emailId,String password) {
try {
clickOnContinueButtonWithGmail();
Utils.waitForPageLoadingToComplete(driver);
enterEmailAddress(emailId);
Utils.waitForPageLoadingToComplete(driver);
clickOnGmailButton();
Utils.waitForPageLoadingToComplete(driver);
enterPassword(password);
Utils.waitForPageLoadingToComplete(driver);
clickOnLoginButton();
} catch(Exception e) {
e.printStackTrace();
}
}
=============================================================================================
Error Coming
[TestNG] Running:
C:\Users\Daffodil-255\AppData\Local\Temp\testng-eclipse--467741697\testng-customsuite.xml
Print app path E:\TodoistAutomation\Android_Todoist_Project\apkfile\Todoist_v12.8_apkpure.com.apk
Jul 25, 2018 11:57:52 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
email_id =tarun.dabbs#daffodilsw.com
projectName =123456
Jul 25, 2018 11:57:52 AM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown method' (405 expected)
FAILED CONFIGURATION: #AfterMethod closeApplication
org.openqa.selenium.UnsupportedCommandException: Method has not yet been implemented
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
System info: host: 'DAFFODILLAP-265', ip: '172.18.1.128', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_65'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: E:\TodoistAutomation\Androi..., appActivity: com.todoist.activity.HomeAc..., appPackage: com.todoist, appium-version: 1.8.1, databaseEnabled: false, desired: {app: E:\TodoistAutomation\Androi..., appActivity: com.todoist.activity.HomeAc..., appPackage: com.todoist, appium-version: 1.8.1, deviceName: Nexus5X1, platformName: android, platformVersion: 7.1.1}, deviceManufacturer: Google, deviceModel: Android SDK built for x86, deviceName: emulator-5554, deviceScreenSize: 1080x1920, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: Android, platformVersion: 7.1.1, takesScreenshot: true, warnings: {}, webStorageEnabled: false}
Session ID: 7333c28b-2ec8-48b2-89c0-b04e2c90ec74
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:46)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:438)
at com.todoist.tests.VerifyProjectFromApp.closeApplication(VerifyProjectFromApp.java:61)
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:497)
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)
FAILED: verifyCreatedProjectInApp
java.lang.NoClassDefFoundError: net/sf/cglib/proxy/MethodInterceptor
at com.todoist.pages.LoginPage.<init>(LoginPage.java:22)
at com.todoist.tests.VerifyProjectFromApp.verifyCreatedProjectInApp(VerifyProjectFromApp.java:46)
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:497)
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)
Caused by: java.lang.ClassNotFoundException: net.sf.cglib.proxy.MethodInterceptor
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 26 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter#19bb089b: 171 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter#35bbe5e8: 14 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter#6bdf28bb: 8 ms
[TestNG] Time taken by org.testng.reporters.jq.Main#1fbc7afb: 65 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2#129a8472: 15 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 11 ms

Issue happens due this:
ClassNotFoundException: net.sf.cglib.proxy.MethodInterceptor
to fix this you need to add cglib:cglib dependency:
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.2.7</version>
</dependency>
hope this helps,

Add both cglib and asm dependency in your project. This will solve your problem.
cglib-3.2.7.jar
asm-6.2.jar

Related

Webdriver: Browser is launched. But not calls URL when GeckoDriver is used

Actually I have installed all latest versions. My firefox browser launches. But URL is not called.
Following are my System details.
OS: Ubuntu 14.04
Firefox Version: 56.0
Selenium Server: selenium-server-standalone-3.6.0
GeckoDriver: geckodriver-v0.19.0-linux64
Browser Launch Code
if(BrowserCode.equalsIgnoreCase("FF"))
{
System.setProperty("webdriver.gecko.driver",System.getProperty("user.dir")+"/AllDrivers/geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
}
I am getting following eror. Can anyone please help me in this.
[TestNG] Running:
/home/vishalpachpute/workspace/ER_CustomerCare/ERCC_Login.xml
/home/vishalpachpute/workspace/ER_CustomerCare
1507724942300 geckodriver INFO geckodriver 0.19.0
1507724942306 geckodriver INFO Listening on 127.0.0.1:3966
1507724942723 mozrunner::runner INFO Running command: "/usr/lib/firefox/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.qsoDFMATTikn"
1507724942948 addons.xpi WARN Error parsing extensions state: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [amIAddonManagerStartup.readStartupData]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm :: loadExtensionState :: line 1554" data: no] Stack trace: loadExtensionState()#resource://gre/modules/addons/XPIProvider.jsm:1554 < getInstallState()#resource://gre/modules/addons/XPIProvider.jsm:1589 < checkForChanges()#resource://gre/modules/addons/XPIProvider.jsm:3109 < startup()#resource://gre/modules/addons/XPIProvider.jsm:2188 < callProvider()#resource://gre/modules/AddonManager.jsm:269 < _startProvider()#resource://gre/modules/AddonManager.jsm:739 < startup()#resource://gre/modules/AddonManager.jsm:906 < startup()#resource://gre/modules/AddonManager.jsm:3090 < observe()#jar:file:///usr/lib/firefox/omni.ja!/components/addonManager.js:65
1507724943785 Marionette INFO Enabled via --marionette
(firefox:22169): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:22169): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(firefox:22169): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(firefox:22169): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:22219): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:22219): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:22219): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
(/usr/lib/firefox/firefox:22219): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1507724946494 Marionette INFO Listening on port 38903
1507725070118 Marionette WARN TLS certificate errors will be ignored for this session
1507725070153 Marionette DEBUG Register listener.js for window 2147483649
Oct 11, 2017 6:01:10 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
1507725070269 Marionette DEBUG Received DOM event "beforeunload" for "about:blank"
1507725160564 Marionette DEBUG Received DOM event "beforeunload" for "about:blank"
1507725160566 Marionette DEBUG Received DOM event "pagehide" for "about:blank"
1507725160567 Marionette DEBUG Received DOM event "unload" for "about:blank"
1507725160612 Marionette DEBUG Received DOM event "DOMContentLoaded" for "about:neterror?e=netTimeout&u=http%3A//localhost%3A8888/ercc/&c=UTF-8&f=regular&d=The%20server%20at%20localhost%20is%20taking%20too%20long%20to%20respond."
org.openqa.selenium.WebDriverException: Reached error page: about:neterror?e=netTimeout&u=http%3A//localhost%3A8888/ercc/&c=UTF-8&f=regular&d=The%20server%20at%20localhost%20is%20taking%20too%20long%20to%20respond.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'vfrootThinkPadT450', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-30-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=/tmp/rust_mozprofile.qsoDFMATTikn, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, moz:headless=false, platform=LINUX, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=56.0, platformVersion=3.16.0-30-generic, moz:processID=22169, browserName=firefox, javascriptEnabled=true, platformName=LINUX}]
Session ID: 12542456-e71a-40f4-944d-c476840f3c99
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:310)
at com.vodafone.er.cc.test.integration.PlatformLayer.LaunchApplication.Execute(LaunchApplication.java:173)
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:498)
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.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:616)
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)
===============================================
ER
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
Attached my full LaunchApplication.java file for more details
package com.vodafone.er.cc.test.integration.PlatformLayer;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
//import java.sql.Date;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import atu.testng.reports.ATUReports;
import atu.testrecorder.ATUTestRecorder;
import atu.testrecorder.exceptions.ATUTestRecorderException;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
/*#Listeners({ ATUReportsListener.class, ConfigurationListener.class,
MethodListener.class })*/
public class LaunchApplication {
{
System.setProperty("atu.reporter.config", "./atu.properties");
}
public static WebDriver driver=null;
ATUTestRecorder recorder;
Date date;
#BeforeTest (alwaysRun = true)
#Parameters({"RunUsingSG","BrowserCode","URL","Title","Platform","Version"})
public void Execute(String RunUsingSG,String BrowserCode,String URL,String Title,String Platform,String Version) throws IOException, InterruptedException, ATUTestRecorderException
{
System.out.println(System.getProperty("user.dir"));
DesiredCapabilities dc=new DesiredCapabilities();
//This code is for recording. if you want to do recording, just uncomment the following code.
/*DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH-mm-ss");
Date date = new Date();
// For Recording the Execution using ATU Reporter.
recorder = new ATUTestRecorder("./ScriptVideos","TestVideo-" +dateFormat.format(date),false);
recorder.start();*/
// For IE 32 Bits
if(BrowserCode.equalsIgnoreCase("IE32"))
{
dc.setBrowserName("internet explorer");
dc.setVersion(Version);
if(RunUsingSG.equalsIgnoreCase("Y"))
{driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc);}
else
{
System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"/AllDrivers/IEDriverServer_32bit_OS.exe");
driver = new InternetExplorerDriver();
}
}
// For PhantomJS
if(BrowserCode.equalsIgnoreCase("PJS"))
{
dc.setJavascriptEnabled(true);
dc.setVersion(Version);
dc.setBrowserName("Phantom JS");
dc.setCapability("phantomjs.binary", "/AllDrivers/phantomjs");
driver = new PhantomJSDriver(dc);
}
//For IE 64 Bits
if(BrowserCode.equalsIgnoreCase("IE64"))
{
//System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"/AllDrivers/IEDriverServer_64bit_OS.exe");
System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"/AllDrivers/IEDriverServer_x64_2.41.0/IEDriverServer_V2.41_64bit.exe");
dc.setBrowserName("internet explorer");
dc.setVersion(Version);
if(RunUsingSG.equalsIgnoreCase("Y"))
{
driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc);
}
else
{
//System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"/AllDrivers/IEDriverServer_64bit_OS.exe");
System.setProperty("webdriver.ie.driver",System.getProperty("user.dir")+"/AllDrivers/IEDriverServer_x64_2.41.0/IEDriverServer_V2.41_64bit.exe");
driver = new InternetExplorerDriver();}
}
/*//For Firefox
if(BrowserCode.equalsIgnoreCase("FF"))
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
dc.setBrowserName("firefox");
//dc.setVersion(Version);
if(RunUsingSG.equalsIgnoreCase("Y"))
{
driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc);
}
else
{
driver=new FirefoxDriver();
}
}*/
//For Firefox GeckoDriver
if(BrowserCode.equalsIgnoreCase("FF"))
{
System.setProperty("webdriver.gecko.driver",System.getProperty("user.dir")+"/AllDrivers/geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
driver.get("URL");
}
// For Chrome
if(BrowserCode.equalsIgnoreCase("CH"))
{
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
dc.setCapability("chrome.binary","./AllDrivers/chromedriver/");
dc.setCapability(ChromeOptions.CAPABILITY, options);
dc.setBrowserName("Google Chrome");
dc.setVersion(Version);
if(RunUsingSG.equalsIgnoreCase("Y"))
{
driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc);
}
else
{
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"/AllDrivers/chromedriver");
driver = new ChromeDriver(dc);
}
}
if(Platform.equalsIgnoreCase("WINDOWS"))
try
{
{dc.setPlatform(org.openqa.selenium.Platform.WINDOWS);}
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get(URL);
Thread.sleep(3000);
Assert.assertEquals(driver.getTitle(), Title);
driver.manage().window().maximize();
Thread.sleep(2000);
// ATU Reports
ATUReports.setWebDriver(LaunchApplication.driver);
ATUReports.indexPageDescription = "ER-CC Automation Scripts Results.";
}
catch (Exception e)
{
Reporter.log("Exception occured " +e.getMessage());
e.printStackTrace();
Assert.fail();
driver.quit();
}
}
#AfterTest
//#Parameters({"RunUsingSG","BrowserCode","URL","Title","Platform","Version"})
public void TearDown() throws MalformedURLException, ATUTestRecorderException
{
driver.close();
//driver.quit();
//recorder.stop();
}
}
This code dont have any URL
if(BrowserCode.equalsIgnoreCase("FF"))
{
System.setProperty("webdriver.gecko.driver",System.getProperty("user.dir")+"/AllDrivers/geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("URL"); //add it
}

PersistenceContext EntityManager (JPA)

I am creating a Java EE application using jpa.
The problem in #PersistenceContext(unitName = "airline") when i comment this line it give me error null_pointer_exception and when put it getting the following error when the code is run on server.
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Info: visiting unvisited references
Severe: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
Severe: java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [com.airline.service.PassengerService/entityManager] in the scope of the module called [FlightPassengersJPA]. Please verify your application.
at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUViaEMRef(BundleDescriptor.java:731)
at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUsViaPCRefs(BundleDescriptor.java:719)
at org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl.findReferencedPUs(WebBundleDescriptorImpl.java:1037)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:186)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)
Severe: Exception while preparing the app
Severe: Exception during lifecycle processing
java.lang.RuntimeException: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [com.airline.service.PassengerService/entityManager] in the scope of the module called [FlightPassengersJPA]. Please verify your application.
at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUViaEMRef(BundleDescriptor.java:731)
at com.sun.enterprise.deployment.BundleDescriptor.findReferencedPUsViaPCRefs(BundleDescriptor.java:719)
at org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl.findReferencedPUs(WebBundleDescriptorImpl.java:1037)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:186)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:925)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:434)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)
Severe: Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-context-ref-name [com.airline.service.PassengerService/entityManager] in the scope of the module called [FlightPassengersJPA]. Please verify your application.
and my code :
AddPassenger.java
package com.airline.controllers;
import com.airline.models.FlightClass;
import com.airline.models.Gender;
import com.airline.models.Passenger;
import com.airline.service.PassengerService;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
#WebServlet(name = "AddPassenger", urlPatterns = {"/AddPassenger"})
public class AddPassenger extends HttpServlet {
#EJB
private PassengerService passengerService;
#Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
Passenger passenger = new Passenger();
passenger.setFirstName("Loai");
passenger.setLastName("Amr");
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 1996);
cal.set(Calendar.MONTH, 9);
cal.set(Calendar.DAY_OF_MONTH, 30);
Date dob = cal.getTime();
passenger.setDob(dob);
passenger.setGender(Gender.Male);
passenger.setFlightClass(FlightClass.Couch);
passengerService.addPassenger(passenger);
System.out.println("First name : " + passenger.getFirstName());
}
#Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
#Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
and class PassengerService :
package com.airline.service;
import com.airline.models.Passenger;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
#Stateless
#LocalBean
public class PassengerService {
public PassengerService() {
}
#PersistenceContext(unitName = "airline")
private EntityManager entityManager;
public void addPassenger(Passenger passenger) {
entityManager.persist(passenger);
System.out.println("Done");
}
}
and persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="FlightPassengersJPAPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/airline</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
You need to define your persistence-unit in a file named persistence.xml. This should reside as resource in META-INF.
An example for that you can see in:
persistence.xml... The datasources you see there is defined in the configuration of the wildfly as you can see it in standalone.xml
In a similar way I think you have do define the datasource in glassfish.

How to catch AngularJS Error with Protractor

I'm experiencing some problem while E2E testing an AngularJS app with Protractor. To sum things up: I have the following specification and the first step always fails with a btstrpd error. (The page is auto-bootstrapped and we use AngularJS v1.3.0 and Protractor v2.1.0.)
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://myapp.abc.de/ext/#/login');
expect(browser.getTitle()).toEqual('My App');
});
it('should do other stuff', function() {
// ...
});
});
Error:
1) Protractor Demo App should have a title
Message:
UnknownError: unknown error: [ng:btstrpd] http://errors.angularjs.org/1.3.15/ng/btstrpd?p0=document
(Session info: chrome=43.0.2357.132)
(Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds
(Full description here)
Since I don't seem to find a solution to prevent this error and the remaining test steps run without any problems, my approach would be to simply ignore the error. However I don't want the test case to fail due to it. This brings me to my question: How can I catch this error so that the test won't fail? A plain try-catch around the two statements in the step does not the trick and since I don't have any promises here I also cannot do the typical promise error handling as one would manually handle e.g. a NoSuchElementError.
Edit - Error in webdriver console:
12:06:18.975 INFO - Executing: [new session: Capabilities [{count=1, browserName
=chrome}]])
12:06:18.995 INFO - Creating a new session for Capabilities [{count=1, browserNa
me=chrome}]
Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on
port 23267
Only local connections are allowed.
12:06:21.248 INFO - Done: [new session: Capabilities [{count=1, browserName=chro
me}]]
12:06:21.271 INFO - Executing: [set script timeoutt: 11000])
12:06:21.281 INFO - Done: [set script timeoutt: 11000]
12:06:21.390 INFO - Executing: [get: data:text/html,<html></html>])
12:06:21.405 INFO - Done: [get: data:text/html,<html></html>]
12:06:21.425 INFO - Executing: [execute script: window.name = "NG_DEFER_BOOTSTRA
P!" + window.name;window.location.replace("http://myapp.abc.de/ext/#/login");, [
]])
12:06:23.440 INFO - Done: [execute script: window.name = "NG_DEFER_BOOTSTRAP!" +
window.name;window.location.replace("http://myapp.abc.de/ext/#/login");, []]
12:06:23.458 INFO - Executing: [execute script: return window.location.href;, []
])
12:06:23.468 INFO - Done: [execute script: return window.location.href;, []]
12:06:23.489 INFO - Executing: [execute async script: try { return (function (at
tempts, asyncCallback) {
var callback = function(args) {
setTimeout(function() {
asyncCallback(args);
}, 0);
};
var check = function(n) {
try {
if (window.angular && window.angular.resumeBootstrap) {
callback([true, null]);
} else if (n < 1) {
if (window.angular) {
callback([false, 'angular never provided resumeBootstrap']);
} else {
callback([false, 'retries looking for angular exceeded']);
}
} else {
window.setTimeout(function() {check(n - 1);}, 1000);
}
} catch (e) {
callback([false, e]);
}
};
check(attempts);
}).apply(this, arguments); }
catch(e) { throw (e instanceof Error) ? e : new Error(e); }, [10]])
12:06:25.603 INFO - Done: [execute async script: try { return (function (attempt
s, asyncCallback) {
var callback = function(args) {
setTimeout(function() {
asyncCallback(args);
}, 0);
};
var check = function(n) {
try {
if (window.angular && window.angular.resumeBootstrap) {
callback([true, null]);
} else if (n < 1) {
if (window.angular) {
callback([false, 'angular never provided resumeBootstrap']);
} else {
callback([false, 'retries looking for angular exceeded']);
}
} else {
window.setTimeout(function() {check(n - 1);}, 1000);
}
} catch (e) {
callback([false, e]);
}
};
check(attempts);
}).apply(this, arguments); }
catch(e) { throw (e instanceof Error) ? e : new Error(e); }, [10]]
12:06:25.633 INFO - Executing: [execute script: return (function () {
angular.module('protractorBaseModule_', []).
config(['$compileProvider', function($compileProvider) {
if ($compileProvider.debugInfoEnabled) {
$compileProvider.debugInfoEnabled(true);
}
}]);
}).apply(null, arguments);, []])
12:06:25.643 INFO - Done: [execute script: return (function () {
angular.module('protractorBaseModule_', []).
config(['$compileProvider', function($compileProvider) {
if ($compileProvider.debugInfoEnabled) {
$compileProvider.debugInfoEnabled(true);
}
}]);
}).apply(null, arguments);, []]
12:06:25.663 INFO - Executing: [execute script: angular.resumeBootstrap(argument
s[0]);, [[protractorBaseModule_]]])
12:06:26.093 WARN - Exception thrown
org.openqa.selenium.WebDriverException: unknown error: [ng:btstrpd] http://error
s.angularjs.org/1.3.15/ng/btstrpd?p0=document
(Session info: chrome=43.0.2357.134)
(Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7
d3),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any
stacktrace information)
Command duration or timeout: 10 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'xxxxx', ip: 'xxx.xxx.xx.x', os.name: 'Windows 7', os.arch: '
amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEn
abled=false, chrome={userDataDir=C:\Users\abcdefg\AppData\Local\Temp\scoped_dir1
1436_18156}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true,
version=43.0.2357.134, platform=XP, browserConnectionEnabled=false, nativeEvents
=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true,
browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsE
nabled=true}]
Session ID: 0c39849d960cccef7ec7036b8414c9fb
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.
java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHa
ndler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
va:599)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDri
ver.java:508)
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.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(Even
tFiringWebDriver.java:101)
at com.sun.proxy.$Proxy1.executeScript(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.executeScript
(EventFiringWebDriver.java:213)
at org.openqa.selenium.remote.server.handler.ExecuteScript.call(ExecuteS
cript.java:53)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession
.java:168)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
12:06:26.103 WARN - Exception: unknown error: [ng:btstrpd] http://errors.angular
js.org/1.3.15/ng/btstrpd?p0=document
(Session info: chrome=43.0.2357.134)
(Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7
d3),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any
stacktrace information)
Command duration or timeout: 10 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'xxxx', ip: 'xxx.xxx.xx.x', os.name: 'Windows 7', os.arch: '
amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEn
abled=false, chrome={userDataDir=C:\Users\abcdefg\AppData\Local\Temp\scoped_dir1
1436_18156}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true,
version=43.0.2357.134, platform=XP, browserConnectionEnabled=false, nativeEvents
=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true,
browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsE
nabled=true}]
Session ID: 0c39849d960cccef7ec7036b8414c9fb
12:06:26.203 INFO - Executing: [delete session: f947352d-3b40-4b1b-a46a-9d4ffe32
8b76])
12:06:27.417 INFO - Done: [delete session: f947352d-3b40-4b1b-a46a-9d4ffe328b76]
In your code, I would put a WaitforAngular() to make sure the sync append with Angular & Protractor. See bellow for reference:
it('should have a title', function() {
browser.get('http://myapp.abc.de/ext/#/login');
browser.waitForAngular();
expect(browser.getTitle()).toEqual('My App');
});
Then if it does not work, I would use the browser.pause(); command. This will break the execution of protractor where you use the command. From there you can open the Chrome debuging console to see what is appening exactly.
You can also use the REPL debuging mode it is very convenient way to check that you element are present on the page and that you are using the correct selector.
Please refer to the following link for more informations on debugging with protractor: https://angular.github.io/protractor/#/debugging

Issues with Protractor and Element Explorer resolving elements on page

I am able to run my protractor tests against localhost, but when hitting my in-house test server, I can't get protractor to find elements on the page. The same issues occur with Protractor 1.3.1 and 1.4.0 with the latest Chrome and Firefox drivers.
...AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113
var template = new Error(this.message);
^
Process finished with exit code 1
So I've been trying to use the Element explorer to debug the issue, but it is giving me the following:
> list(by.css('#logindropdown'))
There was a webdriver error: UnknownError unknown error: Runtime.evaluate threw exception: TypeError: Cannot read property 'click' of null
(Session info: chrome=38.0.2125.111)
(Driver info: chromedriver=2.12.301325 (962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 28 milliseconds
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'NB2D1469', ip: '158.147.71.49', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67'
Session ID: 85966371ff89f75af8cf7fb5d15f6f23
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\mprent99\AppData\Local\Temp\scoped_dir6488_12276}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=38.0
.2125.111, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
Simple things like list(by.css('body')) also give the same exception above. Using by.id give the same results, list(by.id('logindropdown'))
Commands that have no results (when they should) seem to avoid the exceptions:
> list(by.css('a .caret'))
[ '' ]
> list(by.css('.caret'))
[ '' ]
In the webdriver-manager terminal, I am seeing the following:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.executeAsyncScript(RemoteWebDriver.java:526)
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:606)
at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:101)
at com.sun.proxy.$Proxy1.executeAsyncScript(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver.executeAsyncScript(EventFiringWebDriver.java:225)
at org.openqa.selenium.remote.server.handler.ExecuteAsyncScript.call(ExecuteAsyncScript.java:55)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:168)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
and
17:05:00.256 INFO - Executing: [execute async script: try { return (function (rootSelector, callback) {
var el = document.querySelector(rootSelector);
try {
if (angular.getTestability) {
angular.getTestability(el).whenStable(callback);
} else {
angular.element(el).injector().get('$browser').
notifyWhenNoOutstandingRequests(callback);
}
} catch (e) {
callback(e);
}
}).apply(this, arguments); }
catch(e) { throw (e instanceof Error) ? e : new Error(e); }, [body]])
17:05:00.562 WARN - Exception thrown
org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: TypeError: Cannot read property 'click' of null
Versions in use:
protractor --version
Version 1.4.0 or Version 1.3.1
node --version
v0.10.30
webdriver-manager status
selenium standalone is up to date
chromedriver is up to date
IEDriver is not present
These same things work just fine in Chrome DevTools:
('.caret')
[<b class=​"caret">​</b>​]
$('a .caret')
[<b class=​"caret">​</b>​]
$('#logindropdown')
[<li id=​"logindropdown" class=​"dropdown ng-scope">​…​</li>​]
$('body')
[<body class=​"vertical-grow">​…​</body>​]
Here is the onPrepare where the failure appears to be happening:
onPrepare: function() {
var username = element(by.model('login.userName'));
var password = element(by.model('login.password'));
browser.driver.get(env.baseUrl);
browser.driver.findElement(by.css('a .caret')).click();
username.sendKeys('user#company.com');
password.sendKeys('password');
browser.driver.findElement(by.css('.btn-primary')).click();
// Login takes some time, so wait until it's done.
// For the test app's login, we know it's done when it redirects to index.html.
browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return (/dashboards/).test(url);
});
}, 5000);
}
Here is the rest of the conf.js:
/*global browser,element,by */
var env = require('./env.js');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'loginTest.js'
],
suites: {
//smoke: 'spec/smoketests/*.js',
//full: 'spec/*.js'
},
directConnect: false,
multiCapabilities: [
// {browserName: 'firefox'}
{browserName: 'chrome'}
],
maxSessions: -1,
framework: 'jasmine',
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
// If true, display spec names.
isVerbose: false,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 360000
},
// Selector for the element housing the angular app - this defaults to
// body, but is necessary if ng-app is on a descendant of <body>
rootElement: 'html'
};
How do I debug this farther and get to the root of this issue?

sending java mail from with in a proxy server

I am trying to send Email using java mail API from with in a proxy server. The code is as follows:
import java.security.Security;
import java.util.Date;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class GmailSender {
public static void main(String[] args) throws AddressException, MessagingException {
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("proxySet","true");
props.setProperty("socksProxyHost","192.168.1.103");
props.setProperty("socksProxyPort","3128");
props.setProperty("mail.smtp.host", "smtp.gmail.com");
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.store.protocol", "pop3");
props.put("mail.transport.protocol", "smtp");
final String username = "proxy_userName";
final String password = "proxy_password";
Session session = Session.getDefaultInstance(props,
new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}});
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress("xxxxxxx#gmail.com"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("xxxxxxx#gmail.com",false));
msg.setSubject("Hello");
msg.setText("How are you");
msg.setSentDate(new Date());
Transport.send(msg);
System.out.println("Message sent.");
}
}
when I run this code following message is displayed.
DEBUG: JavaMail version 1.4.3
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.S MTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTr ansport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLSto re,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLSto re,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.io.IOException: Couldn't connect using unknown socket factory to host, port: smtp.gmail.com, -1; Exception: java.lang.ClassNotFoundException: false
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
at javax.mail.Service.connect(Service.java:313)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at GmailSender.main(GmailSender.java:57)
Caused by: java.io.IOException: Couldn't connect using unknown socket factory to host, port: smtp.gmail.com, -1; Exception: java.lang.ClassNotFoundException: false
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:216)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672)
... 7 more
Caused by: java.lang.ClassNotFoundException: false
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.mail.util.SocketFetcher.getSocketFactory(SocketFetcher.java:322)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:187)
... 8 more
May be the problem is due to the presence of the proxy server. However I could send the mails by logging in to gmail using browser from with in same proxy server.
Kindly suggest as why the programmatic method is failing and the browser method is working.
I would be thankful for any help.
As described in the FAQ, JavaMail can't use a web proxy server directly, although it can use a SOCKS proxy server. If you only have a web proxy server, programs like Corkscrew can help.
Also, see the JavaMail FAQ for the several common mistakes you've made in your program.

Resources