Error handling when ElementNotVisible in dropdown in Selenium code - apache-flex

I have this following code. Please let me know if there is a way to capture the error and display it when the selectedAVE item is not found in the dropdown.
FlexWebDriver
.call(webDriver,
"container_app",
"doFlexClick",
"TreeNodeItem_com.vmware.ebr2.category/_TreeNodeItem_HGroup1/nodeName",
"");
Thread.sleep(SLEEP_TIME);
DropDownList.clickToOpen(webDriver, "vdrCombo");
Thread.sleep(SLEEP_TIME);
FlexMouseEvents.leftClick(webDriver, "automationName=" + selectedAVE);

You can use Try Catch() to handle the run time exceptions.
Try{
DropDownList.clickToOpen(webDriver, "vdrCombo");
Thread.sleep(SLEEP_TIME);
FlexMouseEvents.leftClick(webDriver, "automationName=" + selectedAVE);
}catch(Throwable e){
system.out.println(e.getMessage())
}

Related

How to try catch block in Jmeter.Webdriver webdriver Sampler

I want to do the exception handling in Jmeter.Webdriver Webdriver Sampler
Please let me , How to use try/catch block in Jmeter.Webdriver webdriver Sampler ?
You can do this via normal JavaScript try block, here is an example of taking a screenshot when error occurs:
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
var wait = new support_ui.WebDriverWait(WDS.browser, 5)
var exception = null
WDS.sampleResult.sampleStart()
try {
WDS.browser.get('http://example.com')
wait.until(conditions.presenceOfElementLocated(pkg.By.linkText('Not existing link')))
} catch (err) {
WDS.log.error(err.message)
var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
screenshot.renameTo(java.io.File('screenshot.png'))
exception = err
} finally {
throw (exception)
}
WDS.sampleResult.sampleEnd())
Don't forget to "throw" the error after you handle it otherwise it will be "swallowed" and you get a false positive result.
See The WebDriver Sampler: Your Top 10 Questions Answered article for more tips and tricks
Surround the code with try block and add catch block at the end by giving variable name to capture the exception. (in the example, it is exc)
try as follows:
try{
WDS.sampleResult.sampleStart()
WDS.browser.get('http://jmeter-plugins.org')
var pkg = JavaImporter(org.openqa.selenium)
WDS.browser.findElement(pkg.By.id('what')) // there is no such element with id what
WDS.sampleResult.sampleEnd()
}
catch(exc){ //exc variable name
WDS.log.error("element not found" + exc)
}
in the JMeter log, you can see the complete trace of NoSuchElementException, which is raised when trying to find the element by id with the values as what, which is not present in the HTML.
Note: use View Results in Table to see the Sampler response time.
Reference:
https://jmeter-plugins.org/wiki/WebDriverSampler/
Reference Image:
It is same as how do you do in other IDEs like eclipse.
you can see below code
//try block starts here
try{
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("element"))).click();
}
catch(Exception e)
{
WDS.log.info("Exception is : " +e);//you can print the exception in jmeter log.
}
double quotes should be replaced with the single quote if you are using javascript Since the BeanShell is easy and it is similar to java use BeanShell as much as possible

Flyway: Using both custom and Java Callbacks

If I specify
flyway.callbacks=com.myclass.CustomCallBack
it gets called fine, but I notice it seems to suppress the SQL callback functionality. Is there any way to have both? I notice there's a SqlScriptFlywayCallback, but that's one of your 'internal' classes....
Currently the only way is to refer both to the internal class and your own. Please file an enhancement request in the issue tracker.
As a simple workaround, you can initialize the SqlScriptFlywayCallback as Axel suggested. Here's how I did it, given an initialized instance of flyway:
DbSupport dbSupport;
try {
dbSupport = DbSupportFactory.createDbSupport(flyway.getDataSource().getConnection(), false);
} catch (SQLException e) {
throw new RuntimeException("Could not get connection to database");
}
final FlywayCallback runSqlCallbacks = new SqlScriptFlywayCallback(
dbSupport,
flyway.getClassLoader(),
new Locations(flyway.getLocations()),
new PlaceholderReplacer(flyway.getPlaceholders(),
flyway.getPlaceholderPrefix(),
flyway.getPlaceholderSuffix()),
flyway.getEncoding(),
flyway.getSqlMigrationSuffix()
);
flyway.setCallbacks(
runSqlCallbacks,
new MyCallback(...));

Elmah error logging, can I just log a message?

I just installed Elmah (https://code.google.com/p/elmah/) for my ASP.NET application.
Is it possible to log a message without creating an Exception first?
catch(Exception e)
{
Exception ex = new Exception("ID = 1", e);
ErrorSignal.FromCurrentContext().Raise(ex);
}
So is it possible to do:
ErrorSignal.FromCurrentContext().log("Hello I am testing Elmah");
Yes, you can use ErrorSignal without throwing an exception.
ErrorSignal.FromCurrentContext().Raise(new NotSupportedException());
For the custom message, you can create a custom exception.
var customEx = new Exception("Hello I am testing Elmah", new NotSupportedException());
ErrorSignal.FromCurrentContext().Raise(customEx);
Try this
Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Your message"));
I know this is an old question, but if you don't want to create an exception you can also use
var error = new Error
{
Source = eventType.ToString(),
Type = $"Trace-{eventType}",
Message = message,
Time = DateTime.UtcNow
};
ErrorLog.GetDefault(HttpContext.Current).Log(error);
as shown in this answer.

HttpRequestValidationException - How to get full value entered?

We receive multiple HttpRequestValidationExceptions on our website. We catch these appropriately, but would like to start logging them in more detail. The message that is caught shows
"A potentially dangerous Request.Form value was detected from the client (ctl00$txtSearch=\"<a href=\"www.google.com...\")."}
We would like to know the full text of what was entered in the text box and will do nothing except log it. I know that I entered
www.google.com
but as you can see, it did not show all of that in the Message part of the exception. InnerException is null, so that is of no help.
This is the code we use:
void Application_Error(object sender, EventArgs e)
{
// Get the last exception that has occurred
if (Server.GetLastError() != null)
{
var ex = Server.GetLastError().GetBaseException();
//...log it here
}
}
How can we get the full text entered into the text box? Turning off the page validation is not an option. Thank you in advance!
Use Request.Form["key name"] after catching last exception.
var val = Request.Form["txtInput1"];
You can also use
foreach (string key in Request.Form.AllKeys)
{
//Log everything.
var x = Request.Form[key];
}
Above I had tbSource as a text box and capturing the Value on Application_Error

Stop execution of a page

I have a task board, some person is working on some task, if task is assigned to another person by his manager the first person who is working on the task board, his execution should be stopped, and a message should be displayed that "This task is assigned to some one else."
I tried using following in page load.
//Code Behind
if (!Owner)
{
SomecontrolsToHide();
MessageDisplay(); // JavaScript function call using RegisterStartupScript()
Response.End();
}
protected void MessageDisplay()
{
string dbMessage = "Task is assigned to someone else.";
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(typeof(Page), "ShowMessageWrapup_" + UniqueID, "showMessageDisplay('','" + dbMessage + "');", true);
}
// JavaScript function that displays message.
function showMessageDisplay(args, displayMessage) {
if (displayMessage != "") {
document.getElementById("spanMessage").innerHTML = displayMessage;
document.getElementById("spanMessage").style.display = 'inline';
}
}
It stops the execution but message is not displayed and Controls are not hidden too.
What should I do?
Don't do Response.End(). Just return without doing anything.
This will show the message box. Try this.
Response.Write(#"<script language='javascript'>alert('You are not allowed for this task !!!')</script>");

Resources