I meet a strange behavior. I dont understand my mistake.
I want to read a value from an HTML page. I can obtain it with :
JavaScript
function getSize() {
return (size.toString());
}
getSize();
Output (in Chrome console)
120
C#
// wBrowser is not null and the page is loaded
String o = wBrowser.InvokeScript("eval", "getSize();").ToString();
Debug.WriteLine(o);
Here o is empty.
I read the msdn doc and try some research without success. What am I missing?
Thank you.
Well ...
Just found my error.
My solution is working. Lukasz's solutions works too.
I just forgot to swith the run mode from Release to Debug ...
So working solutions are :
String o1 = wBrowser.InvokeScript("eval", "getSize();").ToString();
// Lukasz's 1st solution
String o2 = wBrowser.InvokeScript("getSize").ToString();
// Lukasz's 2nd solution
String o3 = wBrowser.InvokeScript("eval", "size.toString();").ToString();
Both print the right size.
Maybe it could be helpful for someone else ...
Related
I'm trying to take a full screen screenshot of my page by using this code:
public void OpenEyesForVisualTesting(string testName) {
this.seleniumDriver.Driver = this.eyes.Open(this.seleniumDriver.Driver, "Zinc", testName);
}
public void CheckScreenForVisualTesting() {
this.eyes.Check("Zinc", Applitools.Selenium.Target.Window().Fully());
}
public void CloseEyes() {
this.eyes.close();
}
but instead I just get a half a page of the screenshot, I tried to contact Applitools but they just told me to replace eyes.checkwindow() to eyes.Check("tag", Target.Window().Fully()); which still didn't work.
If anyone can help me that would be great.
I work for Applitools and sorry for your troubles. Maybe you did not see our replies or they went to your spam folder. You need to set ForceFullPageScreenshot = true and StitchMode = StitchModes.CSS in order to capture a full page screenshot.
The below code example is everything you'd need to do in order to capture a full page image. Also, please make sure your .Net Eyes.Sdk version is >= 2.6.0 and Eyes.Selenium >= 2.5.0.
If you have any further questions or still encountering issues with this please feel free to email me directly. Thanks.
var eyes = new Eyes();
eyes.ApiKey = "your-api-key";
eyes.ForceFullPageScreenshot = true;
eyes.StitchMode = StitchModes.CSS;
eyes.Open(driver, "Zinc", testName, new Size(800, 600)); //last parameter is your viewport size IF testing on a browser. Do not set if testing on a mobile devices.
eyes.CheckWindow("Zinc");
//or new Fluet API method
eyes.Check("Zinc", Applitools.Selenium.Target.Window().Fully();
eyes.Close();
Use extent Reporting library, in that you can take screen shot as well as an interactive report on pass and fail cases.
here is the link how it works:
http://www.softwaretestingmaterial.com/generate-extent-reports/
If you want to take complete page Screenshot/ Particular element with Applitools. You can use lines of code:-
Full Screenshot
eyes.setHideScrollbars(false);
eyes.setStitchMode(StitchMode.CSS);
eyes.setForceFullPageScreenshot(true);
eyes.checkWindow();
Take screenshot for particular element
WebElement Button = driver.findElement(By.xpath("//button[#id='login-btn']"));
eyes.setHideScrollbars(false);
eyes.setStitchMode(StitchMode.CSS);
eyes.open(driver, projectName, testName);
eyes.setMatchLevel(MatchLevel.EXACT);
eyes.checkElement(Button );
(I am from Applitools.)
When setting forcefullpagescreenshoot to true, applitools will try to scroll the HTML element in the page, if the HTML is not the scrollable element then you will need to set it yourself:
eyes.Check(Target.Window().ScrollRootElement(selector))
In Firefox, you can see a scroll tag near elements that are scrollable.
I'm having issues with a piece of code for a website in C# and when I debug it, it opens the site (localhost in Chrome. Every page works except the one I'm debugging, regardless of whether or not that's the page I'm debugging. Whenever I try to open it, it gives me an Object Reference error at the line I've marked below. This happens no matter which browser I use.
Protected void page_load (object sender, EventArgs e)
{
DateTime dteNow = SI.Getsource.DAL.Time.Now.Eastern();
If(!IsPostBack)
{
txtStartDate.SelectDate = dteNow.AddDays(-2)
txtEndDate.SelectedDate = dtenow.AddDays(1)
txtStartDate.Visible = False
txtEndDate.Visible = False
Shipping.DataTable.dt = SI.Getsource.DAL.EquipmentDB.getPrinter();
ddlPrinter.DataSource = dt.Result
ddlPrinter.DataTextField = dt.Result.Columns["Name"] //Error is here
ddlPrinter.DataValueField = dt.Result.Columns["PrinterID"]
ddlPrinter.DataBind();
Try
{
ddlPrinter.SelectedValue = System.Web.Configuration.WebConfigurationManager.AppSettings["DefaultPrinterID"]
}
Catch
}
}
I've tried running it in IE and Firefox. I also tried adding a try-catch for "Name" similar to the one for "Printer" but that didn't do anything. Any suggestions would be greatly appreciated, since this error prevents me from debugging the actual issue.
Edit: I'm using Visual Studio 2015. Also, this only happens when I run the page locally, ie. When debugging.
Set a breakpoint on the line giving you the error, then add dt.Result to the Watch window to examine its value when the execution breaks on this line. It could be that dt.Result is null.
edit: Also, I think you only need to specify the field name for .DataTextField and .DataValueField.
As it turns out, it was an issue with memory. Once I took care of that, it worked.
I have pretty annoying problem. :)
visual = context.ActiveVisualReference;
TablePlot tablePlot = visual.As<TablePlot>();
colorings = tablePlot.Colorings;
categories = colorings.GetCategories();
coloring1 = colorings.GetColoringForCategory(categories[0]);
coloring2 = colorings.GetColoringForCategory(categories[1]);
coloring3 = colorings.GetColoringForCategory(categories[2]);
category2 = categories[2];
bool removed = colorings.Remove(coloring2);
This is the C# code I execute at the custom Tool level and the problem is that I do not see any effect within the Web Professional (using 5.5)
of the Remove method execution.
According to the documentation the method should remove the custom coloring from visualisation and it does NOT.
Perhaps it is needed to call some method that refreshes view but I didnt manage to locate it.
Please help. :)
http://stn.spotfire.com/dxp/html/M_Spotfire_Dxp_Application_Visuals_ConditionalColoring_ColoringCollection_Remove.htm
Have you tried tablePlot.Colorings = colorings at the end of your code ? What is the value of "removed" at the end of your code ?
In ironPython this one works:
from Spotfire.Dxp.Application.Visuals import TablePlot
print myVisual.Title
myTablePlot = myVisual.As[TablePlot]();
print myTablePlot.Title
myColorings = myTablePlot.Colorings;
myCategories = myColorings.GetCategories();
print myCategories.Count
myColorings.Remove(myColorings.GetColoringForCategory(myCategories[1]))
I have implemented the latest code mirror in our asp.net application. the editor allows to type javascript which has commented code and un commented code.
I want to know whether all the code written in the editor is commented or not.
Can anyone please advice.
You can fetch the document text, than pass it through a regex, filtering out all the comments:
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
lineNumbers: true
});
var out = document.getElementById('out');
out.textContent = editor.getValue()
.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:[\s;]+\/\/(?:.*)$)/gm, '');
Demo
I have the following line of code to open a web page modal dialog in C# (Silverlight):
var so = (ScriptObject)HtmlPage.Window.Invoke(
"showModalDialog",
modalWindowUrl,
dialogArgs,
"dialogWidth:600px;dialogHeight:600px;");
Now, code similar to the following is being called on the page I am displaying, and I need to make sure it gets the values I'm trying to pass in (this is a MSCRM web page I don't have control over):
dialogArgs.items <-- will be an array I pass in
dialogArgs.items[i].getAttribute("oid") <-- will return something
dialogArgs.items[i].getAttribute("otype") <-- will return something
dialogArgs.items[i].values <-- will return something
What I have tried to send in (from my C# code) is this:
dialogArgs = #"{items:[{oid:" + id + ",otype:" + type + "}]}";
which will result in a JSON string... but I'm guessing this just ends up as a string within the JavaScript and not a JSON object.
Any ideas how I get this to work?
A few side notes:
I can't get IE to debug the modal dialog that results from this call. I can get the debugging tools displaying, but it won't attach to the page because it cannot refresh it.
I don't have control over this modal dialog. It's a page that is displayed using MS Dynamics CRM. For that reason I cannot mess with the JavaScript or anything to test stuff.
Looks like I won the tumbleweed award for this one! Can't believe how uncommon this scenario seems to be. The solution ended up being quite simple, but not very documented so took me a while to track down. Thought I would share here.
Firstly, a quick search across the internet reveals that we can set this up using the following:
var dialogArgs = HtmlPage.Window.CreateInstance("Object");
Which gives you a ScriptObject back. For properties:
dialogArgs.SetProperty("items", items);
Some code for setting up an array and an item should look something like this (I have just created a new GUID for the purpose of this example):
var item = HtmlPage.Window.CreateInstance("Object");
item.SetProperty("oid", Guid.NewGuid());
item.SetProperty("otype", "account");
var items = HtmlPage.Window.CreateInstance("Object");
items.SetProperty(0, item);
And finally, just pass that object straight into your dialog window like this:
var so = (ScriptObject)HtmlPage.Window.Invoke("showModalDialog", lookUpWindow, dialogArgs, "dialogWidth:600px;dialogHeight:600px;");