How to verify that the table has been correctly sorted in Codeception? - codeception

How can I test that the order of the rows in an HTML table is correct, after "clicking" table column caption to sort the table?

It should be something like this:
*Assuming that the table has only 1 column
$elements = $this->elements($this->using('xpath')->value("//div[#id='row']/div")); //identifying row element
$rows = count($elements); //count the number of rows
$unsortedrow = [];
$unsortedrows = []
for($count=0;$count<$rows;$count++){ // Get all values in Unsorted table
$unsortedrow[$count] = $I->grabTextFrom('//div[#id='main_body']/div/div['.$count.']/div/strong'); // Get text from row
array_push($unsortedrows, $unsortedrow[$count]); // push the value of row N to rows array
}
Note: $this->elements() and count() are proven working in selenium 2 but I don't know if it also does in codeception, according to some of the articles i've read seeNumberOfElements is the alternative for that.

Related

Comparing multiple row and columns in sql server

I had two tables first one is the real table second one is the temporary. I had to compare this two table . First table had 'KartelaKod' field should match with temp's 'KartelaKodu' field, First's 'OzellikKod' field should match with temp's 'OzellikKodu',first's 'AltKod' field should match with temp's 'StokKodu'.
Finally if it doesn't match exactly it should return ''.
PS: You should have to group first table according to VrtUrunKod.
In example if MAM|002's (which is VrtUrunKod) OzellikKod field doesn't match with temp table's OzellikKodu field, it should look for another VrtUrunKod record.
Edit1:isnull((Select TOP 1 VrtUrunKod From KonfigOlusmusOzellikler k Where Sirket_Kod = #sp_Sirket_Kod and AnaUrunKod = #spStokKod and
exists(Select * From #TempDegisen t Where t.KartelaKodu = k.KartelaKodu and t.OzellikKodu = k.OzellikKod and t.StokKodu = k.AltKod)),'') this is what i written so far you can ignore Sirket_Kod field and parameter.
This should produce a list of rows where there is a k with no matching t, and at with no matching k. If no rows result, all rows are matched:
SELECT *
FROM
KonfigOlusmusOzellikler k
FULL OUTER JOIN
#TempDegisen t
ON
t.KartelaKodu = k.KartelaKodu and
t.OzellikKodu = k.OzellikKod and
t.StokKodu = k.AltKod
WHERE t.KartelaKodu IS NULL OR k.KartelaKodu IS NULL

PIG filter out rows with improper number of columns

I have simple data loaded in a:
dump a
ahoeh,1,e32
hello,2,10
ho,3
I need to filter out all rows with number of columns/fields different than 3. How to do it?
In other words result should be:
dump results
ahoeh,1,e32
hello,2,10
I know there should be a FILTER built-in function. However I cannot figure out what condition (number of columns =3) should be defined.
Thanks!
Can you try this?
input
ahoeh,1,e32
hello,2,10
ho,3
3,te,0
aa,3,b
y,h,3
3,3,3
3,3,3,1,2,3,3,,,,,,4,44,6
PigScript1:
A = LOAD 'input' AS (line:chararray);
B = FOREACH A GENERATE FLATTEN(STRSPLIT(line,','));
C = FOREACH B GENERATE COUNT(TOBAG(*)),$0..;
D = FILTER C BY $0==3;
E = FOREACH D GENERATE $1..;
DUMP E;
PigScript2:
A = LOAD 'input' USING PigStorage(',');
B = FOREACH A GENERATE COUNT(TOBAG(*)),$0..;
C = FILTER B BY (int)$0==3;
D = FOREACH C GENERATE $1..;
DUMP D;
Output:
(ahoeh,1,e32)
(hello,2,10)
(3,te,0)
(aa,3,b)
(y,h,3)
(3,3,3)
(It seems that I don't have enough karma to comment; that's why this is posted as a new answer.)
The accepted answer doesn't quite behave as expected if null/empty string is a valid field value; you need to use COUNT_STAR instead of COUNT to count empty/null fields in your schema.
See: https://pig.apache.org/docs/r0.9.1/func.html#count-star
For example, given the following input data:
1,2,3
1,,3
and this Pig script:
a = load 'input' USING PigStorage(',');
counted = foreach a generate COUNT_STAR(TOBAG(*)), $0..;
filtered = filter counted by $0 != 3;
result = foreach filtered generate $1..;
The filtered alias will contain both rows. The difference is that COUNT({(1),(),(3)}) returns 2 while COUNT_STAR({(1),(),(3)}) returns 3.
I see two ways to do this:
First, you can rephrase the filter I think, as it boils down to: Give me all lines that do not contain an NULL value. For lots of columns, writing this filter statement is rather tedious.
Second, you could convert your columns into a bag per line, using TOBAG (http://pig.apache.org/docs/r0.12.1/func.html#tobag) and then write a UDF that processes the input bag to check for null tuples in this bag and return true or false and use this in the filter statement.
Either way, some tediousness is required I think.

Pig script to get top 3 data in a single record

I have the sample data as
user_id, date, accessed url, session time
the data refers to the top 3 interests of the user depending on the session time.
Got the data using the code:
top3 = FOREACH DataSet{
sorted = ORDER DataSet BY sessiontime DESC;
lim = LIMIT sorted 3;
GENERATE flatten(group), flatten(lim);
};
Output:
(1,20,url1,2484)
(1,20,url2,1863)
(1,20,url3,1242)
(2,22,url4,484)
(2,22,url5,63)
(2,22,url6,42)
(3,25,url7,500)
(3,25,url8,350)
(3,25,url9,242)
But I want my output to be like this:
(1,20,url1,url2,url3)
(2,22,url4,url5,url6)
(3,25,url7,url8,url9)
Please help.
You are close. The problem is that you FLATTEN the bag of URLs when you really want to keep them all in one record. So do this instead:
top3 = FOREACH DataSet{
sorted = ORDER DataSet BY sessiontime DESC;
lim = LIMIT sorted 3;
GENERATE flatten(group), lim.url;
};
Based on the output you got, you will now get
(1,20,{(url1),(url2),(url3)})
(2,22,{(url4),(url5),(url6)})
(3,25,{(url7),(url8),(url9)})
Note that the URLs are contained inside a bag. If you want to have them as three top-level fields, you will need to use a UDF to convert a bag into a tuple, and then FLATTEN that.

Active record - 3 results found, but only one being returned

The query below is returning that 3 results are available, but it is only returning one entry id.
How can I have the three entry_id's returned?
$this->EE->db->select('entry_id, count(portfolio_number) AS results');
$this->EE->db->from('submissions');
$this->EE->db->where('type_id', '1');
$this->EE->db->where('member_group', $member_group);
$this->EE->db->group_by('portfolio_number');
$this->EE->db->having('results = 3');
$query = $this->EE->db->get();
$submissions = $query->result_array();
print_r($submissions);
EDIT:
I have a table columns entry_id, member_group, type_id and portfolio_number.
The portfolio_number column will have a number between 1 and 7.
I need to query the database for 3 rows that have the same portfolio_number (as well as matching type and member_id) and return the entry_id for each of those three rows.
There must be 3 results, else I don't want to show them.
You can handle it like this
$results = $this->EE->db
->select('entry_id')
->from('submissions')
->where('type_id', '1')
->where('member_group', $member_group)
->group_by('portfolio_number')
->get()
->result_array();
if(count($results)){
return $results
}else {
return false;
}
Your $this->EE->db->group_by('portfolio_number'); is causing a single row with aggregated data to be returned.
If you want all the ids to be returned as well, you can try adding
$this->EE->db->select('GROUP_CONCAT(entry_id) AS entry_ids', false);
and then splitting the entry_ids field in PHP:
str_getcsv($submissions);
Edit: I put in the second argument for the select query to prevent backticks being placed around the custom select query.
Can you please replace this code
$this->EE->db->group_by('portfolio_number'); //It will return only one row per portfolio_number
$this->EE->db->group_by('portfolio_number,entry_id'); // It will return one row per portfolio_number and entry_id
I think it will return 3 rows of different entry_id

Creating filter with SQL queries

I am trying to create a filter with SQL queries but am having trouble with numeric values linking to other tables.
Every time I try to link to another table, it takes the same record and repeats it for every element in the other table.
For example, here is query:
SELECT ELEMENTS.RID,TAXONOMIES.SHORT_DESCRIPTION,[type],ELEMENT_NAME,ELEMENT_ID,SUBSTITUTION_GROUPS.DESCRIPTION,namespace_prefix,datatype_localname
FROM ELEMENTS,SUBSTITUTION_GROUPS,TAXONOMIES,SCHEMAS,DATA_TYPES
WHERE ELEMENTS.TAXONOMY_ID = TAXONOMIES.RID AND ELEMENTS.ELEMENT_SCHEMA_ID = SCHEMAS.RID AND
ELEMENTS.DATA_TYPE_ID = DATA_TYPES.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = 0
The last line is the actual filtering criteria.
Here is an example result:
There should only be ONE result (Item has an RID of 0). But it's repeating a copy of the one record for every result inside the substitution groups table (there's 4).
Here is my database schema for reference. The lines indicate relationships between tables and the circles indicate the values I want:
You're forgot to join between ELEMENTS and SUBSTITUTION_GROUPS in your query.
SELECT
ELEMENTS.RID,TAXONOMIES.SHORT_DESCRIPTION,[type],ELEMENT_NAME,ELEMENT_ID,SUBSTITUTION_GROUPS.DESCRIPTION,namespace_prefix,datatype_localname
FROM
ELEMENTS,SUBSTITUTION_GROUPS,TAXONOMIES,SCHEMAS,DATA_TYPES
WHERE
ELEMENTS.TAXONOMY_ID = TAXONOMIES.RID AND ELEMENTS.ELEMENT_SCHEMA_ID = SCHEMAS.RID
AND ELEMENTS.DATA_TYPE_ID = DATA_TYPES.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = SUBSTITUTION_GROUPS.RID
AND ELEMENTS.SUBSTITUTION_GROUP_ID = 0