UnsupportedCommandException while executing seleium script with firefox 59.0.3 (64-bit) gecko driver 0.15 - selenium-firefoxdriver

I am a beginner in Selenium. This is my code I am executing. I am using Selenium-Java-3.3.1 version, Firefox 59.0.3 (64-bit) and gecko driver 0.15 version
package selenium_test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class TestClass {
WebDriver driver;
public void invokeBrowser() {
try {
System.setProperty("webdriver.gecko.driver", "D:\\GEGDC\\KT00475829\\Downloads\\geckodriver-v0.15.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get("https://stg2-magic.health.ge.com:13007/enovia/common/emxNavigator.jsp");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[]) {
TestClass myObj = new TestClass();
myObj.invokeBrowser();
}
}
Below is my error:
org.openqa.selenium.UnsupportedCommandException: timeouts
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10
09:00:17 -0800'
System info: host: 'TMIC-PCS2200', ip: '3.235.34.200', os.name: 'Windows 7',
os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Please help me in solving my error.

Related

Android studio: How to create BiometricManager and other bugs

So as a homework from collage i have to make a simple login app using fingerprint, i followed this video: How to Make a FingerPrint Authentication System in Android Studio and Java
But im getting some error that aren't explained and i can't find a answer form, this is my code:
package com.example.actividad14;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import android.graphics.Color;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.concurrent.Executor;
public class MainActivity extends AppCompatActivity {
#RequiresApi(api = Build.VERSION_CODES.Q)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView msg_txt = findViewById(R.id.txt_msg);
Button login_btn = findViewById(R.id.login_btn);
BiometricManager biometricManager = BiometricManager.from(this);
switch (biometricManager.canAuthenticate()){
case BiometricManager.BIOMETRIC_SUCCESS:
msg_txt.setText("You can use the fingerprint sensor to login");
msg_txt.setTextColor(Color.parseColor("#Fafafa"));
break;
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
msg_txt.setText("The device doesn't have a fingerprint sensor");
login_btn.setVisibility(View.GONE);
break;
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
msg_txt.setText("The biometric sensor is currently unavailable");
login_btn.setVisibility(View.GONE);
break;
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
msg_txt.setText("Your device doesn't have any fingerprint saved, please check your security settings");
login_btn.setVisibility(View.GONE);
break;
}
Executor executor = ContextCompat.getMainExecutor(this);
BiometricPrompt biometricPrompt = new BiometricPrompt(MainActivity.this, executor, new androidx.biometric.BiometricPrompt.AuthenticationCallback() {
#Override
public void onAuthenticationError(int errorCode, #NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
}
#Override
public void onAuthenticationSucceeded(#NonNull androidx.biometric.BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(getApplicationContext(),"Login Succes!", Toast.LENGTH_SHORT).show();
}
#Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
});
final BiometricPrompt.PrompInfo prompInfo = BiometricPrompt.PrompInfo.Builder()
.setTitle("Login")
.setDescription("Use your fingerprint to login in your app")
.setNegativeButtonText("Cancel")
.build();
login_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
biometricPrompt.authenticate(prompInfo);
}
});
}
}
At BiometricManager biometricManager = BiometricManager.from(this); im getting "cannot resolve method 'from' in 'biometricmanager'", but every video i have seen says that you create your BiometricManager this way.
At BiometricPrompt biometricPrompt = new BiometricPrompt(MainActivity.this, executor, new androidx.biometric.BiometricPrompt.AuthenticationCallback() { im getting "'BiometricPrompt' has private access in 'android.hardware.biometrics.BiometricPrompt'".
At final BiometricPrompt.PrompInfo prompInfo = BiometricPrompt.PrompInfo.Builder() im getting "cannot resolve PromptInfo"
And finally at biometricPrompt.authenticate(prompInfo); im getting "cannot resolve method '(authenticate(BiometricPrompt.PrompInfo))'"
Sorry for the inconvinience, i fount out what was wrong, instead of using:
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.BiometricPrompt;
use
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
in the build.gradle i used
implementation 'androidx.biometric:biometric:1.2.0-alpha04'
But this can depend on new updates, so try with the newer ones also:
https://mvnrepository.com/artifact/androidx.biometric/biometric?repo=google
And finally i had PrompInfo instead of PromptInfo
This other post really helped me:
Android BiometricPrompt: Cannot resolve symbol PromptInfo

in android studio doing face detection using opencv. E/AndroidRuntime: FATAL EXCEPTION: main

I am doing face detection application using opencv.the app is installed in the phone but due to fatal error it get closed suddenly. this is my MainActivity.java
package com.example.oc2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraActivity;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.JavaCameraView;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2{
JavaCameraView javaCameraView;
File cascfile;
CascadeClassifier facedetector;
private Mat mRgba,mGrey;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(!OpenCVLoader.initDebug())
{
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_4_0,this, baseCallback);
}
else
{
try {
baseCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
} catch (IOException e) {
e.printStackTrace();
}
}
javaCameraView.setCvCameraViewListener(this);
}
#Override
public void onCameraViewStarted(int width, int height) {
mRgba=new Mat();
mGrey=new Mat();
}
#Override
public void onCameraViewStopped() {
mGrey.release();
mRgba.release();
}
#Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba=inputFrame.rgba();
mGrey=inputFrame.gray();
MatOfRect facedetection= new MatOfRect();
facedetector.detectMultiScale(mRgba,facedetection);
for(Rect rect: facedetection.toArray())
{
Imgproc.rectangle(mRgba,new Point(rect.x,rect.y),new Point(rect.x+rect.width,rect.y+rect.height),new Scalar(255,0,0));
}
return mRgba;
}
private final BaseLoaderCallback baseCallback=new BaseLoaderCallback(this) {
#Override
public void onManagerConnected(int status) throws IOException {
switch (status)
{
case LoaderCallbackInterface.SUCCESS:
{
InputStream is = getResources().openRawResource(R.raw.haarcascade_frontalface_alt2);
File cascadedir=getDir( "cascade" , Context.MODE_PRIVATE);
cascfile= new File(cascadedir, "haarcascade_frontalface_alt2.xml" );
FileOutputStream fos= new FileOutputStream(cascfile);
byte[] buffer=new byte[4096];
int bytesread;
while((bytesread = is.read(buffer))!=-1)
{
fos.write(buffer,0,bytesread);
}
is.close();
fos.close();
facedetector=new CascadeClassifier(cascfile.getAbsolutePath());
if(facedetector.empty())
{
facedetector=null;
}
else
{
cascadedir.delete();
}
javaCameraView.enableView();
}
break;
default:
{
super.onManagerConnected(status);
}
break;
}
}
};
}
this are my errors can anyone help?
D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION:
main
Process: com.example.oc2, PID: 19468
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.oc2/com.example.oc2.MainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
org.opencv.android.JavaCameraView.enableView()' on a null object
reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6864)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.opencv.android.JavaCameraView.enableView()'
on a null object reference
at com.example.oc2.MainActivity$1.onManagerConnected(MainActivity.java:116)
at com.example.oc2.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:7232)
at android.app.Activity.performCreate(Activity.java:7221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2964)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:201) 
at android.app.ActivityThread.main(ActivityThread.java:6864) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
I/Process: Sending signal. PID: 19468 SIG: 9
if anyone could give steps to resolving the errors it would be very helpful.
I have two feelings about your code:
1 - in your onCreate activity you are missing a line as:
javaCameraView = (CameraBridgeViewBase) findViewById(R.id.java_camera_view);
2 - you are not checking if the camera permission was granted, which may cause you another error later ["it seems that your device does not support camera or it is locked - application will be closed"]
So have a test with this snippet but consider that in order to have it working you will need to enable the camera permission for the app before launching the app [Settings->Apps->YourApp->Permissions->Camera]. The permission part must be rewritten properly, this is just for a quick test
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
javaCameraView = (CameraBridgeViewBase) findViewById(R.id.java_camera_view);
// added for black screen
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Permissions granted");
javaCameraView.setCameraPermissionGranted();
javaCameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_FRONT);
javaCameraView.setVisibility(CameraBridgeViewBase.VISIBLE);
javaCameraView.setCvCameraViewListener(this);
} else {
Log.d(TAG, "Troubles");
}
}

