Getting Compile time error in java funciton body [closed] - java

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have created below code in java but getting error during compilation i have gone through with complete code but not able debug the problem
package csaAutomation;
import com.thoughtworks.selenium.SeleneseTestCase;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.util.Date;
import java.util.Date.*;
import java.text.SimpleDateFormat;
public class GuiAutomation extends SeleneseTestCase {
#BeforeTest
public void setUp() throws Exception {
WebDriver driver = new FirefoxDriver();
String baseUrl = "url";
selenium = new WebDriverBackedSelenium(driver, baseUrl);
}
#Test
public void testGUI_Automation() throws Exception {
String VAR_1="30000";
public void GUI_Login_MR_SIT() throws Exception {
selenium.open("/CSAlogin");
selenium.type("//input[#id=\"username\"]", "Administrator");
selenium.type("//input[#id=\"password\"]", "Ari_123");
selenium.click("//img[#src=\"/csaweb/resources/images/buttons/bf_login.gif\"]");
System.out.println("-----------GUI Login Successful-----------");
}
}
#AfterTest
public void tearDown() throws Exception {
selenium.stop();
}
}
Below is the error message :
C:\CSA_GUI_Automation_0.4\src\csaAutomation\GuiAutomation.java:34: illegal start
of expression
public void GUI_Login_MR_SIT();
^
Please assist

You've declared a method inside another method. I'm not sure of the intent of your code but I suspect it will work better if you have:
#Test
public void testGUI_Automation() throws Exception {
String VAR_1="30000";
GUI_Login_MR_SIT();
}
public void GUI_Login_MR_SIT() throws Exception {
selenium.open("/CSAlogin");
selenium.type("//input[#id=\"username\"]", "Administrator");
selenium.type("//input[#id=\"password\"]", "Ari_123");
selenium.click("//img[#src=\"/csaweb/resources/images/buttons/bf_login.gif\"]");
System.out.println("-----------GUI Login Successful-----------");
}
}

public void testGUI_Automation() throws Exception {
String VAR_1="30000";
public void GUI_Login_MR_SIT();
You are trying to declare a method within a method body. This syntax:
is unsupported in Java;
generally has no apparent meaning which could be assigned to it.

Related

Graalvm unknown identifier when passing java object to js

I am trying to run this Graalvm sample code:
package org.homi.scripting.experimental;
import org.graalvm.polyglot.*;
import java.nio.file.*;
import static java.nio.file.StandardWatchEventKinds.*;
import java.io.File;
import java.io.IOException;
public class ScriptEngine {
public static class Name {
#HostAccess.Export public String name = "hello";
#HostAccess.Export
public String getName() {
return name;
}
}
public static void main(String[] args) {
Name n = new Name();
Context context = Context.newBuilder("js")
.allowAllAccess(true)
.allowIO(true)
.allowPolyglotAccess(PolyglotAccess.ALL)
.build();
context.getPolyglotBindings().putMember("name", n);
context.eval("js", "var name = Polyglot.import('name');");
context.eval("js", "console.log(name.getName())");
}
}
I am getting this exception:
Exception in thread "main" TypeError: invokeMember (getName) on org.homi.scripting.experimental.Name#2313052e failed due to: Unknown identifier: getName
at <js> :program(Unnamed:1:12-25)
at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:379)
at ScriptEngine/org.homi.scripting.experimental.ScriptEngine.tester(ScriptEngine.java:43)
at ScriptEngine/org.homi.scripting.experimental.ScriptEngine.main(ScriptEngine.java:29)
I'm new to graalvm, what am I doing wrong? I was following this demo from the documentation (see the section on host interoperability):
https://www.graalvm.org/sdk/javadoc/
The code and the stack trace don't match, for example the code lacks the tester method
at ScriptEngine/org.homi.scripting.experimental.ScriptEngine.tester(ScriptEngine.java:43)
When you specify allowAllAccess(true) you allow all access, so the HostAccess stops being necesary.
The code in the question works for me and prints hello as expected.

How to parameterize exceptions in JUnit5 with hemcrest? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
i want to test all different exceptions with one parameterized test using hemcrest for one method. So that means that Exception1.class, Exception2.class should be parameters. How do i parameterize them, and do it by using hemcrest?
Suppose your method under test returns distinct exceptions according to scenarios, you should parameterize both fixture (for scenarios) and expected (for exceptions).
With a Foo.foo(String input) method to test such as :
import java.io.FileNotFoundException;
public class Foo {
public void foo(String input) throws FileNotFoundException {
if ("a bad bar".equals(input)){
throw new IllegalArgumentException("bar value is incorrect");
}
if ("inexisting-bar-file".equals(input)){
throw new FileNotFoundException("bar file doesn't exit");
}
}
}
it could look like :
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.api.Assertions;
public class FooTest {
#ParameterizedTest
#MethodSource("fooFixture")
void foo(String input, Class<Exception> expectedExceptionClass, String expectedExceptionMessage) {
Assertions.assertThrows(
expectedExceptionClass,
() -> new Foo().foo(input),
expectedExceptionMessage
);
}
private static Stream<Arguments> fooFixture() {
return Stream.of(
Arguments.of("a bad bar", IllegalArgumentException.class, "bar value is incorrect"), Arguments.of("inexisting-bar-file", FileNotFoundException.class, "bar file doesn't exit"));
}
}

