Match html response in karate [duplicate] - karate

This question already has an answer here:
Karate: Match repeating element in xml
(1 answer)
Closed 2 years ago.
I hava a problem in matching my response errors with html.
I tried like this
match $.errors == '#present'
match $.errors == response
Errors:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Error: Unexpected object!</pre>
</body>
</html>
I'm doing it like this and the scnario will be stoped!
When method post
* if (responseStatus == 500 ) karate.abort()
Then status 200
* match $.errors == '#notpresent'
How can I do to get the response match as html text?

Sorry Karate only works with well-formed XML. You can try to replace content in the HTML to clean it up. Or you can just do string contains matches etc. Or you can write some JS or Java code for custom checks.
This will work (after removing the <meta> tag which is not well-formed.
* def response =
"""
<!DOCTYPE html>
<html lang="en">
<head>
<title>Error</title>
</head>
<body>
<pre>Error: Unexpected object!</pre>
</body>
</html>
"""
* match //pre == 'Error: Unexpected object!'

Related

problems with configuration of mathjax 3 demo interactive TeX input and HTML output

demo path:
https://github.com/mathjax/MathJax-demos-web/blob/master/input-tex2chtml.html
I add mathjax config:
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script>
MathJax = {
tex: {
inlineMath: [['$', '$']]
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax#3/es5/tex-chtml-full.js"></script>
run like this:
The $ sign should not be there, but it still shows,even though the Tex grammar is right.
How do I make the $ go away? Where am I wrong? and what's the solution?
Your configuration is correct. There is a slight issue with the way you are trying to use the input field and tex2chtmlPromise via convert.
You can see that your code is working if you put your lines in the body rather than in the textarea:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width">
<title>MathJax v3 with interactive TeX input and HTML output</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script>
MathJax = {
tex: {
inlineMath: [["$", "$"]]
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax#3/es5/tex-chtml.js"></script>
</head>
<body>
Testing math:
<p>$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$</p>
</body>
</html>
For more information about your usage issue, see this GitHub Issue Delimiter not working with MathJax.tex2chtmlPromise method
"the MathJax.tex2chtmlPromise() function takes a LaTeX string as its parameter, which does not require a delimiter. [...] So if you are passing delimiters to this, they will be typeset as part of the math. There is no need for delimiters because you are identifying the math, not MathJax, and are passing it directly to the function. There is no need for delimiters, because there is no need to separate the math from the surrounding text, as you have already done that yourself."
When you use the $ delimiter in your document, your specified delimiters will be handled appropriately. The delimiters are necessary in the document body as a way to distinguish it from the surrounding text.
However, in the textarea, it is expected that the only thing the user inputs is valid Math. Given this expectation, delimiters are unexpected. When the raw input is passed to the MathJax.tex2chtmlPromise any text included will be typeset as math. Hence, why your $ signs appear as literals in your output field.

How can i use a template in the email body for Microsoft graph API?

I am looking to use the source code of an email which has the desired template that i need in the Microsoft Graph API.
The standard format for this looks like so:
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "HTML",
"content": "The new cafeteria is open."
},
The sourcecodes template that i am looking to use already has contentType etc within the code.I have tried removing contentType and content and just having the source code within the body but this still does not work. Below is start of the source code that i am looking to use:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--[if !mso]>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="http://www.opusenergy.com/wp-content/uploads/2016/03/Favicon-150x150.png" />
<title>Opus</title>
<!--[if (gte mso 9)|(IE)]>
<style type="text/css">
table {border-collapse: collapse !important;}
</style>
Any help will be greatly appreciated, Thank you.
The above payload is not what Graph API looks for. You need to specify the payload for the create message API call and the structure is given in the Graph API document. Still if you want to customize, you can do it, by making sure to modify/customize in-lines with Microsoft Graph API recommendation. Say i will put the HTML content inside the content of the Graph API call, specify the contenttype as HTML. This is the way i would start testing it make sure whether it's working or still i need to modify so that the message can show correctly in Outlook or not.
You tried the above recommendation and confirmed that it works.
If i want to send out email/template then i would first make sure it works in Word/Outlook; so that you can validate the HTML/CSS tags are working in, as i know that not all tags are not supported. Please keep this best practice and plan it accordingly. It will help you to build the template as you wish and you're guaranteed that the Outlook will show-up them as well.

Strange behaviour in nightwatch text assertion

I am pretty new to nightwatchjs and encountering a strange behaviour when I tried to assert simple text in a single dom
Same assertion method and one works but another doesn't
// This works
client.expect.element('#MenuToggle').text.to.contain('Menu');
// This doesn't work and it always returns empty "" string
client.expect.element('#BackToMain').text.to.contain('Back to main');
The code given in your question is correct and should work... To help you with debugging, please try to run the following minimal working example:
HTML (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Nightwatch</title>
</head>
<body>
Menu
Back to main
</body>
</html>
JavaScript (test.js)
module.exports = {
'Test': function (browser) {
browser.url('http://localhost:8000/index.html'); // Change this if needed
browser.expect.element('#MenuToggle').text.to.contain('Menu');
browser.expect.element('#BackToMain').text.to.contain('Back to main');
browser.end();
}
};
Command
nightwatch -t tests/test.js
If it does not work:
Check if your environment is OK (it works with Node v7.7.4 + Nightwatch v0.9.14).
Edit your question to add more code.

PHP $_GET encoded param return invalid chars

I got a really strange issue that I can't solve, can anyone please suggest a solution? thank you in advance :)
I want to pass a complete url to a script, the script will check the url and do a meta refresh to redirect to it, so assume my script is goto.php and I want it redirect to:
http://www.google.com/?name=david&param=gender
So I enter this in my browser:
www.mydomain.com/goto.php?u=http%3A%2F%2Fwww.google.com%2F%3Fname%3Ddavid%26param%3Dgender
But my goto.php script get:
http://www.google.com/?name=david¶m=gender
As you can see, the "&" is missed, here is the code of my goto.php:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>checking</title>
<meta name="robots" content="noindex,nofollow" />
</head>
<body>
<?php echo $_GET ['u'];?>
</body>
</html>
although if I add
<meta http-equiv="refresh" content="0;url=<?php echo $_GET ['u'];?>" />
it works in some browser, but in some other browser, it won't work, because the $_GET['u'] didn't return a valid url.
Thank you once more for any suggestion.
Looks like you have an issue with charset encoding/decoding. Whats the output of your "php -i"?
edit
I just gave it another try and your script is fine. The issue is that your URL is not escaped for HTML. If you look at the source of your page, then you will realize that everything looks fine.
You must escape all ampersands (&) before you output to HTML. Use htmlspecialchars() or htmlentities() for that.
http://php.net/manual/en/function.htmlspecialchars.php
<?php echo htmlspecialchars($_GET['u']); ?>
Please change the line
<?php echo $_GET['u']; ?>
to the following line
<?php echo urldecode($_GET['u']); ?>

Cannot display unicode chars on Apache but works fine in shell using Python 3 [duplicate]

For HTML5 and Python CGI:
If I write UTF-8 Meta Tag, my code doesn't work.
If I don't write, it works.
Page encoding is UTF-8.
print("Content-type:text/html")
print()
print("""
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
şöğıçü
</body>
</html>
""")
This codes doesn't work.
print("Content-type:text/html")
print()
print("""
<!doctype html>
<html>
<head></head>
<body>
şöğıçü
</body>
</html>
""")
But this codes works.
For CGI, using print() requires that the correct codec has been set up for output. print() writes to sys.stdout and sys.stdout has been opened with a specific encoding and how that is determined is platform dependent and can differ based on how the script is run. Running your script as a CGI script means you pretty much do not know what encoding will be used.
In your case, the web server has set the locale for text output to a fixed encoding other than UTF-8. Python uses that locale setting to produce output in in that encoding, and without the <meta> header your browser correctly guesses that encoding (or the server has communicated it in the Content-Type header), but with the <meta> header you are telling it to use a different encoding, one that is incorrect for the data produced.
You can write directly to sys.stdout.buffer, after explicitly encoding to UTF-8. Make a helper function to make this easier:
import sys
def enc_print(string='', encoding='utf8'):
sys.stdout.buffer.write(string.encode(encoding) + b'\n')
enc_print("Content-type:text/html")
enc_print()
enc_print("""
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
şöğıçü
</body>
</html>
""")
Another approach is to replace sys.stdout with a new io.TextIOWrapper() object that uses the codec you need:
import sys
import io
def set_output_encoding(codec, errors='strict'):
sys.stdout = io.TextIOWrapper(
sys.stdout.detach(), errors=errors,
line_buffering=sys.stdout.line_buffering)
set_output_encoding('utf8')
print("Content-type:text/html")
print()
print("""
<!doctype html>
<html>
<head></head>
<body>
şöğıçü
</body>
</html>
""")
From https://ru.stackoverflow.com/a/352838/11350
First dont forget to set encoding in file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
Then try
import sys
import codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
Or if you use apache2, add to your conf.
AddDefaultCharset UTF-8
SetEnv PYTHONIOENCODING utf8