Spark launcher handle not updating state on Standalone cluster mode

I'm trying to programmatically submit Spark jobs using the Spark Launcher library in a spring web application.
Everything works fine with yarn-client, yarn-cluster and standalone-client modes. However, when using standalone-cluster mode, the getState() of SparkAppHandle stays in UNKNOWN forever. Any advice? Thanks.
Here is the code of the Service
import org.apache.spark.launcher.SparkAppHandle;
import org.apache.spark.launcher.SparkLauncher;
import org.springframework.stereotype.Service;
#Service
public class SparkServices {
public String launchJob(String master, String mode) throws Exception {
SparkAppHandle handle = new SparkLauncher()
.setAppName("test1")
.setSparkHome("/usr/local/spark")
.setAppResource("hdfs://nn:9000/spark-application.jar")
.setMainClass("my.App")
.setMaster(master)
.setDeployMode(mode)
.setConf("spark.executor.instances", "2")
.setConf("spark.driver.memory", "2g")
.setConf("spark.driver.cores", "1")
.setConf("spark.executor.memory", "2g")
.setConf("spark.executor.cores", "1")
.addAppArgs("hdfs://nn:9000/spark-project/files/")
.setVerbose(true)
.startApplication(new SparkAppHandle.Listener() {
#Override
public void stateChanged(SparkAppHandle sparkAppHandle) {
System.out.println("state >>> " + sparkAppHandle.getState());
}
#Override
public void infoChanged(SparkAppHandle sparkAppHandle) {
System.out.println("info >>> " + sparkAppHandle.getState());
}
});
while (!handle.getState().isFinal()){
System.out.println("state >>> " + handle.getState());
Thread.sleep(10000);
}
return "finished with >>>" + handle.getState();
}
}
And the code of Controller
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class TaskController {
#Autowired
private SparkServices sparkServices;
#GetMapping("/sparkJobs/{master}/{mode}")
public String sparkJob(#PathVariable("master") String master, #PathVariable("mode") String mode) throws Exception {
return sparkServices.launchJob(master, mode);
}
}

