Please this simple scenario:
#Chrome
Scenario: Simple Calculation
Given user
When User login to the system
And ....
So i have many scenarios, each scenario use default Browser or specific one (in this example the Browser is Chrome)
So i have several URLs than i am checking so i looking for way to define global Tag what will represent URL and inside .cs file this Tag will converted into my URL (and as i mentioned before i have several).
And i want to use it this way:
#GlobalURL
#Chrome
Scenario: Simple Calculation
Given user
When User login to the 'GlobalURL'
And ....
Any suggestion ?
If you want to use #GlobalURL tag for scenarios, then you can add method with annotation: [BeforeScenario] and in this method get that hook, and depending on it's value get correct url. In my project I made a separate class - TestConfiguration, which properties (base url, key, what kind of test) and filled from tags before every scenario, and then used in test.
Also you can in scenario send parameter and based on it choose url in the code.
Related
In my effort of trying to find a neat way to validate which buttons are visible to the user based on his Role and Permissions i have encountered a problem. I am using the Page Object Model design pattern with selenium to test a website. A few pages have a different set of buttons which should either be visible or not to the user according to his role.
I keep a Dictionary<Permission,IWebElement> and initialize it in the constructor of the page (class representing a certain page in the site).
All web elements are defined as follows:
private IWebElement btn_openShop => driver.ById("open_shop");
(ById is equivalent to FindsElement(By.Id("open_shop"))
The problem is that if the button shouldn't exist an exception is thrown when adding it to the Dictionary.
Note: moving the initialization of the Dictionary wont help since i test both cases (one in which the user should see the button and one in which he shouldn't).
I changed the Dictionary to be of type <Permission,Lazy<IWebElement>>
and added items to it as follows:
dictionary.Add(somePermission,new Lazy<IWebElement>(()=>the button))
Edit: this technique works but it seems that when debugging in visual studio the code crashes.
Any thoughts? (no exceptions are thrown during test execution).
I'm currently in the process of designing as RESTful of an API as I can using Microsoft's Web API 2 in C#. What I'm struggling on is how best to represent resources or the proper way to do it where the GET call and POST/PUT are very different.
For example say I have something calls states that have an id, name, status, etc., these can be assigned to a document. So I have a route like this /documents/{id}/states/ . If I call a GET here I need to get the full list of all assigned states including their id, name, etc.
However, in order to change which states are assigned to the document I simply need to pass the id. I cannot do this individually, it must be an array that gets sent up since users may be interacting with hundreds or thousands at a time.
So in this case I have a few issues. I don't even know if POST or PUT is correct here, and second whichever one it is can I just take in an array of integers?
In your case, I would suggest PUT is the method you would be wanting to use, as you know the location of the resource that you are updating. For more info, see here: http://restcookbook.com/HTTP%20Methods/put-vs-post/
In ASP.NET Web API 2 you can use the [FromBody] parameter attribute, so that your method signature would be:
public void UpdateStates(int id, [FromBody]List<int> states) {}
More info on parameter attributes can be found here: http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api
My question is almost similar to this
ASP.Net Roles: Page-Level Security Question
except for the fact that I'm not using asp.net membership, What I have done is I have created roles and assigned pages to roles, menus are also populating according to the user's role. I want to restrict user to access pages by simply typing the PageName.aspx , One solution might be checking on every page load, but I don't think it's efficient. I have googled but only found solutions for adding <location path="Logon.aspx"> to restrict, I have to add this for every page in web.config, which defeats the whole purpose of keeping this thing dynamic, I am using Form Authentication, Some are suggesting creating a Base Class and derive other pages from that class, I think there may be some global.asax way to acheive this, but have no idea. Please suggest me best approach to achieve this !
P.S : I am not using ASP.NET Membership
legendinmaking,
This is depend on your project layout . One solution is that you create a folder structure where you place webconfig and there you give permission for the user i think this may be one solution and may be others.
finally, what I did is I checked access of Pages for every user on MasterPage's Page_Load using a method name IsPageAssignedToRole() to check
string requestedPage = Request.Url.Segments[Request.Url.Segments.Length-1];
if (requestedPage != "UnAuthorized.aspx")
{
AdminUserAuthInfo au = (AdminUserAuthInfo)Context.Items["AdminUserAuthInfo"];
int current_role= int.Parse(au.Roles[0].ToString());
if (!AdminRole.IsPageAssignedToRole(current_role, requestedPage))
{ Response.Redirect("UnAuthorized.aspx",true); }
}
I'm using EWL and I have an EwfPage and when I type partial in the Info class I see:
partial void initDefaultOptionalParameterPackage( OptionalParameterPackage package )
and
partial void initUserDefaultOptionalParameterPackage( OptionalParameterPackage package )
I don't really see what they're used for. They also sound similar and I'm wondernig what the difference between them is.
They are both used if you want an optional parameter to default to something other than the default value of its C# data type. There are two significant differences:
initUserDefaultOptionalParameterPackage is called only when you are creating an Info object for the page; it is not called when the page is requested. If a request is made without a parameter value in the URL, the framework will fall back to the value specified in initDefaultOptionalParameterPackage or the data type default.
You can access AppTools.User from initUserDefaultOptionalParameterPackage if you meet the conditions specified in the doc comment for AppTools.User.
An example of when you might use initUserDefaultOptionalParameterPackage is a page that should default to showing information for the currently logged-in user but has a select list or something that lets you look at information for a different user.
In our new product we have a few data entry fields that require you to search for the correct value to place in this field.
When you enter this data entry field I would like to provide a search option via something on the view (perhaps an Ajax implementation) and have it allow searching of the database for the value, but when the result returns I want to keep the existing values in place for other fields not affected by the search.
But I have no idea how to do this with MVC. Does anyone have any suggestions on how this should be done?
Write your data entry page in the
usual way for an ASP.NET MVC view.
Get it working without the Ajax
(e.g., submit works correctly when
you just type in the values, without
auto complete).
Write the prototype for a JavaScript method you'll called when the user performs a certain action (e.g. presses a key inside of a certain control). But this inside a script tag in your aspx page. Unfortunately, stack overflow seems to "sanitize" script tags in my example, so I can't demonstrate that part. But you're JavaScript prototype will look something like this:
function startAutoComplete() {
}
Now hook up the event handlers on the user interface control. You need to call the function you've just prototyped an appropriate event handlers for your application. From your description, it sounds like you might want to use onkeydown, but there are lots of events to choose from. You probably need to handle more than one event, as appropriate for your application.
So far, everything that we've done has been standard aspx and JavaScript. In this step, we'll do the only part of the whole process which is really different for ASP.NET MVC. You need to add an action to your controller which will be called (indirectly) by the JavaScript prototype you've just written. The action should accept appropriate input (e.g., a string representing the text from control, or something like that, as appropriate for your application) and return its results in JSON format. I'm going to show a really simple example here; feel free to substitute more complex code in your real application.
public ActionResult GetSuggestions(string searchText)
{
return Json(new {SearchText = searchText});
}
This example just returns a JavaScript object containing one property, which contains the value passed to the function. Like you said, you can write something more useful for your application.
Now you need to call this function in JavaScript. The URI will look something like:
http://localhost/mycontroller/GetSuggestions?searchText=Foo
It is possible to make Ajax calls without a JavaScript library, but much easier if you use jQuery or some other library which handles cross-browser compatibility issues for you. Since I happen to like jQuery, I'll demonstrate that. Let's update the startAutoComplete method we prototyped earlier:
function startAutoComplete() {
var searchText = $("#myeditorid").text();
$.getJSON("/mycontroller/GetSuggestions?searchText=" + searchText,
null,
autoCompleteResponse);
}
The first line uses jQuery to get the text in the control with the ID myeditorid. We'll pass this to the ASP.NET MVC action as the searchText argument, by appending it as a query string parameter.
The next line, which starts with $.getJSON calls a jQuery function which makes an Ajax call to the URI you specify. We pass an argument, autoCompleteResponse, which is the name of a JavaScript method to be called if the response from the Ajax call is successful. Now we have to write autoCompleteResponse.
function autoCompleteResponse(data) {
if (data.SearchText)
{
$("#myeditorid").text(data.SearchText);
}
}
This says, "If the data returned has a SearchText property, set the text of the control to that value." Again, do whatever is appropriate for your application with the data returned.