i have a controller and an action. this action is to save data into database. and now, i want when i submit a button, my controller do an action and open new window.
public ActionResult New(FormCollection collection)
{
data.Population_Code = collection["Countrys[0].CountryCode"];
data.Population_Desc = collection["Countrys[0].CountryDesc"];
data.Population_Grouping = collection["Countrys[0].CountryGroup"];
data.Population_Type = "CNTRY";
data.Population_Redudant = "N";
data.Population_Modified_At = officeCode.User_Office.ToString();
db.SaveChanges();
//example for new window
//window.open('/Report/New.aspx')
return RedirectToAction("index");
}
so my controller do an action and open a new window.
anyone can help me ?
thanks
Technically, this can be done by returning javascript that will open the new window.
However, most browsers will kill a new window called in this manner (i.e. popup blocker).
You would be better off, if possible, by opening the link to your action in a new window from the start;
#Html.ActionLink("New report", "New", "Report", null, new {target = "_blank"})
Edit
I can see from your action, that it is probably a form that creates the report; you can also use the attribute target='_blank' on a form as well.
Related
So this is how I launch my login page:
this.OnGoogleDrive = new Command(() =>
{
var presenter = new OAuthLoginPresenter();
presenter.Login(auth);
});
And this is how I define my Authenticator:
var auth = new OAuth2Authenticator(
this.clientId,
string.Empty,
scope,
new Uri("https://accounts.google.com/o/oauth2/v2/auth"),
new Uri(redirectUrl),
new Uri("https://www.googleapis.com/oauth2/v4/token"),
isUsingNativeUI: true);
So my app opens a page where the Google login page appears and authorizes my scope. At the very end, it shows me a code that I had to copy paste. So far I thought that the page would instead make IsAutheticated true. But when I got to the method handling the Completed event, it is read as false.
Why is that? Was I using the wrong way to open the Login page?
I try the new Shell of Xamarin Form 4 for a small project.
I have a list of order, then someone chooses an order and start picking some inventory for this order with barcode. To be simple, I use 2 views and 2 viewmodel.
The process is:
1. User select an order the click a button "pickup"
2. I use ViewModelLocator (TinyIoc) to resolve the correct ViewModel of the pickup view
3. I call Initialize on the new ViewModel and pass some parameters needed. Like a list of items needed to be pickup.
4. Open the view in modal state.
I don't understand that if I change some qty in the list I pass on the second viewmodel, then hit the back button (modal view close). The quantity changed is now in the original viewmodel. How this is possible? I was thinking that passing parameter to a function do not share the same variable but just copy it??
Viewmodel of the first view (look at the Initialize function the List passed and the JobEnCours object)
private async Task GoPickup()
{
Device.BeginInvokeOnMainThread(async () =>
{
if (this.CodeJob != null && this.CodeJob != "")
{
this.IsBusy = true;
PrepChariotSP3ViewModel vm = ViewModelLocator.Resolve<PrepChariotSP3ViewModel>();
await vm.InitializeAsync(this._jobEnCours, this.ComposantesPick.ToList()) ;
await Shell.Current.Navigation.PushAsync(new PrepChariotSP3Page(vm));
this.IsBusy = false;
}
});
}
the the Initialize code on the second Viewmodel (look I set the JobEnCours.Description=Test)
public async Task InitialiseAsync(Job jobEnCours, List<ComposantePick> composantePick)
{
Title = "Ceuillette: " + jobEnCours.CodeProd;
this._jobEnCours = jobEnCours;
this.ComposantesPick = new ItemsChangeObservableCollection<ComposantePick>();
foreach(ComposantePick c in composantePick)
{
this.ComposantesPick.Add(c);
}
jobEnCours.Description = "test";
So, If I do the back button, then in the first VM the JobEnCours.Description is now set to "test" how this is possible?!
Any idea?
I have my test method in a test class. I use Coded UI.
Everything I tested so far seems good. Now I want to await a Ajax call on clicking the Save button, but I don't know how.
Is it possible to do that? And if my Ajax response is above 500ms the test should fail.
This is my sample class:
[TestInitialize]
public void TestInitialize()
{
string serviceName = "xxxxxxx.exe";
var binPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)));
string servicePath = #"\ServiceProjects\vvvvvv\bin\Debug\";
string absolutePath = String.Format("{0}{1}{2}", binPath, servicePath, serviceName);
Process.Start(absolutePath);
BrowserWindow.CurrentBrowser = "ie";
BrowserWindow.Launch(baseAddress);
}
[TestMethod]
public void ManagerTestMethod()
{
this.UIMap.ManagerTestMethod_MobilePrefix();
}
[TestCleanup]
public void TestCleanup()
{
this.UIMap.TestCleanup();
}
And in this ManagerTestMethod_MobilePrefix() method I click on the save button:
public void ManagerTestMethod_MobilePrefix()
{
#region Variable Declarations
HtmlDiv uISljedećizahtjevNoPane = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument.UISljedećizahtjevNoPane;
HtmlButton uIItemButton = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument.UIItemButton;
HtmlCustom uIItemCustom = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument1.UIŠifarniciCustom.UIItemCustom;
HtmlHyperlink uIMobilniprefiksHyperlink = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument1.UICodelistsSubMenuCustom.UIMobilniprefiksHyperlink;
HtmlDiv uIItemPane = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIAps_mng_mobilephonepPane.UIItemPane;
HtmlSpan uIItemPane1 = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIAps_mng_mobilephonepPane.UIItemPane1;
HtmlEdit uIApsmngmobilephonepreEdit = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIApsmngmobilephonepreEdit;
HtmlEdit uIApsmngmobilephonepreEdit1 = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIApsmngmobilephonepreEdit1;
HtmlEdit uIApsmngmobilephonepreEdit2 = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UIApsmngmobilephonepreEdit2;
HtmlButton uISačuvatiButton = this.UIAddikoAPSInternetExpWindow.UIAddikoAPSDocument2.UISačuvatiButton;
#endregion
// Click '+ Sljedeći zahtjev + No' pane
Mouse.Click(uISljedećizahtjevNoPane, new Point(1651, 234));
// Click '+ Sljedeći zahtjev + No' pane
Mouse.Click(uISljedećizahtjevNoPane, new Point(1778, 308));
// Click '+' button
Mouse.Click(uIItemButton, new Point(51, 23));
// Click custom control
Mouse.Click(uIItemCustom, new Point(48, 30));
// Click 'Mobilni prefiks' link
Mouse.Click(uIMobilniprefiksHyperlink, new Point(87, 18));
// Set flag to allow play back to continue if non-essential actions fail. (For example, if a mouse hover action fails.)
Playback.PlaybackSettings.ContinueOnError = true;
// Mouse hover pane at (1, 1)
Mouse.Hover(uIItemPane, new Point(1, 1));
// Reset flag to ensure that play back stops if there is an error.
Playback.PlaybackSettings.ContinueOnError = false;
// Click pane
Mouse.Click(uIItemPane1, new Point(6, 5));
// Type 'test1' in 'aps.mng.mobilephoneprefix.details.Code' text box
uIApsmngmobilephonepreEdit.Text = this.ManagerTestMethod_MobilePrefixParams.UIApsmngmobilephonepreEditText;
// Type '{Tab}' in 'aps.mng.mobilephoneprefix.details.Code' text box
Keyboard.SendKeys(uIApsmngmobilephonepreEdit, this.ManagerTestMethod_MobilePrefixParams.UIApsmngmobilephonepreEditSendKeys, ModifierKeys.None);
// Type 'test1' in 'aps.mng.mobilephoneprefix.details.CoreCode' text box
uIApsmngmobilephonepreEdit1.Text = this.ManagerTestMethod_MobilePrefixParams.UIApsmngmobilephonepreEdit1Text;
// Type '100' in 'aps.mng.mobilephoneprefix.details.Value' text box
uIApsmngmobilephonepreEdit2.Text = this.ManagerTestMethod_MobilePrefixParams.UIApsmngmobilephonepreEdit2Text;
// Click 'Sačuvati' button
Mouse.Click(uISačuvatiButton, new Point(52, 20));
}
The last step is crucial to me: Mouse.Click(uISačuvatiButton, new Point(52, 20)); in that step I am doing a Ajax call to my API controller in order to insert the data.
I want to be able to catch validations from my form, also I want to be able to catch the response from the Ajax call that is triggered by clicking on the save button.
I may have a idea you could try. I never had a situation like yours, so I can't confirm it will work.
You could provide a hidden control on that form with a value that will only be set if the Ajax call is completed. If you are able to find that control with your Coded UI test, you could run a timer for 500ms after clicking that save button.
I have a kendo.combobox() control on my Layout.cshtml page which is a list of projects.
#(Html.Kendo().ComboBox()
.Name("projects")
.Placeholder("select project")
.DataTextField("Text")
.DataValueField("ID")
.HtmlAttributes(new { style = "width:45%;" })
.Filter("contains")
.SelectedIndex((int)Session["ProjectNoIndex"])
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetProjectsList", "Home");
})
.ServerFiltering(true);
})
)
I have a menu as well in the Layout.cshtml which is created using #Html.ActionLinks (one sample below).
<li>#Html.ActionLink("Documents", "Search", "Document", new { projectNo = 1}, new {#id = "send"})</li>
Search action in Document controller and most other actions in the application expect the projectNo parameter (entire application works based on the selected project of the user). So, I thought of saving the selected ProjectNo in Session but if I do this then users can only work with 1 project even if they open the application in multiple tabs/windows in a single browser (sessions are shared across tabs/windows).
So, I thought of passing the selected ProjectNo using querystrings. I tried below, which worked fine except when user right clicks and open's the link in new tab. in such case, below click event does not fire.
$('#send').click(function () {
var x = $("#projects").data("kendoComboBox").selectedIndex;
var url = '#Url.Action("Search", "Document", new { projectNoIndex = "-1" })'
url = url.replace("-1", x);
this.href = url;
});
I don't want to restrict user by oncontextmenu = "return false;" option either. What are my options here?
Q1: How can I make sure I can pass the selected ProjectNo using querystring
Q2: Is there any other alternative to Session where I can persist the project information across tabs/windows which can be easily available in the entire application per user, per tab/window.
I am trying to switch to a New window which gets displayed when I click on the Debt Pricing Template. But I am unable to do that as a result of which I am not able to proceed with further scripting... The problem is I am not able to know what should I pass in the switchTo.window() because Pricing Approval Gateway window displays and following is the HTML for the new window:
<*h1 class="pageType noSecondHeader">Pricing Approval Gateway<*/h1>
Following is the code:
LoginPage2.driver.findElement(By.linkText("TEST ORG")).click();
System.out.println("3.Select Dept pricing template button from the organization detail page.");
if(LoginPage2.driver.findElement(By.name("debt_pricing_template")).isDisplayed())
System.out.println("User should able to navigate to Dept pricing template and template display few question, user have answer these question for further navigation.");
LoginPage2.driver.findElement(By.name("debt_pricing_template")).click();
LoginPage2.driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
LoginPage2.driver.switchTo().window("bPageTitle");
Please advise what needs to be added?
I never used it because in my tests I am not using any new windows, but this should help:
Set<string> handlers = driver.getWindowHandles();
if (driver.getWindowHandles().size()>= 1){
for(String handler : handlers){
driver.switchTo().window(handler);
if (driver.getElement(By.tagName("h1")).contains("Pricing")){
System.out.println("Get focus on Popup window");
break;
}
}
}
else System.out.println("No windows founded!");
I am not quite sure with the h1 approach. So if it does not help, try before opening new window storing current window to String:
String mainWindow = driver.getWindowHandle();
Then click the link (or do something else as you are doing now) to open new window. Then to switch to the new window:
Set<string> handlers = driver.getWindowHandles();
for (String handler : handlers){
if (!handler.equals(mainWindow)){
driver.switchTo(handler);
break;
}
}
And then to switch back to original window just do:
driver.switchTo(mainWindow);
Ofcourse the driver variable is expected live instance of
WebDriver
driver.findElement(By.linkText("Go to Billing Summary")).click();
driver.findElement(By.linkText("01 Mar 2016")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("AMS TAX")).click();
driver.findElement(By.linkText("00842")).click();
Set<String> instancewindow= driver.getWindowHandles();
Iterator<String> it = instancewindow.iterator();
String parent =it.next();
String child = it.next();
driver.switchTo().window(child);
driver.switchTo().frame("modalSubWindow");
driver.findElement(By.linkText("View More Vehicle Details>>")).click();
driver.switchTo().window(parent);