Assert issue in selenium Java - java

I am trying to assert the other language text .While asserting i am getting a error message
Expected: a string containing "Fornavn er et felt som mÃ¥ fylles ut." but: was "Fornavn er et felt som må fylles ut."
Below is the Code i am using in the framework
default void assertElementContainsText(WebElementFacade element, String text) {
try {
Assert.assertThat(element.waitUntilVisible().waitUntilClickable().getText(), CoreMatchers.containsString(text));
} catch (NoSuchElementException e) {
throw new NoSuchElementException("Could not find element " + element);
}
}
Its working fine for the English language when its comparing with other language getting the issue as
Expected: a string containing "Fornavn er et felt som må fylles ut."
but: was "Fornavn er et felt som må fylles ut."

Related

Can't succeed in linking an OpenGL program

Here are my (very simple) shaders:
protected String [] codeTransformateurSommets = {
"#version 400 core",
"void main(void) {",
"const vec4 vertices[3]=vec4[3](vec4(0.25,-0.25,0.5,1.0),",
" vec4(-0.25,-0.25,0.5,1.0),",
" vec4(0.25,0.25,0.5,1.0));",
"gl_position=vertices[gl_VertexID];",
"}"
};
protected String [] codeTransformateurFragments = {
"#version 400 core",
"out vec4 color;",
"void main(void) {",
"color=vec4(1.0,0.0,0.0,1.0);",
"}"
};
Here's how I try to get a program :
private int créeProgrammeOpenGL(){
IntBuffer résultatEditionLiens;
int transformateurSommets,transformateurFaces;
int programme;
transformateurSommets = chargeTransformateur(GL4.GL_VERTEX_SHADER,codeTransformateurSommets);
transformateurFaces = chargeTransformateur(GL4.GL_FRAGMENT_SHADER, codeTransformateurFragments);
programme = gl4.glCreateProgram();
gl4.glAttachShader(programme, transformateurSommets);
gl4.glAttachShader(programme, transformateurFaces);
gl4.glLinkProgram(programme);
if(programme!=0) {
résultatEditionLiens=IntBuffer.allocate(1);
gl4.glGetProgramiv(programme, GL4.GL_LINK_STATUS, résultatEditionLiens);
if (résultatEditionLiens.get(0) == 0) {
gl4.glDeleteProgram(programme);
throw new RuntimeException("Erreur à la création du programme!!");
} else {
gl4.glUseProgram(programme);
gl4.glDeleteShader(transformateurSommets);
gl4.glDeleteShader(transformateurFaces);
}
} else {
throw new RuntimeException("Erreur à la création du programme!!");
}
return(programme);
}
public static int chargeTransformateur(int type, String [] codeTransformateur){
int transformateur,i,j;
IntBuffer résultatCompilation;
transformateur = gl4.glCreateShader(type);
if(transformateur!=0) {
// création réussie : lui indiquer le code source
gl4.glShaderSource(transformateur,codeTransformateur.length,codeTransformateur,null);
// compiler le code source
gl4.glCompileShader(transformateur);
// récupérer le diagnostic de création du shader
byte [] infoLog=new byte[10000];
int [] taille=new int[100];
gl4.glGetShaderInfoLog(transformateur,1000,taille,0,infoLog,0);
// récupérer le résultat de la compilation
résultatCompilation=IntBuffer.allocate(1);
gl4.glGetShaderiv(transformateur,GL4.GL_COMPILE_STATUS,résultatCompilation);
if(résultatCompilation.get(0)==0) {
// la compilation a échoué!
throw new RuntimeException("Erreur à la compilation du shader!!"+"\r\n"+"\r\n"+codeTransformateur+"\r\n"+"\r\n"+infoLog.toString()+"\r\n"+"\r\n"+"\r\n");
}
} else {
// la création est un échec!
throw new RuntimeException("Erreur à la création du nom du shader!!"+"\r\n"+codeTransformateur);
}
return(transformateur);
}
And the result is a GL_LINK_STATUS set to false when glLinkProgram returns.
My investigations :
calling glGetShaderiv with parameter GL_COMPILE_STATUS returns true for both shaders.
calling glGetProgramiv function with parameter GL_ATTACHED_SHADERS returns 1 after the first attachment and 2 after the second.
Any idea about what I am doing wrong?
The major is is, that you've to set the source code to the shader object by glShaderSource rather than reading the source code string from a shader object by glGetShaderSource.
See Java Code Examples for com.jogamp.opengl.GL2.glShaderSource().
What you actually do, is to compile "empty" shader objects (of course with out any errors). But linking fails, because the vertex shader does not write to gl_Position (of course, because it is "empty").
If you want to create and initialize an array of vec4, then the correct syntax is:
(See Array constructors)
const vec4 vertices[3] = vec4[3](
vec4(0.25,-0.25,0.5,1.0),
vec4(-0.25,-0.25,0.5,1.0),
vec4(0.25,0.25,0.5,1.0));
Furthermore, OpenGL Shading Language (GLSL) is case sensitive. It is gl_Position rather than gl_position:
gl_position=vertices[gl_VertexID];
gl_Position = vertices[gl_VertexID];
I recommend to get the compile error messages by glGetShaderInfoLog. See Java Code Examples for org.lwjgl.opengl.GL20.glCompileShader()

