First of all below is my Excel file.
+-----------------+-----------------------------+
| Data | Output |
+-----------------+-----------------------------+
| URL | http://www.gmail.com |
+-----------------+-----------------------------+
| Username | abc123 |
+-----------------+-----------------------------+
| Password | 123abc |
+-----------------+-----------------------------+
In my Initialize class I am calling URL to be navigates.
Then in test class to get data from excel for Username and Password. Below is my code.
My Main class contains
PageObject credLogin = new PageObject();
var fileName = #"path";
string sheetName = "Sheet";
var book = new LinqToExcel.ExcelQueryFactory(fileName);
var users = from x in book.Worksheet<Login>(sheetName)select x;
foreach (var x in users)
{
My.driver.Navigate().GoToUrl(a["URL"]);
credLogin.Login(x["uid"], x["pwd"]);
}
--> My PageObject class contains
namespace Abc13465
{
class PageObject
{
//use using OpenQA.Selenium.Support.PageObjects;
[FindsBy(How = How.Name, Using = "txtuname")]
public IWebElement Username { get; set; }
[FindsBy(How = How.Name, Using = "txtpass")]
public IWebElement Password { get; set; }
[FindsBy(How = How.ClassName, Using = "login_button")]
public IWebElement logbtn { get; set; }
public void Login(string uname, string paswd)
{
Username.EnterText(uid);
Password.EnterText(pwd);
logbtn.Click();
}
PN: URL link and Username/Password are changed to but al functions are same.
My Question:
What am I missing here? Neither, I am not able to get data from excel for username and password. Nor able to navigate to the site
Format that you are using is not correct. I made that same mistake so it was not working. Use below format and It should work.
+----------------------+----------+------------------+
| URL | Username | Password |
+----------------------+----------+------------------+
| http://www.gmail.com | abc123 | 123abc |
+----------------------+----------+------------------+
Related
I have a certain table in the database that stores the following objects:
public partial class Invoice
{
public string DocumentNumber { get; set; }
public DateTime? DocumentDate { get; set; }
public string DocumentReference { get; set; }
public string SerialNumber { get; set; }
public string ProductCode { get; set; }
public string Description { get; set; }
public string Certificate { get; set; }
public string Language { get; set; }
public string Email { get; set; }
}
I also have a query that returns me the number of specific elements:
SELECT Count(*)
FROM (
SELECT DocumentNumber,DocumentDate,DocumentReference
FROM vInvoiceSwivelInfoWeb
WHERE Email = 'someemail#gmail.com' AND Language = 'FR'
GROUP BY DocumentNumber,DocumentDate,DocumentReference
) AS T
The answer looks something like this:
How to use EF to make such a request and get a numerical answer?
I tried like this:
_context.Database.ExecuteSqlRawAsync($"..some SQL query..")
but I do not get the expected result.
UPD: Having received the answer about the impossibility of fulfilling this request through EF, the following question reasonably arose: Is it possible to make this request using LINQ?
You can Leverage ADO.NET via the Context.Database property.
Unfortunately, there is no way to get the count from the database using EF Core execute methods if you have a custom query that is not related to your entities.
using (var command = context.Database.GetDbConnection().CreateCommand())
{
command.CommandText = "SELECT Count(*) From Table1";
context.Database.OpenConnection();
using (var result = command.ExecuteReader())
{
// do something with result
}
}
for Updated question
var count = from a in _context.vInvoiceSwivelInfoWeb
where a.Email == "someemail#gmail.com" && a.Language == "FR"
group new { a.DocumentNumber , a.DocumentReference , a.DocumentDate } by a into g
select g.Count()
also, it's important to know which version of EF-Core are you using:
currently, if you are using EF-Core 3 group-by doesn't translate to SQL command so you have to do it on client-side:
check this link :
https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#linq-queries-are-no-longer-evaluated-on-the-client
for EF-Core 3.0 - 3.1.1
var count = _context.vInvoiceSwivelInfoWeb
.Where(a => a.Email == "someemail#gmail.com" && a.Language == "FR" ).ToList()
.GroupBy(a => new { a.DocumentNumber ,a.DocumentDate, a.DocumentReference }).Count();
I have a problem. I am using a Visual studio web performance test and I have a csv file with the data that I need to send in a string body of a web request. The issue is that when the web test retrieve the data from accountID it takes the data as int instead of a string. So if the account number is 000005 or 000016 the test put a 5 and a 15 ignoring the zeroes on the left. That give me an error on my web service.
Is there a way to force the web test to see all the data as strings? Thanks
Below you can see an example of the csv file. The data is not a lot and is only 2 columns so I don’t want to create a database for that
AccountsNames, AccountID
Nombre1, 00001
Nombre3, 00002
Nombre4, 00003
Nombre5, 00004
Nombre6, 00005
Nombre7, 00006
Nombre8, 00007
What I end up doing is creating a Web Request plug in that gets the data source from the webtest context and editing the value.
Here is a code example:
namespace WebTestProjectToPlayArround
{
[DisplayName("Add Padding Zeroes")]
[Description("")]
public class EditContextParameter : WebTestRequestPlugin
{
[DisplayName("DataSourceContext")]
[Description("")]
public string DataSourceContextParam { set; get; }
[DisplayName("ContextParamToStoreValue")]
[Description("")]
public string ContextParam { set; get; }
public override void PreRequest(object sender, PreRequestEventArgs e)
{
base.PreRequest(sender, e);
var value = (string) e.WebTest.Context[DataSourceContextParam];
string newValue = "";
object contextParam;
string contextName = value.Replace("{","").Replace("}", "");
if (e.WebTest.Context.TryGetValue(contextName, out contextParam))
{
newValue = contextParam.ToString();
newValue = newValue.PadLeft(10, '0');
}
e.WebTest.Context[ContextParam] = newValue;
}
}
}
I have a class called AccountData and I would like to return all rows that relate to a particular user. In the class I have a Pointer to the User table which contains their "ObjectId"
I have tried with the following call to the API:
string url = "https://api.parse.com/1/classes/AccountData?" + WebUtility.UrlEncode("where={\"user\":\"fvJ8jPjyjx\"}");
where the fvJ8jPjyjx is the ObjectId of the user I want rows relating to...
The api doesn't throw any errors just returns:
{"results":[]}
I have also tried it using a "User Object" as follows:
public class AccountDataUser
{
public string __type { get; set; }
public string className { get; set; }
public string objectId { get; set; }
}
building the object as follows:
AccountDataUser user = new AccountDataUser();
user.__type = "Pointer";
user.className = "_User";
user.objectId = objectId;
string jsonUser = JsonConvert.SerializeObject(user);
but this throws an api error.
Can anyone help me return the rows relating to a "user" please?
Thanks
UPDATE
Based on Ryans feedback I have reverted to trying to send an object...
This is what is being sent:
GET https://api.parse.com/1/classes/AccountData?where%3D%7B%22user%22%3A%22%7B%22__type%22%3A%22Pointer%22%2C%22className%22%3A%22_User%22%2C%22objectId%22%3A%22fvJ8jPjyjx%22%7D%22%7D HTTP/1.1
Content-Type: application/json
X-Parse-Application-Id: xxxxx
X-Parse-REST-API-Key: xxxxxx
Host: api.parse.com
Connection: Keep-Alive
The url is built with this line of code:
ParseModel.AccountDataUser user = new ParseModel.AccountDataUser();
user.__type = "Pointer";
user.className = "_User";
user.objectId = objectId;
string jsonUser = JsonConvert.SerializeObject(user);
string url = "https://api.parse.com/1/classes/AccountData?" + WebUtility.UrlEncode("where={\"user\":\"" + jsonUser + "\"}"); // this doesn't work
And the error I receive from the API is:
{"code":107,"error":"invalid json: {\"user\":\"{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"fvJ8jPjyjx\"}\"}"}
I believe the issue is in building the URL. You're wrapping the JSON in a string and Parse is expecting an object. If you strip the double quote around jsonUser, I bet that'll work.
string url = "https://api.parse.com/1/classes/AccountData?" + WebUtility.UrlEncode("where={\"user\":" + jsonUser + "}");
Here I am retrieving items and including the creator of the item. The goal is to include only the first and last name from the creator, not the entire user model.
var items = _db.Items.Include("Creator")
The item model has Creator as a navigation property like this:
public User Creator { get; set; }
It works fine, but it loads the entire user model, when really I just want the first name and last name.
How do I specify I only want specific property returned from the user model?
You cannot do that using Include. You can use Select instead:
var items = _db.Items.Select(i => new { Item = i, Creator = new { i.Creator.FirstName, i.Creator.LastName } });
Update
If you need to return that query as method result you have to create a class which could hold the results:
public class ItemWithCreatorNames
{
public Item Item { get; set; }
public string CreatorFirstName { get; set; }
public string CreatorLastName { get; set; }
}
var items = _db.Items.Select(i => new ItemWithCreatorNames { Item = i, CreatorFirstName = i.Creator.FirstName, CreatorLastName = i.Creator.LastName });
I'm using ASP.Net MVC3, I've a View in which I'm displaying a simple Table with Model Data as follows:
+-------+---------------+----------------+
| ID | Name | Order |
+-------+---------------+----------------+
| ID | Name | textbox val=1 |
+-------+---------------+----------------+
| ID | Name | textbox val=3 |
+-------+---------------+----------------+
| ID | Name | textbox val=2 |
+-------+---------------+----------------+
+-------+ +--------------+
|submit | | update order |
+-------+ +--------------+
Here, Order column contains Inputbox with Order values (1,3,2 etc.,). I need to Update my Model [Item {ID, Name, Order}]by reading Order column.
Meaning, I need to submit the Order values to Model, by reading a HTML table column. How to do this?
Create a view model for each item:
public class ItemViewModel
{
public string Id { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
And a model for the action:
public class EditViewModel
{
public IEnumerable<ItemViewModel> Items { get;set; }
public int Index { get; set; }
}
Render the rows like this:
#foreach (var item in Model.Items)
{
<tr>
<td><input type="hidden" name="Id[#Model.Index]" value="#item.Id" />#item.Id</td>
<td>#item.Name</td>
<td><input type="text" name="Value[#Model.Index]" value="#item.Value" /></td>
</tr>
#{ Model.Index = Model.Index + 1 }
}
And finally receive the rows as:
[HttpPost]
public ActionResult Edit(ItemViewModel[] items)
{
}