Google Firebase real time database updateChildren() method is not working? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
In my application, I am using google firebase real-time database with admin-sdk for Java. When I run a sample program from my machine it works perfectly and updates the given data into firebase db. But, when I try to run the same program from another public server, it's not working. It doesn't throw any exceptions at all. updateChildren() was executed, and then nothing. I tried with onCompletionListener too.There is nothing in there. What might be the problem?
FBManager.java
import com.nexge.firebase.Firebase;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import java.util.HashMap;
class FBManager {
//FIREBASE
public static Firebase fireBase;
public static DatabaseReference dbRef = null;
public static String filePath="key/siva-6d0aa-firebase-adminsdk-1bo0t-e98c5af5d5.json";
public static String databaseUrl="https://siva-6d0aa.firebaseio.com";
public static String projectName="ABES";
public static String databaseChildPath;
public static void main(String[] args) {
try {
databaseChildPath="calls/";
System.out.println("Inside iniDB !");
fireBase = new Firebase(filePath, databaseUrl, projectName, databaseChildPath);
System.out.println("FireBase db created!");
dbRef = fireBase.getDatabaseReference();
System.out.println("Got reference!");
T t = new T();
new Thread(t).start();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
T.java
class T implements Runnable {
public void run() {
try {
String path = "191963944/5e0e44e2-3442-4acd-977a-fea7232c0f0a";
HashMap hm1 = new HashMap();
hm1.put("caller_Recv_Media_IpPort","xxx.xxx.xx.xxx:9811");
HashMap hm2 = new HashMap();
hm2.put("yServer_src_Media_IpPort","xxx.xx.xx.xx:10000");
FBManager.dbRef.child(path).updateChildren(hm1);
FBManager.dbRef.child(path).updateChildren(hm2);
Thread.sleep(10000);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
It seems this is to do with server network issue. Working fine in another server. Closing this question. thanks

Adding a public class to click using xpath with Java Selenium

I am trying to create a public class to click an item on a webpage with selenium by just passing it the xpath and driver I'm using. I want to be able to just do:
ClickByXpath(driver, "/html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/input[1]");
Here's the code I'm using, but it's complaining that the method xpath string is not applicable:
package TestPackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Question {
public static void main(String[] args) throws Exception {
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();
// Go to google
driver.get("http://www.google.com");
//click in the searchbox
ClickByXpath(driver, "/html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/input[1]");
}
public static void ClickByXpath(WebDriver [] driverUsed , String[] XPath_to_click) throws Exception {
driverUsed.findElement(By.xpath(XPath_to_click)).click();
}
}
You are passing a String:
ClickByXpath(driver, "/html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/input[1]");
But you method signature says that you should pass a String Array:
public static void ClickByXpath(WebDriver [] driverUsed , String[] XPath_to_click)
Same problem with your driver! If you change the signature and remove the Arrays, you should be good:
public static void ClickByXpath(WebDriver driverUsed , String XPath_to_click)
Please note that this has nothing to do with Selenium, this is (very?) basic Java programming. You should consider getting some help with learning at least basics of programming first.

FEST: How to use the NoExitSecurityManager properly?

I starting to use FEST to help me to perform unit test on my Java Swing GUI.
For now, I managed to get through the documentation (mostly deprecated) and help me by looking at the Javadoc and the code.
Right now I am stuck on a problem while using the NoExitSecurityManager. The documentation is quite out dated but we can understand the big lines of it.
I simply try to test if my "Quit" MenuItem is working well in my GUI. So, I need to block the System.exit(0) and map the exit status of the program to a JUnit test.
Here is a simplified code I use to perform the test (the tested class is GraphicalUserInterface).
import org.junit.Test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.fest.swing.annotation.RunsInEDT;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.fixture.FrameFixture;
import org.fest.swing.junit.testcase.FestSwingJUnitTestCase;
import org.fest.swing.security.NoExitSecurityManagerInstaller;
public class GraphicalUserInterfaceTest extends FestSwingJUnitTestCase {
private static FrameFixture gui;
private static NoExitSecurityManagerInstaller noExitSecurityManagerInstaller;
#BeforeClass
public static void setUpBeforeClass() throws Exception {
NoExitSecurityManagerInstaller.installNoExitSecurityManager(new ExpectExitSuccess());
}
#AfterClass
public static void tearDownAfterClass() throws Exception {
noExitSecurityManagerInstaller.uninstall();
}
#Override
protected void onSetUp() {
gui = new FrameFixture(robot(), createNewGUI());
gui.show();
}
#RunsInEDT
private GraphicalUserInterface createNewGUI() {
return GuiActionRunner.execute(new GuiQuery<GraphicalUserInterface>() {
protected GraphicalUserInterface executeInEDT() {
return new GraphicalUserInterface();
}
});
}
#Test
public final void testFileMenuQuitMenuItem() {
gui.menuItemWithPath("File", "Quit").click();
}
}
The ExitCallHook are coded like this (you can guess the other one easily).
import static org.junit.Assert.assertTrue;
import org.fest.swing.security.ExitCallHook;
public final class ExpectExitSuccess implements ExitCallHook {
#Override
public void exitCalled(int status) {
assertTrue(status == 0);
}
}
All the tests are performed well and everything seems to be ok except that I get a java.lang.NullPointerException at the end.
So, I wonder what did I do wrong (or what can I improve to not get this nullpointer exception at the end of the test).
I found the solution in the code. In fact, the proper way to do it is the following:
#Test
public final void testFileMenuQuitMenuItem() {
NoExitSecurityManagerInstaller noExitSecurityManagerInstaller =
NoExitSecurityManagerInstaller.installNoExitSecurityManager(new ExpectExitSuccess());
gui.menuItemWithPath("File", "Quit").click();
noExitSecurityManagerInstaller.uninstall();
}
This way prevent to pollute each test with a NoExitSecurityManager.

Categories