How do I stop a while loop without exiting it (Java)

Hello so I have a question to Java (I'm new so dont excpext too much).
I want to just print everything from the method once and not the whole time.
The method is called 'kuehlschrankInformationen'.
So my question is, how do I just run the methode once and then he starts me asking again, what I want to do. Here is the code(the text is german but I guess it wont make any difference):
System.out.println("Geben Sie ein, was Sie mit dem Kühlschrank machen wollen:");
USER_INPUT = input.nextLine();
while(true){
if (USER_INPUT.equalsIgnoreCase("Ich möchte meinen Kühlschrank schließen")){
TimeUnit.SECONDS.sleep(1);
System.out.println("Das System wird nun herunter gefahren, bis bald");
TimeUnit.SECONDS.sleep(3);
System.exit(0);
}
else if (USER_INPUT.equalsIgnoreCase("Was ist die derzeitige Temperatur im Kühlschrank")){
kuehlschrankTemperatur();
}
else if (USER_INPUT.equalsIgnoreCase("Zeigen Sie mir Informationen über den Kühlschrank an")){
kuehlschrankInformationen();
}
}
And here is the methods code:
public void kuehlschrankInformationen(){
dimensionen = "Die Breite beträgt 178cm, die Höhe 66,8cm & die Länge 59,5cm";
verbrauch = 157;
volumen = 707.5; // in liter
name = "Build Your Body Fat";
gewicht = 63;
try{
System.out.println(name);
System.out.println(gewicht);
System.out.println(volumen +" Liter");
System.out.println("Der Kühlschrank verbraucht " + verbrauch + "kWh");
System.out.println(dimensionen);
TimeUnit.SECONDS.sleep(5);
I would be pretty thankful, if you could help me out
If you want to stop executing the method you put the return statement in the end of this method, if you want to skip an iteration you put continue in your loop skipping one iteration. And if you put break your loop stops and not the method.
I believe you're looking for break
Read the docs while loop

Problems fetching URL in java with Jsoup

Edit: I have apparently solve the problem forcing the code getting the HTML. The problem I have is that randomly the HTML is not taken. To force that I have added:
int intento = 0;
while (document == null) {
intento++;
System.out.println("Intento número: " + intento);
document = getHtmlDocument(urlPage);
}
I am experiencing this random issue. Sometimes it gives me problems when fetching an URL an as it reaches to the timeout the program execution stops. The code:
public static int getStatusConnectionCode(String url) {
Response response = null;
try {
response = Jsoup.connect(url).userAgent("Mozilla/5.0").timeout(100000).ignoreHttpErrors(true).execute();
} catch (IOException ex) {
System.out.println("Excepción al obtener el Status Code: " + ex.getMessage());
}
return response.statusCode();
}
/**
* Con este método devuelvo un objeto de la clase Document con el contenido del
* HTML de la web que me permitirá parsearlo con los métodos de la librelia JSoup
* #param url
* #return Documento con el HTML
*/
public static Document getHtmlDocument(String url) {
Document doc = null;
try {
doc = Jsoup.connect(url).userAgent("Mozilla/5.0").timeout(100000).get();
} catch (IOException ex) {
System.out.println("Excepción al obtener el HTML de la página" + ex.getMessage());
}
return doc;
}
Should I use another method or increase the time out limit? The problem is that the program execution spends more or less 10 hours, and sometimes the problem happens in the URL number 500 another time in the 250...this is nonsense for me...if there is a problem in the link number 250, why if I run another time the program the problem happens in the link number 450 (for example)? I have been thinking that it could be internet problems but it's not.
The solution for another case is not solving my problem: Java JSoup error fetching URL
Thanks in advice.

Search database with multiple keywords separated by a comma

I have been trying for several days to write a search function where you can enter multiple keywords to output all lines that have these words stored in the respective column.
Searching for a single term is not a problem.
Here is my code:
private void StartSearchTagsTextKeyPressed(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode()==KeyEvent.VK_ENTER) {
try {
String sql = "SELECT ID, Titel, Autor, Regal, Fach, Gelesen, Tags FROM TableDB WHERE UPPER(Tags) LIKE UPPER(?) "; // hinter select kommt entweder ein * wenn alle spalteninhalte angezeigt werden sollen oder der jeweilige spaltenname welche angezeigt werden sollen
pst = conn.prepareStatement(sql);
pst.setString (1, "%" +StartSearchTagsText.getText()+ "%");
rs= pst.executeQuery ();
StartTable.setModel (DbUtils.resultSetToTableModel(rs));
pst.close();
StartSearchTagsText.setText("");
}
catch (SQLException e) {
JOptionPane.showMessageDialog (null, "searchtagskey");
}
}
}
I hope someone has a suggestion.
String searchterm1 = "Herrmann";
String searchterm2 = "Die kleine Hexe";
String sql = "Select * from TableDB where Autor like ? and Titel like ?";
pst = conn.prepareStatement(sql);
pst.setString (1, searchterm1);
pst.setString (2, searchterm2);
It should work like that.
This should be the simplest solution. If you can tell us what DBMS you are using we might be able to make it shorter depending on the system used.
First of all: LIKE only works with a single value for each evaluation it does. You can't separate it by commas like in the IN statement for example.
Therefore I'd suggest that you split the value of StartSearchTagsText.getText() into an array using the the .split("DELIMITER") function.
Then you can use a loop to add "OR LIKE %" + yourArray[i] + "%" to your sql String for every term you want to search for. (lose the OR for the first pass of the loop)
Du kannst mit LIKE nicht mehrere Bedingungen evaluieren, wie es z.B. mit IN geht.
Ich würde vorschlagen, dass du dir ein Array mit den gesplitteten Werten deines Textfeldes erzeugst. Das geht mit .split("TRENNUNGSZEICHEN"). Das Trennungszeichen musst du entsprechend anpassen. Wenn ein Komma die einzelnen Wörter nach denen du suchen willst separiert, dann schreibst du statt TRENNUNGSZEICHEN entsprechend ein , in die Klammer.
Sobald du das Array hast, kannst du es einfach komplett durchlaufen und bei jedem Durchlauf dein SQL-Statement mit "OR LIKE %" + deinArray[i] + "%"erweitern. Beim ersten Durchlauf das OR weglassen. Dann liefert dir das SELECT alle Datensätze zurück, was einem der Begriffe aus deinem Textfeld entspricht.

Recieving json with html tags fails in PHP

I have a website that sends and receives string in JSON format from my Java REST server with jersey. Everything works fine until I'm trying to receive a json object with html tags.
A println on my java server tells me that this data has ben sent:
data sent: {"text": "Wij zijn Pixel Apps, ook wel bekend als Groep 6.<br />
Samen met onze 6 groepsleden verzorgen wij het reilen en zijlen op Ford Lommel Proving Grounds.<br />
<br />
<b>Korte inleiding</b><br />
<p>Onze taak bestaat er uit een functionele applicatie te maken binnen Windows 8. De app bestaat er uit de chauffeurs te begeleiden op hun testritten.<br />De chauffeurs worden onder andere geholpen bij het bekijken van hun routineplan, het bijhouden van notities en het overzetten van de resultaten naar het hoofdgebouw.</p>
<b>Bijkomende hoort natuurlijk het onderhouden van deze website.</b>
<p>Zoals u kan zien vind u hierboven het navigatiemenu.<br />
Voor meer informatie over ons project kan u terecht bij <i>Over ons</i><br />
Wenst u contact op te nemen? U kan zich wenden naar het tabblad <i>Contact</i><br />
Indien u meer over de individuele groepsleden wil weten kan u terecht bij <i>Leden</i><br />
Als u meer informatie wenst over ons project, gelieve contact op te nemen met ons en wij verzorgen uw verzoek.</p>
<b>Happy browsing!</b>"}
It's basically a simple json with one variable "text" and as content some HTML formatted content. I've googled my issue and it seems that this should work fine.
Here's my java GET method that fails to send json with html tags in it's content:
#GET
#Path("gettext")
#Produces("application/json")
public String getJson(#QueryParam("id") String id, #QueryParam("taalcode") String taalcode) {
Connectie c = new Connectie();
try
{
c.openConnectie();
String content = c.getCms(id, taalcode);
if (content == null || content.equals("")) {
content = "{ \"text\" : \"Geen tekst gevonden.\" }";
}
System.out.println("data send: "+content);
return content;
}
catch(Exception e)
{
System.out.println("data send: { \"text\" : \"Server error, sorry.\" }");
return "{ \"text\" : \"Server error, sorry.\" }";
}
}
My put method successfully receives a json with html tags in it's content.
Here's how I receive my json objects in PHP (which again works if no html tags are present):
public function getCMS($id) {
$taalcode = '';
if($this->session->userdata('language') == 'nederlands') {
$taalcode = 'NL';
} else {
$taalcode = 'EN';
}
$curl_instance = curl_init();
curl_setopt($curl_instance, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_instance, CURLOPT_URL, 'http://192.168.0.251:8084/Groep1/webresources/cmspost/gettext?id='.$id.'&taalcode='.$taalcode);
try {
$data = json_decode(curl_exec($curl_instance), true);
if ($data == null) {
$data['text'] = "Altough I set a string in my java get method if it's null, this message is always printed";
}
return $data;
} catch (HttpException $ex) {
$data['text'] = $ex;
return $data;
}
}
In PHP I test if ($data == null) which is always true, even though I set a string manually in my GET method if appears to be null before sending the string.
What am I doing wrong?
The problem is not with HTML. The problem is that JSON does not allow multi-line strings. If you remove the line breaks, your JSON works fine.
NB that you really should use a JSON library for building JSON, rather than doing it yourself, because it will deal with this kind of issue.

Categories