im very new to testing and have no training in automated tests so please bare with me if i say stupid things but ill try the best i can.
Bascially i am trying to assert that a specific employee in the employee list has the status of 'leaver'.
This is what i have tried (and other variations with the different classes)
Assert.Equal("image-tile__badge background-color--status-leaver ng-star-inserted", Driver.FindElement(By.XPath("//*[contains(#class,'image-tile__content-header') and contains(text(),'End Date, Contract') and contains(#class, 'image-tile__badge')]")).GetAttribute("Class"));
Assert.Equal("image-tile__badge background-color--status-leaver ng-star-inserted", Driver.FindElement(By.XPath("//*[contains(#class,'image-tile__content-header') and contains(text(),'End Date, Contract')]")).FindElement(By.XPath("//*[contains(#class, 'image-tile__badge')]")).GetAttribute("Class"));
The last one finds the element when the status is 'new', but when i change the employee status to 'leaver', it still returns as 'new' so possibly looking at another employee with a 'new' status.
Hopefully this is enough info, let me know if more is needed (this is my first ever post!)
HTML code in image below
[HTML code on Chrome]
[1]: https://i.stack.imgur.com/kUxkf.png
Summary: im trying to assert that the Employee "End Date, Contract" has the status of leaver (aka the leaver class "image-tile__badge background-color--status-leaver ng-star-inserted")
Thanks everyone for their help!
One of my devs managed to take #noldors example and modify it a bit so heres what ended up working for me:
var newElmList1 = Driver.FindElements(By.CssSelector("div.background-color--status-leaver")).ToList();
List<string> newNames1 = new List<string>();
foreach (var newElm in newElmList1)
{
var newName1 = newElm.FindElement(By.XPath(".."))
.FindElement(By.CssSelector("div.image-tile__content-header")).Text;
newNames.Add(newName1);
}
if (!newNames.Contains("End Date, Contract"))
{
throw new Exception("Exception Error on leaver Person");
}
As per your screenshot i fill it's better if you try using Xpath
var elmList = Driver.FindElements(By.Xpath("//div[contains(text(),'leaver')]")).ToList();
i hope it will help you
Thank You.
According to your screenshot, you can find all elements with 'Leaver' specific class with this;
var leaverElmList = Driver.FindElements(By.CssSelector("div.background-color--status-leaver")).ToList();
List<string> leaverNames = new List<string>();
foreach (var leaverElm in leaverElmList) {
var leaverName = leaverElm.FindElement(By.XPath(".."))
.FindElement(By.CssSelector("div.image-tile__content-header"));
.Text()
leaverNames.Add(leaverName);
}
Enddate, Contract which is not related to the div that contains Leaver. It's direct parent is the image-tile div
Related
I have been developing a search engine for a business directory application using Lucene.net. However when i search for Sports shop it returns the result of other shops including the sports shops because the key word shop matches with that. So how can i prioritize that it should return the results which is matches with the keyword sport
If anyone have solution for this please share here. Any helpful example or links will be appreciated.
I would very much appreciate it if you could paste some code to give you a better example.
However, from reading your question I think that what you need is a phrase query to give Sports Shop a higher boost.
My implementation of this query is this:
public List QueryToPhraseQuery(string pQuery) {
QueryParsers.Classic.MultiFieldQueryParser oPhraseParser = new QueryParsers.Classic.MultiFieldQueryParser(Version, FieldArray, Analyzer, BoostDictionary);
List<PhraseQuery> lstPhraseQuery = new List<PhraseQuery>();
HashSet<Term> lstTerms = new HashSet<Term>();
oPhraseParser.Parse(pQuery).ExtractTerms(lstTerms);
foreach (var group in lstTerms.GroupBy(x => x.Field))
{
PhraseQuery oPhraseQuery = new PhraseQuery() { Boost = 10, Slop = 3 };
foreach (var oTerm in group.ToList())
{
oPhraseQuery.Add(oTerm);
if (oTerm.Field == Field.ImportantField)
oPhraseQuery.Boost = 30;
}
lstPhraseQuery.Add(oPhraseQuery);
}
return lstPhraseQuery;
}
This would search for thing like this in your index which will match exactly and will return better results with more relevance
attributedescriptions:"something something"~3^10.0 attributemajor:"something something"~3^30.0 description:"something something"~3^10.0 edescription:"something something"~3^10.0
If you want me to give you an example using your code, just past eit and I can modify it to better fit your exam
This is a part of the code that i was trying to use to get the respective elements, but it keeps giving me the following error:
System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]or
others identical
This is also shown in a datagridview, in her rows.
IList<IWebElement> ruas = Gdriver.FindElements(By.ClassName("search-title"));
String[] AllText = new String[ruas.Count];
int i = 0;
foreach (IWebElement element in ruas)
{
AllText[i++] = element.Text;
table.Rows.Add(ruas);
}
First thing is: as far as I understand the elements you are talking about are not contained in table. Its a list: <ul class="list-unstyled list-inline">... (considering the comment you left with site link)
If you want to find those elements you can use the code below:
var elements = driver.FindElements(By.CssSelector("ul.list-inline > li > a"));
// Here you can iterate though links and do whatever you want with them
foreach (var element in elements)
{
Console.WriteLine(element.Text);
}
// Here is the collection of links texts
var linkNames = elements.Select(e => e.Text).ToList();
Considering the error you get, I may assume that you are using DataGridView for storing collected data, which is terribly incorrect. DataGridView is used for viewing data in MVC application. There is no standard Selenium class for storing table data. There are multiple approaches for this, but I can't suggest you any because I don't know your what you are trying to achieve.
Here is how i answered my own question:
IList<string> all = new List<string>();
foreach (var element in Gdriver.FindElements(By.ClassName("search-title")))
{
all.Add(element.Text);
table.Rows.Add(element.Text);
}
I am new to sitefinity, I am looking for a way to the access the description field of the classification in my code.
Please let me know how I can do that.
I have written code that gets me all the classifications(hierarchial taxonomy) in the form of a tree that I am binding to a RadTreeView control.
Each node in the RadTreeView control has properties like text, navigateURL etc. but no Description. I assume I have to do it differently to get the description field.
Any help or direction is appreciated. It looks to me like a very basic implementation to get the description but not able to get it.
Thanks!
Below is a function that uses the Sitefinity API to look up a Category by Title.
You'll need the following using statements:
using Telerik.Sitefinity.Taxonomies;
using Telerik.Sitefinity.Taxonomies.Model;
I've added the line that gets the description to hopefully better answer your question.
private Taxon GetCategoryByTitle(string category)
{
var manager = TaxonomyManager.GetManager();
var categoriesTaxa = manager.GetTaxonomy<HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId);
var taxomony = categoriesTaxa.Taxa.FirstOrDefault(t => t.Title == category);
var description = taxomony.Description; //get description here
return taxomony;
}
I am having problems searching through my Arraylist. The array list stores various information about a number of teams such as the image path to their logo and the team name etc. It is being filled from a separate datafile using a StreamReader
I would like the user to input something in a Textbox from a windows form such as the team name and then consequently the program will then search my arraylist for said string and open another form where the information of the searched team will be loaded up on screen using the Form.Load procedure
To put it simply.
private void btn_Search_Click(object sender, EventArgs e)
{
//what code do I write here?
}
I understand that I might be a little to deep here for my current knowledge of coding so help would be appreciated.
EDIT: unfortunately it must be in an arraylist, sorry for the inconvenience.
If you can use LINQ:
string nameToMatch = "Tigers"; //can you tell who's from Michigan?
List<Team> teams = new ArrayList<Team>();
//fill team data here
Team selected = teams.FirstOrDefault(t => t.TeamName.Equals(nameToMatch, StringComparison.OrdinalIgnoreCase));
Something like this should work. (This will match the text exactly but allow the search to be case insensitive. You can read about other options here.)
If you want to match a list of all "partial matches", you can do this instead:
List<Team> matchedTeams = teams.Select(t => t.TeamName.Contains(nameToMatch));
Read here for an extension overload of Contains that takes a StringComparison enum value.
If you're unfamiliar with LINQ like I am you could use a foreach loop. Something like this:
String nameToMatch = textBox1.text; //read from the text box
foreach (Object obj in Teams)
{
MyTeam team = (MyTeam)obj; //MyTeam is an object you could write that would store team information.
if (team.TeamName.ToUpper() == nameToMatch.ToUpper()) //case insensitive search.
{
FormTeam frmTeam = new FormTeam(team); //windows form that displays team info.
frmTeam.Visible = true;
break; //if team names are unique then stop searching.
}
}
Worst case senario is pretty bad, but for me, at least, it's easier to get my head around than LINQ. Good Luck, hope that helps.
You can use some codes like this to fill your arraylist:
// ArrayList class object
ArrayList arrlist = new ArrayList();
// add items to arrlist collection using Add method
arrlist.Add("item 1");
arrlist.Add("item 2");
arrlist.Add("item 3");
arrlist.Add("item 4");
arrlist.Add("item 5");
and use some codes like this to search in your arraylist
string teamName= this.txtTeamName.Text;
// for loop to get items stored at each index of arrlist collection
for (int i = 0; i < arrlist.Count; i++)
{
if(arrlist[i].toString()==teamName)
// open a new form for show the found team details
}
it is a good practice to change the cunstractor of your "Team Details" form to get a "team name"
frmTeamDetails(team myteam)
then use this code in the above FOR statement:
frmTeamDetals frm=new frmTeamDetals(teamName);
frm.ShowDialog();
Hi i'm using magento soap api v2 with c#. Do far I have been calling
var groupedProducts = magentoService.catalogProductLinkList(sessionId, "grouped", id, "productId");
that does return grouped Products, but instead I would like to retrieve simple products such as green large t-shirt which is associated with configurable t-shirt.
How can this be achieved?
Unfortunatelly that's not possible with the magento SOAP api. You are not able to retrieve child products of a parent product via the api. Believe me, I have tackled this myself some time ago. I can suggest 2 fixes and 1 workaround.
Workaround - Try to retrieve child products by sku or name. This can work provided that all your child products use the parent's name or sku as the prefix. That's how I resolved it in the beginning and it worked well as long as the client did not introduce child product names that did not match the parent name. Here's some sample code:
//fetch configurable products
filters filter = new filters();
filter.filter = new associativeEntity[1];
filter.filter[0] = new associativeEntity();
filter.filter[0].key = "type_id";
filter.filter[0].value = "configurable";
//get all configurable products
var configurableProducts = service.catalogProductList(sessionID, filter, storeView);
foreach (var parent in configurableProducts)
{
filters filter = new filters();
filter.filter = new associativeEntity[1];
filter.filter[0] = new associativeEntity();
filter.filter[0].key = "type_id";
filter.filter[0].value = "configurable";
filter.complex_filter = new complexFilter[1];
filter.complex_filter[0] = new complexFilter();
filter.complex_filter[0].key = "sku";
filter.complex_filter[0].value = new associativeEntity() { key="LIKE", value=parent.sku + "%" };
var simpleProducts = service.catalogProductList(sessionID, filter, storeView);
//do whatever you need with the simple products
}
Fix #1 - Free - Write your own api extension. To retrieve child products you could use:
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
You then send the results to the api caller and all should be well. I have not tried that myself, though, so I'm not sure if there are any other problems on the way.
Fix #2 - Paid - Get the (excellent, but pricey) CoreAPI extension from netzkollektiv. That's what I did when the workaround stopped working out for me and never regretted this decision.
I dont think what you are trying to do is possible with default magento SOAP api.
What you could do is create a custom api
eg.
How to setup custom api for Magento with SOAP V2?
http://www.magentocommerce.com/api/soap/create_your_own_api.html
Then create the logic to retrieve all the simple products associated with that configurable product.
$_product = Mage::getModel('catalog/product')->load($id);
// check if it's a configurable product
if($_product->isConfigurable()){
//load simple product ids
$ids = $_product->getTypeInstance()->getUsedProductIds();
OR
$ids = Mage::getResourceModel('catalog/product_type_configurable')->load($_product);
}
Please be aware that it should be
... new associativeEntity() { key="like", ...
and not
... new associativeEntity() { key="LIKE", ....
Upper case LIKE does not work.
I found a Magento Extension on Github, which includes this functionallity.
Get configurable's subproducts informations in the same response.
https://github.com/Yameveo/Yameveo_ProductInfo