How to pick an element from .XML file in MS edge browser - selenium

I am trying to get a value(Identifier in my case) from XML to pull some logic rules for a web app. I have managed to get my JavaScript to work on Firefox & Chrome but for Edge, instead of picking an element(Identifier) it's picking an element description from Developers tool.
Test case is:
1. Get an identifier from .XML
2. Go to an application and search using that identifier
For example: .XML
<Application Type="ABCD">
<Identifier>18753</Identifier>
<SalesChannel SalesChannelType="PQRS" SalesChannelSegment="XYZ">
<Identifier>AB1234</Identifier>
My code for this:
driver.get("URL for .XML");
Assert.assertTrue(driver.getPageSource().contains("Identifier"));
String xml = driver.getPageSource();
String appID = xml.split("<Identifier>")[1].split("</Identifier>")[0];
**Code to navigate to web app **
driver.findElement(By.id("oData")).sendKeys(appID);
--It uses appID and proceed with an application.
But instead of picking an identifier which is "18753" in this case, it's picking below value and putting in Search :
{{a xmlns="http://www.w3.org/1999/xhtml" tabindex="-1" role="treeitem" aria-expanded="true" aria-posinset="1" aria-setsize="20" aria-level="2" style="color: blue; margin-left: -2em;"><Identifier>18754</Identifier>
After investigation i found this value is coming from developer tool:

Try replacing
String appID = xml.split("<Identifier>")[1].split("</Identifier>")[0];
With
String appID = xml.split("<Identifier>")[0];

Related

Open URL in new tab instead of new window in FPM application

I'm building an application in FPM and I'm trying to open an external URL in a new tab. I'm using the following code:
data: lr_fpm type ref to if_fpm,
lr_nav type ref to if_fpm_navigate_to,
ls_url type fpm_s_launch_url,
ls_nav_additional_parameters type apb_lpd_s_portal_parameters.
if lr_fpm is not bound.
lr_fpm = cl_fpm_factory=>get_instance( ).
endif.
lr_nav = lr_fpm->get_navigate_to( ).
ls_url-url = '<A URL leading to a different application within my organisation>'.
ls_nav_additional_parameters-navigation_mode = 'EXTERNAL'.
call method lr_nav->launch_url
exporting
is_additional_parameters = ls_nav_additional_parameters
is_url_fields = ls_url_oi.
Unfortunately, in all browsers this opens a new window instead of a new tab. Is there some parameter that changes this behavior to opening the external URL in a new tab?
Thank you in advance,
Joshua
you can add the attribute target="_blank" to the end of your url.
Maybe if you add this to the "IS_ADDITIONAL_PARAMETERS" it will work as well.
Unfortunately, I currently do not have access to my SAP system to test this.
But it is worth a try

Protractor get console variable value

In Firefox browser developer tool console, I type var a = libraryform.firstname
It returns the firstname value entered by user for that form.
I am new to protractor and selenium. How can I call library.firstname in protractor to get the value of fistname?
Use Javascript Executor to execute the javascript which you able to get them working in developer console against your application.
For e.g.,
this returns web-element which retrieved through javascript executed in browser.
var element = browser.executeScript("document.getElementById('identifier1')");
Refer this page for more examples
If this single line returns required value in browser console, then the protractor code should be some thing like this,
var name = browser.executeScript('return libraryform.firstname')
If you need too many lines of js, you can specify with semicolon separated,
var name = browser.executeScript("var element=$('.dropdown-toggle').eq(0); return element.text();")

Mary TTS with HTML/JavaScript and PHP

I installed Mary TTS (version 5.1.2) on my Windows (and Linux computers).
I started the Mary TTS server and the Mary TTS client, and I did some trials with text to audio conversion in the GUI window (its great).
I would like to use Mary TTS on my website to read text aloud, where a user can add a text into the input field and generate the output like in the GUI window, without using the java client.
For example:
<input type="text" id="text">
<button onclick="play('text');">Speak it</button>
<script>
function play(id){
var text = document.getElementById(id).value;
var a = new Audio(text);
a.play();
}
</script>
Just to get started.. I can't realize how to do that in HTML/JavaScript and PHP?
Step 1. Host MaryTTS on a server
I wrote marytts-http to wraps MaryTTS so it's easy to deploy to Heroku, though you could deploy it to other servers as well.
First you'll need an account with Heroku, then install their toolbelt and run heroku login.
After that you can deploy marytts-http to Heroku like this:
git clone https://github.com/draffensperger/marytts-http
cd marytts-http
heroku create
git push heroku master
Step 2. Use your hosted MaryTTS instance in your website
Heroku will give a name to your marytts-http instance that you created above which you can change later on the Heroku dashboard. Let's say the name of your instance is my-marytts, then the URL to get a text-to-speech audio file would be my-marytts.herokuapp.com/?text=Hello (just specify the text query parameter).
To embed the audio on your website you should use an <audio> tag, e.g.:
<audio src="my-marytts.herokuapp.com/?text=Hello" autoplay></audio>
The autoplay makes it start the audio when the element is loaded. So in your case, what you could do is dynamically add an <audio> element after the user clicks the button, e.g.:
<input type="text" id="text">
<button onclick="play('text');">Speak it</button>
<span id="audio-container" style="display:none;"></span>
<script>
function play(id) {
var maryttsHost = 'https://example-mary-tts.herokuapp.com'
var text = document.getElementById(id).value;
var container = document.getElementById("audio-container");
var audioSrc = maryttsHost + '/?text=' + encodeURIComponent(text);
container.innerHTML = '<audio src="' + audioSrc + '" autoplay></audio>';
}
</script>
You would need to change maryttsHost above to match the actual URL of your marytts-http instance on Heroku.

Balanced Payments doesn't seem to work with Phonegap

We are not able to call balanced.card.create from a Phonegap application. This is reproduced in a stock Phonegap application here: https://github.com/kevg/phonegap-balanced. Full details are in the README.md on github, but the basic summary is:
For those not familiar with phonegap, the main page that loads is
index.html. This initializes phonegap in index.js. When the device is
ready, we will show a hidden DIV with a button named "Execute
Balanced." When you click this button, app.executeBalanced in index.js
will be called which prompts for the balanced marketplace URI, loads
balanced.js with $.getScript, and then calls balanced.card.create with
a test credit card.
The expected result is that callbackHandler is called or an exception
is caught. Instead, it seems the execution of the Javascript thread
disappears into balanced.card.create, never to return and without any
error.
Alrighty, I found the bug in balanced.js. So, in Phonegap, window.location.href returns something like file:///.../index.html. Balanced.js creates an iframe to something like https://js.balancedpayments.com/proxy#file
var src = proxy + "#" + encodeURIComponent(window.location.href);
https://github.com/balanced/balanced-js/blob/master/src/utils.js#L48
In the script returned in proxy.html (which I can't find on github), it does:
c.parentURL=decodeURIComponent(
window.location.hash.replace(/^#/,"")
).replace(/#.*$/,"")
c.parentDomain=c.parentURL.replace(/([^:]+:\/\/[^\/]+).*/,"$1")
The regex doesn't match because file: has three slashes. Now, at first, I thought I could just convert the regex to:
/([^:]+:\/+[^\/]+).*/
However, then there's another problem, because balanced does a security origin check on the match:
if (d.origin.toLowerCase() !== c.toLowerCase()) return !1;
However, the regex returns file:///firstcomponent, whereas event.origin does not include a host name for the file scheme, so these won't match even with a fixed regex.
I can't change anything in the script returned in the proxy response because if I load that from a domain other than balancedpayments.com, then the AJAX POST fails (return code 0 with a blank body). Therefore, the only thing I can control is the hash passed to the iframe.
However, since this regex is a replace, we can simply pass exactly what we know we need (we don't care that the regex is a no-op).
Therefore, the solution is to change L48 above to:
var src = proxy + "#" + encodeURIComponent("file://");
This works.

How to set a global Base URL for every test case of one test suite in Selenium IDE?

How to set a global Base URL for every test case of one test suite in Selenium IDE so that I can switch to different environment easily?
If you have a lot of test cases in a single suite, it's a pain to change the Base URL for each. Instead, create a separate case for each Base URL you need to switch between. For example, I have store https://testing.site.com/ as myEnvironment saved as test case SetEnvTesting. I create another case for my production site, SetEnvProduction.
Then, insert the ${myEnvironment} at the beginning of each relative URL in your test cases. For example, open ${myEnvironment}/login.aspx. (This might be a pain if you've got a lot of tests already. I suggest just adding it from now on.) Then, simply put the set-environment test case at the beginning of your test suite. To switch your entire suite to another Base URL, simply put a different set-environment case at the start. Another nice thing is that you can switch environments in the middle of the suite by putting a different set-environment case in the middle.
Edit: Example of using a SetEnvironment test case.
The SetEnvironment case:
An example of a following test case.
Notice
how the CurrentEnvironment variable is used. You can do this for every case in the suite. Additionally, you can make every separate test suite use this same SetEnvironment case, so they all switch together.
that the Base Url becomes irrelevant. You're overriding it, essentially.
I hope that's helpful!
The test case HTML file is responsible for setting the base URL. From the Selenium IDE, you can override the base URL for a test case. A test suite, on the other hand, is only a bag for your test cases.
Remove the base URL setting from each of the test case files referenced from your test suite. Then set the base URL by hand for the test suite and run the suite.
The line in question is in the head of each test case file:
<link href="http://server-name/" rel="selenium.base"/>
If it is missing, then the base URL overrides it automatically.
I found it exceedingly frustrating that I couldn't just have a blank Base URL and have it use whatever page I already had open as the start of the test. What is the point of being able to record relative URLs when it forces you to hardcode a base url that is prefixed to every relative url (thus turning them into absoulte urls)??
Extending on the other answers and from this question: In Selenium IDE, how to get the value of the base url
You can store the current domain in a variable and then use that instead of a hard coded one. This lets you login to the server you want to run the tests on, hit play and it will run the tests without all this baseURL nonsense redirecting you to the wrong server.
Just use these commands at the start of the first script in your suite:
And keep using the http://${host}/ syntax for every truly relative URL you need in your script.
I just created a separate test and put it at the top of all tests. Store the base url to an variable and now I am able to access it in other test cases by ${variable_name}.
I tried the accepted answer, it does work for selenium IDE, but it does not work when running stand-alone server.
finally, I put the value inside the user-extensions.js , and use storeEval to get the value back. Then the same value could be retrieved inside different cases.
EDIT:
In the user-extensions.js, add the following
var selenium_base_url = "http://example.com"
In the HTLM suite, add the following
<tr>
<td>storeEval</td>
<td>selenium_base_url</td>
<td>case_base_url</td>
</tr>
<tr>
<td>open</td>
<td>${case_base_url}/case_path?a=1&b=2</td>
<td></td>
</tr>
This may look odd at the first sight, but actually user-extension.js could be modified on the fly right before the stand-alone server execution, so you may put a different base url using a script in the real QA scenario.
Hmm, I think there is a simpler solution:
In the first test (of the test suite) adjust
<link rel="selenium.base" href="http://google.com" /> as needed
In the following tests remove (using text editor or similar):
<link rel="selenium.base" ... />
If you're fine double clicking multiple times,
Double click the top one, set it to the URL you want.
Now double click the top, middle, bottom.
Now double click the bottom, middle, top.
I created a user-extension command 'doBaseURL' that manipulates the Selenium IDE field 'Base URL'.
In every test case of a test suite I added this command | baseURL | | |. Below the surface it sets a stored variable named baseURL.
It is possible to give the stored variable 'baseURL' a value from a test case command prior to the first 'baseURL' command.
This method overwrites the <link href="http://server-name/" rel="selenium.base"/> setting of each test case file.
For me this works fine as now the Selenium IDE reflects the Base URL that the test case(s) will use (or was using when an error occured).
The java script is:
Selenium.prototype.doBaseURL = function(strTarget, strValue) {
/**
* Enables a more predictive Base URL when running a test suite with multiple test cases.
* On first usage it wil fill a stored variable 'baseURL' either with the given strTarget,
* or when not given with the Base URL as shown on the Selenium IDE UI. The Selenium IDE UI field
* Base URL is updated to reflect the (new) base URL.
* In each subsequent test case with a baseURL command the stored variable 'baseURL' will determine
* the base.
*
* <p> Best to use as first command in each test case and only in the first test case a strTarget
* argument, in that way the test cases of a test suite will no longer depend on their 'hidden'
* '<link rel="selenium.base" href="http://www.something.com/" />
* construction, that makes test cases effectively having an absolute base URL.
* </p>
*
* #param strTarget a Base URL value to be used in the test case (e.g. https://www.google.com/)
*/
// pushes the given strTarget into the selenium.browserbot.baseUrl
// and makes the new Base URL value visible on the Selenium IDE UI.
// A subsequent open command will use this new Base URL value
LOG.debug("begin: doBaseURL | " + strTarget + " | " + strValue + " |");
// note: window.location.href = strTarget; causes the browser to replace Selenium-IDE UI with the given url
// used that knowledge to manipulate the Selenium IDE UI as if a manual Base URL change was done.
LOG.debug("window.location.href= [" + window.location.href + "]");
LOG.debug("window.editor.app.getBaseURL() gives [" + window.editor.app.getBaseURL() + "]");
if (strTarget && (strTarget.substring(0,1)!="$")) { // only when strTaget has a value
strValue = "Base URL changed from [" + selenium.browserbot.baseUrl.toString() + "] into [" + strTarget + "]";
selenium.browserbot.baseUrl = strTarget.toString();
// set the visible Base URL value on the Selenium IDE UI to the new value
window.editor.app.setBaseURL(strTarget);
LOG.debug("updated into: " + window.editor.app.getBaseURL());
// remember this value for future calls
storedVars["baseURL"] = window.editor.app.getBaseURL();
LOG.debug("storedVars[\"baseURL\"] set to [" + window.editor.app.getBaseURL() + "]");
} else {
// no value => take storeVars["baseURL"] when set;
// otherwise take Selenium IDE Base URL field.
if ((storedVars["baseURL"] != undefined) && (storedVars["baseURL"] != "")) {
strValue = "Base URL changed from [" + selenium.browserbot.baseUrl.toString() + "] into [" + storedVars["baseURL"] + "]";
selenium.browserbot.baseUrl = storedVars["baseURL"];
// set the visible Base URL value on the Selenium IDE UI to the new value
window.editor.app.setBaseURL(storedVars["baseURL"]);
LOG.debug("updated from storedVars[\"baseURL\"]");
} else {
strValue = "Base URL changed from [" + selenium.browserbot.baseUrl.toString() + "] into [" + window.editor.app.getBaseURL() + "]";
selenium.browserbot.baseUrl = window.editor.app.getBaseURL();
// remember this value for future calls
storedVars["baseURL"] = window.editor.app.getBaseURL();
LOG.debug("storedVars[\"baseURL\"] set to [" + window.editor.app.getBaseURL() + "]");
}
}
LOG.info(strValue);
LOG.debug("end: doBaseURL | " + strTarget + " | " + strValue + " |");
}
Installing a user-extension script is explained in the "Using User-Extensions With Selenium-IDE" section SeleniumHQ documentation: http://www.seleniumhq.org/docs/08_user_extensions.jsp