I have a requirement where I would like to read combination of English and non English characters from a dropdown on Web UI
Example- abcd , efgh, 你好, こんにちは
public void test(){
dropdown.click();
Select newValues = new Select(dropdown);
List<WebElement> listNewValues = countryValues.getOptions();
ArrayList<String> actualDropDownItems = new ArrayList();
for(WebElement value : listNewValues){
actualDropDownItems.add(value.getText());
System.out.println(value.getText().toString());
}
If I try to run and print this, I get ?? for Chinese and Japanese values.
Please note I have read some of the previous suggestions and in eclipse at project> properties level> Resource> Other is set to UTF-8.
Everywhere it is suggested to use UTF-8. But what else can I do If I have already set this at project properties level.
Is there any other easier way of getting this non-English characters? Any help is appreciated.
P.S. I had also tried using BufferedWriter approach, but it gives me å›½æ—¥æœ¬ëŒ€í•œë¯¼êµ instead of 你好, こんにちは
Running simple System.out.println("你好"); was not giving me correct output on Eclipse console.
Looks like setting eclipse at project level was not doing anything to help me.
project> properties level> Resource> Other is set to UTF-8
Did right click on test, Coverage As> Coverage configuration > Common and then set Other to UTF-8, solved my problem.
Related
I'm using the Play Framework (Java) and am not able to figure out how to use environment variables in my configuration file for building the database connection string. While I'm able to use environment variables like this (for user name and password):
default.username = ${?FU_MAIN_DB_USERNAME}
default.password = ${?FU_MAIN_DB_PASSWORD}
I'm not able to make it work in the url string. Perhaps this is a simple case of string processing in Scala that I'm missing, but since I'm working in Java, I could use some help.
So far, I have tried the url string in the following formats and failed:
Tried to add a $ to variable name to perform interpolation:
default.url = "jdbc:postgresql://$${?FU_MAIN_DB_HOST}:$${?FU_MAIN_DB_PORT}/$${?FU_MAIN_DB_NAME}";
But this doesn't substitute. Rather, it picks the string as such.
default.url = "jdbc:postgresql://${?FU_MAIN_DB_HOST}:${?FU_MAIN_DB_PORT}/${?FU_MAIN_DB_NAME}";
This too inserts the '$' and all verbatim. Then I thought maybe something like PHP-style will work
default.url = "jdbc:postgresql://${${?FU_MAIN_DB_HOST}}:${${?FU_MAIN_DB_PORT}}/${${?FU_MAIN_DB_NAME}}";
But no.
I also tried doing stuff like "jdbc:postgresql://".concat(${?FU_MAIN_DB_HOST}) ... but this also inserts '.concat' verbatim.
Finally, I tried concatenation using the '+' operator, but I'm told (by my IDE) that symbols like +: etc. are not allowed in the application.conf file.
How then, in God's name, am I supposed to do that?!
The double quotes turn off interpolation. But you need to do that for the : and the //.
Try
default.url = "jdbc:postgresql://"${?FU_MAIN_DB_HOST}":"${?FU_MAIN_DB_PORT}/${?FU_MAIN_DB_NAME}
Maybe you are better off to set the whole thing in one big environment variable instead.
I am using a MessageConsole in Eclipse to display output information. The output is formatted into Error 1 - (MyClass.java:10), which is expected to generate a clickable link to code (MyClass.java line 10, in this case), since the console should be able to parse the pattern (FileName.java:LineNumber) automatically as suggested in this post.
However, it failed to work this way. But when I use System.out.println() to output this pattern directly in the plugin Eclipse, the link can be generated.
I also considered the possibility of multiple consoles in the plugin, but streaming the patterned text to other consoles did not work either. Any insights?
My code is like below:
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
MessageConsole myConsole = new MessageConsole( name, null );
conMan.addConsoles( new IConsole[]{myConsole} );
MessageConsoleStream out = myConsole.newMessageStream();
out.println("Error 1 - (MyClass.java:10)");
Matching for Java code links is only done for consoles which have the javaStackTraceConsole console type.
So you can use the org.eclipse.ui.console.consolePatternMatchListeners extension point to define your own pattern matcher to do the same thing for your console.
Or you can use the:
public MessageConsole(String name, String consoleType, ImageDescriptor imageDescriptor, boolean autoLifecycle)
constructor to specify the console type for your console to match the existing matchers.
when I am trying to call method with parameter using my Polish language f.e.
node.call("ąćęasdasdęczć")
I get these characters as input characters.
Ä?Ä?Ä?asdasdÄ?czÄ
I don't know where to set correct encoding in maven pom.xml? or in my IDE? I tried to change UTF-8 to ISO_8859-2 in my IDE setting, but it didn't work. I was searching similiar questions, but I didn't find the answer.
#Edit 1
Sample code:
public void findAndSendKeys(String vToSet , By vLocator){
WebElement element;
element = webDriverWait.until(ExpectedConditions.presenceOfElementLocated(vLocator));
element.sendKeys(vToSet);
}
By nameLoc = By.id("First_Name");
findAndSendKeys("ąćęasdasdęczć" , nameLoc );
Then in input field I got Ä?Ä?Ä?asdasdÄ?czÄ. Converting string to Basic Latin in my IDE helps, but It's not the solution that I needed.
I have also problems with fields in classes f.e. I have class in which I have to convert String to basic Latin
public class Contacts{
private static final By LOC_ADDRESS_BTN = By.xpath("//button[contains(#aria-label,'Wybór adresu')]");
// it doesn't work, I have to use basic latin and replace "ó" with "\u00f3" in my IDE
}
#Edit 2 - Changed encoding, but problem still exists
1:
Here is what happens.
User types in "лос ан"
I have a bunch of products whose location is "лос анджелис"
if I do:
String userInput = "лос ан"
for(Product product : products) {
if(product.getCity().trim().toLowerCase().contains(userInput.trim().toLowerCase())) {
System.out.println("MATCH");
}
}
I don't get MATCH.
This works for Latin characters
try specifying Locale in toLowerCase() on both sides of the equation: http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toLowerCase(java.util.Locale)
The editor and the compiler (javac -encoding) must use the same encoding.
The compiler encoding are done easily. The editor, source encoding, can be tested with a programmer's editor like NotePad++ or JEdit, which can switch encodings.
You can also u-escape the Java source text to check this:
String userInput = "\u043b\u043e\u0441 \u0430\u043d";
If that does not work, there is a discrepancy between the encodings.
Furthermore String.toLowerCase(new Locale("ru", "RU")) or such is already mentioned.
Using jdk 1.8.0_45, the following code gives a match in both cases:
System.out.println("лос анджелис".trim().toLowerCase().contains("лос ан".trim().toLowerCase()));
System.out.println("лос анджелис".trim().toLowerCase(Locale.ROOT).contains("лос ан".trim().toLowerCase(Locale.ROOT)));
As others already mentioned, you may look for a working Locale as argument to String#toLowerCase.
I hope someone could help me with some issue.
I'm using OWASP ESAPI 2.1.0 with JavaEE, to help me to validate some entries in a web application. At some point I needed to validate a Windows file path, so I added a new property entry in the 'validation.properties' like this one:
Validator.PathFile=^([a-zA-Z]:)?(\\\\[\\w. -]+)+$
When I try to validate, for example, a string like "C:\TEMP\file.txt" via ESAPI, I get a ValidationException:
ESAPI.validator().getValidInput("PathFile", "C:\\TEMP\\file.txt", "PathFile", 100, false);
Alternatively, I also tried the java.util.regex.Pattern class to test the same regular expression with the same string example and it works OK:
Pattern.matches("^([a-zA-Z]:)?(\\\\[\\w. -]+)+$", "C:\\TEMP\\file.txt")
I must say that I added other regex in 'validation.properties' and worked OK. Why this one is so hard? Could anyone help me out with this one?
This is happening because the call to validator().getValidInput("PathFile", "C:\\TEMP\\file.txt", "PathFile", 100, false); wraps a call to ESAPI.encoder().canonicalize() that is transforming the input to the char sequence (Not literal String!) C:TEMP'0x0C'ile.txt before it passes to the regex engine.
Except for the second "\" getting converted to the char 0x0c this is normally desired behavior. That could be a bug in ESAPI.
What you want, is to make a call to ESAPI.validator().getValidDirectoryPath()