How to create one instance of WebDriver per thread for parallel execution

I am taking input for test from Data Provider where Data Provider is used in parallel.
Method will run in parallel so i want to create separate instance of WebDriver per method
Tried till now:
public class Demo {
private static final ThreadLocal<WebDriver> webDriverThreadLocal= new InheritableThreadLocal<>();
public static Logger log = Logger.getLogger(Demo.class.getName());
#BeforeMethod
public void beforeMethod() {
WebDriver driver=null;
DOMConfigurator.configure("log4j.xml");
Random random = new Random();
int cnt=random.nextInt(2);
if(cnt == 0) {
driver = new FirefoxDriver();
System.out.println(" New Firefox Driver Instantiated");
log.info("New Firefox Driver Instantiated");
}
else if(cnt == 1) {
System.setProperty("webdriver.chrome.driver","path");
driver = new ChromeDriver();
System.out.println(" New Chrome Driver Instantiated");
log.info("New Chrome Driver Instantiated");
}
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().window().maximize();
webDriverThreadLocal.set(driver);
}
#Test(dataProvider = "dp1")
public void testPrelogin(TestCase testCase) {
WebDriver driver = webDriverThreadLocal.get();
//here call static methods of different classes for each screen
}
#DataProvider(name ="dp1",parallel=true)
public Object[][] dp() {
return new Object[][] {
new Object[] { 1, "a" },
new Object[] { 2, "b" },
};
}
#AfterMethod
public void afterClass() {
WebDriver driver = webDriverThreadLocal.get();
System.out.println("In after method for id:"+Thread.currentThread().getId()+" "+driver);
driver.quit();
}
Testng.xml
<suite name="Suite" parallel="methods" data-provider-thread-count="2">
<test name="prelogin" >
<classes>
<class name="com.package.Demo" />
</classes>
</test>
</suite>
With the above code multiple browsers are launched but out of 2 test atleast one of my test fails as browser screen becomes blank.
Is it because in some way thread resources are shared like webDriver or any other issue?

Connecting to Bluetooth when trying to get Current Geographic Location in J2ME

I had done A Simple Application to Record Current Geographic Location and Display it on Mobile Screen then its working fine in j2me emulator but when application installed in mobile(Nokia Asha 210) it installed and opening directly to connecting to bluetooth. It is opening the bluetooth settings where the problem i cant understand so i need help regarding this issue..
This is my Entire Code....
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.location.Location;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import javax.microedition.location.QualifiedCoordinates;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class LocationWithPolling extends MIDlet implements Runnable, CommandListener {
Form mainform;
Thread t;
LocationProvider lp;
Display display;
StringItem latitude;
StringItem longitude;
Command exitCommand=new Command("Exit",Command.OK,0);
protected void destroyApp(boolean arg0) {}
protected void pauseApp() {}
protected void startApp() throws MIDletStateChangeException
{
mainform=new Form("Location Polling");
latitude=new StringItem("Latitude:","N/A");
longitude=new StringItem("Longitude:","N/A");
Display.getDisplay(this).setCurrent(mainform);
mainform.append(latitude);
mainform.append(longitude);
mainform.addCommand(exitCommand);
mainform.setCommandListener(this);
t=new Thread(this);
t.start();
}
public void run()
{
try{
lp = LocationProvider.getInstance(null);
while(true)
{
Location loc=lp.getLocation(5000);
QualifiedCoordinates c=loc.getQualifiedCoordinates();
latitude.setText(String.valueOf(c.getLatitude()));
longitude.setText(String.valueOf(c.getLongitude()));
Thread.sleep(5000);
}
}catch(Exception e)
{
Alert alert =
new Alert("Error", "Could not retrieve location!", null, AlertType.ERROR);
display.setCurrent(alert);
}
}
public void providerStateChanged(LocationProvider provider, int newState) { }
public void commandAction(Command cmd, Displayable arg1)
{
if(cmd==exitCommand)
{
notifyDestroyed();
}
}
}
Asha phones do not have internal GPS, so it attempts to connect to a bluetooth GPS, and you apparently have none paired with the phone. That is why I think it opens BT settings. If you had one, it would connect to it.

Resources