How do i get the Specflow scenario outline example data to a table - selenium

Is there any way to get the scenario context outline example values i mean all the values in to a table
Scenario Outline: Create a Matter
Given I enter "< parameter1 >"
Then I enter "<parameter2>"
Then I enter "<parameter3>"
Then I enter "<parameter4>"
Then review all the parameters entered above in this final step
Examples:
| parameter1 | Paramter2|Parameter3|Parameter4|....|parameter14|
| value |value2 |value3 |value4 |....|value14|
in the above scenario is there any way to get all the example values in step4 to a table
I know I can set ScenarioContext.Current[parameter1] = value in each step
In my case I have 14 parameters which are used in each step but in the final step i need to use all the 14 parameters
is there any way I get the example values in to table.
I don't want to break in to smaller scenario
like below
Scenario: breaking in to smaller chunks
Given I enter the following
| parameter1 | Paramter2|
| value |value2|

Here is something I use that may help. Andreas is the expert though on this stuff and he probably has a better idea. Since your format was less than ideal, I used a basic scenario.
Change it to a "Scenario" and Drop the "Scenario Outline".
The feature looks like this:
Scenario: Validate Shipping Fees
When the user enters the State then we can verify the city and shipping fee
| City | State | Shipping |
| Boulder | Colorado | 6.00 |
| Houston | Texas | 8.00 |
Add the Table.
public class ShippingTable
{
public string City { get; set; }
public string State { get; set; }
public string Shipping { get; set; }
}
Then in your step:
[When(#"the user enters the State then we can verify the city and shipping fee")]
public void WhenTheUserEnterTheStateThenWeCanVerifyTheCityAndShippingFee(Table table)
{
var CityState = table.CreateSet<ShippingTable>();
foreach (var row in CityState)
{
try
{
Pages.CheckoutPage.SelectState(row.State);
Pages.CheckoutPage.SelectCity(row.City);
var recdPrice = Pages.CheckoutPage.GetShippingPrice;
Assert.AreEqual(row.shipping, recdPrice);
}
catch (Exception)
{
throw new Exception("This is jacked up");
}
}
}

Related

How to get Google Dataflow to write to a BigQuery table name from the input data?

I'm new to Dataflow/Beam. I'm trying to write some data to BigQuery. I want the destination table name to be brought in from the previous stage a map entry keyed "table". But I couldn't find out how I pass this table name through the pipeline to BigQuery. Here's where I'm stuck.. any ideas what do to next?
pipeline
// ...
//////// I guess I shouldn't output TableRow here?
.apply("ToBQRow", ParDo.of(new DoFn<Map<String, String>, TableRow>() {
#ProcessElement
public void processElement(ProcessContext c) throws Exception {
////////// WHAT DO I DO WITH "table"?
String table = c.element().get("table");
TableRow row = new TableRow();
// ... set some records
c.output(row);
}
}))
.apply(BigQueryIO.writeTableRows().to(/* ///// WHAT DO I WRITE HERE?? */)
.withSchema(schema)
.withWriteDisposition(
BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
));
You can use DynamicDestinations for that.
As an example I create some dummy data and I'll use the last word as the key:
p.apply("Create Data", Create.of("this should go to table one",
"I would like to go to table one",
"please, table one",
"I prefer table two",
"Back to one",
"My fave is one",
"Rooting for two"))
.apply("Create Keys", ParDo.of(new DoFn<String, KV<String,String>>() {
#ProcessElement
public void processElement(ProcessContext c) {
String[] splitBySpaces = c.element().split(" ");
c.output(KV.of(splitBySpaces[splitBySpaces.length - 1],c.element()));
}
}))
and then with getDestination we control how to route each element to a different table according to the key and getTable to build the fully qualified table name (prepending the prefix). We could use getSchema if the different tables had different schemas. Finally, we control what to write in the table using withFormatFunction:
.apply(BigQueryIO.<KV<String, String>>write()
.to(new DynamicDestinations<KV<String, String>, String>() {
public String getDestination(ValueInSingleWindow<KV<String, String>> element) {
return element.getValue().getKey();
}
public TableDestination getTable(String name) {
String tableSpec = output + name;
return new TableDestination(tableSpec, "Table for type " + name);
}
public TableSchema getSchema(String schema) {
List<TableFieldSchema> fields = new ArrayList<>();
fields.add(new TableFieldSchema().setName("Text").setType("STRING"));
TableSchema ts = new TableSchema();
ts.setFields(fields);
return ts;
}
})
.withFormatFunction(new SerializableFunction<KV<String, String>, TableRow>() {
public TableRow apply(KV<String, String> row) {
TableRow tr = new TableRow();
tr.set("Text", row.getValue());
return tr;
}
})
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
To fully test this I created the following tables:
bq mk dynamic_key
bq mk -f dynamic_key.dynamic_one Text:STRING
bq mk -f dynamic_key.dynamic_two Text:STRING
And, after setting the $PROJECT, $BUCKET and $TABLE_PREFIX (in my case PROJECT_ID:dynamic_key.dynamic_) variables, I run the job with:
mvn -Pdataflow-runner compile -e exec:java \
-Dexec.mainClass=com.dataflow.samples.DynamicTableFromKey \
-Dexec.args="--project=$PROJECT \
--stagingLocation=gs://$BUCKET/staging/ \
--tempLocation=gs://$BUCKET/temp/ \
--output=$TABLE_PREFIX \
--runner=DataflowRunner"
We can verify that each element went to the correct table:
$ bq query "SELECT * FROM dynamic_key.dynamic_one"
+---------------------------------+
| Text |
+---------------------------------+
| please, table one |
| Back to one |
| My fave is one |
| this should go to table one |
| I would like to go to table one |
+---------------------------------+
$ bq query "SELECT * FROM dynamic_key.dynamic_two"
+--------------------+
| Text |
+--------------------+
| I prefer table two |
| Rooting for two |
+--------------------+
Full code here.

Get a particular string from an expression in a column in T-SQL

I have a column in my SQL Server database table which contains '|' (pipe) separated values.
Example:
'FirstName |testname| lastName | lastname | roll |ee097765 | 100 | end'
'FirstName |testname1| lastName | lastname1 | roll2 |ee0977652 | 1100 | end'.
I want to extract the marks only using T-SQL, where my output column will have only marks i.e. 100 only or 1100 subsequently. In Oracle we can use the
SUBSTRING_INDEX
function, but the same is not available in T-SQL.
Can anyone point me how to do this?
SUBSTRING_INDEX(SUBSTRING_INDEX(field, '|', 3), '|', -1)
declare #TEST table(val nvarchar(1000))
insert into #TEST
values ('FirstName |testname| lastName | lastname | roll |ee097765 | 100 | end'),
('FirstName |testname1| lastName | lastname1 | roll2 |ee0977652 | 1100 | end')
SELECT Value
FROM #TEST CROSS APPLY
Split(val,'|')
WHERE ISNUMERIC(Value) = 1
You just have to use a generic split function you'll find : https://codereview.stackexchange.com/questions/15125/sql-server-split-function
You could use SQLCLR function. There are some caveats in applying it to SQL Server. Anyway, here's one of the variants to find required values:
public partial class UserDefinedFunctions
{
[SqlFunction]
public static SqlString GetMarkPosition(SqlString sqlString)
{
// Assume there will be no result,
// so initialize return value to null string.
SqlString retVal = SqlString.Null;
// Extract C# string
string input = sqlString.Value;
// I use Regex Split method rather array Split method,
// since Regexe method handles spaces in elegant way.
string pattern = #"\s*\|\s*";
// Get array of values
string[] split = Regex.Split(input, pattern);
// The logic is the following:
// First, we find the marker's position in list.
// The sought value is one index less.
// This process is repeated for each marker.
// If no match is found for any marker,
// the function will just return empty string,
// as we initialized retVal variable.
foreach (string marker in new[] { "100", "1100" })
{
var list = new List<string>(split);
int index = list.IndexOf(marker);
if (index > 0)
{
retVal = new SqlString(list[index - 1]);
break;
}
}
return retVal;
}
}
In order to create this function, there are several steps you need to do.
If you're using SQL Server 2017, the security model has been changed (read, for example here and here), so Visual Studio won't help you in creating assembly on SQL Server's side - you'll have to do it manually.

Optionally copy values between EMF attributes

Question
Imagine following EMF-model based JFace-form
+-------------------------------------------------+
| My text field1 : __________________ |
+-------------------------------------------------+
| Inherit value from field1: [x] |
| My text field2 : __________________ |
+-------------------------------------------------+
Corresponding EMF-EClass
class Model {
String field1;
boolean inherit;
String field2;
}
Here the user should enter the value of the field1. Then he can
check the checkbox to copy the value from field1 to field2
uncheck the checkbox and enter a different value for the field2
My question:
How this kind of pattern should be properly implemented using JFace data-binding?
(The text field my be all kind of widgets including tables)
(I would like to leave the enabling/disabling field2 text box out of the scope of this question)
Dirty solution
IObservableValue value1Obs = EMFProperties.value(field1).observe(model);
IObservableValue value2Obs = EMFProperties.value(field2).observe(model);
IObservableValue inheritObs = EMFProperties.value(inherit).observe(model);
IObservableValue copyObs = new ComputedValue() {
#Override
protected Object calculate() {
if ((Boolean)inheritObs.getValue()) {
return value1Obs.getValue();
}
return value2Obs.getValue();
}
}
getBindingContext().bindValue(value2Obs, copyObs);
Don't use this
This works for simple attributes but don't work for lists/tables.
Also in case inherit=false I bind field2 to itself. This looks weird and may cause problems in the future.

org.springframework.jdbc.BadSqlGrammarException: bad SQL grammar

I am getting the following error in my code:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad
SQL grammar [insert into bulletins (date, name, subject, note, approved) values
(?, ?, ?, ?, ?)]; nested exception is com.mysql.jdbc.exceptions.MySQLSyntaxError
Exception: Unknown column 'date' in 'field list'
This line is in my Spring controller.
bulletinDAO.writeBulletin(bulletin);
The actual place in my DAO class where I'm trying to write using Hibernate.
public void writeBulletin(Bulletin bulletin) {
try {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(bulletin);
tx.commit();
} catch (Exception e) {
System.out.println(e.toString());
}
}
Here is my model class.
#Entity
#Table(name="login")
public class Bulletin {
#Id
#Column(name="id")
#GeneratedValue
private int id;
#Column(name="bulletin_date")
private String date;
#Column(name="name")
private String name;
#Column(name="subject")
private String subject;
#Column(name="note")
private String note;
#Column(name="approved")
private boolean approved;
// Getters and setters follow
}
Finally, here is the layout of the table.
+---------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| bulletin_date | varchar(10) | YES | | NULL | |
| name | varchar(30) | YES | | NULL | |
| subject | varchar(50) | YES | | NULL | |
| note | varchar(2500) | YES | | NULL | |
| approved | tinyint(1) | YES | | NULL | |
+---------------+---------------+------+-----+---------+----------------+
There must be something wrong with your getters and setters.
I would recommend changing the property name from date to bulletinDate. And then set & get it correctly...
#Column(name="bulletin_date")
private String bulletinDate;
public String getBulletinDate() {
return bulletinDate;
}
public void setBulletinDate(String bulletin_date) {
this.bulletinDate = bulletin_date;
}
Your issue is here
[insert into bulletins (date, name, subject, note, approved)]
Whereas you need bullletin_date.
From experience i needed to rebuild the project completely to ensure that right column name is referenced.
Clear your project cache and rebuild it.
Let me know how you go and i'll help further if it doesn't help.

Hibernate: Refrain update on Many-to-Many insert

Problem
I use hibernate to store data in an MySQL database. I now want to store a Company and one of its Branches.
The company:
#Entity
#Table(name="company")
public class Company {
#Id
#GeneratedValue
#Column(name="id")
private int id;
#Column(name="name")
private String name;
#ManyToMany(cascade = CascadeType.ALL)
#JoinTable(name="company_branch_join",
joinColumns={#JoinColumn(name="company_id")},
inverseJoinColumns={#JoinColumn(name="branch_id")})
private Set<CompanyBranch> branches;
// Getters and setters...
}
And the branch:
#Entity
#Table(name="company_branch")
public class CompanyBranch {
#Id
#GeneratedValue
#Column(name="id")
private int id;
#Column(name="branch")
private String branch;
#ManyToMany(mappedBy="branches", cascade = CascadeType.ALL)
private Set<Company> companies;
// Getters and setters...
}
Question
The code works and i can insert the data in the join table. The problem is the override policy regarding the branches. My branch table in the database is already filled with branches and its IDs so i don't want to modify the data. However on an company-insert the branches associated with the company get stored again and override the data with the same ID in the database. How can I prevent this behavior?
CompanyBranch cb1 = new CompanyBranch();
cb1.setId(1);
cb1.setBranch("Manufacturing");
CompanyBranch cb2 = new CompanyBranch();
cb2.setId(2);
cb2.setBranch("DONT-INSERT");
Company c = new Company();
c.setName("[Random-Company-Name]");
c.addBranch(cb1);
c.addBranch(cb2);
CompanyManager cm = new CompanyManagerImpl();
cm.saveCompany(c);
The branch table before execution looks like this:
| id | branch |
+----+----------------+
| 1 | Manufacturing |
| 2 | IT |
|... | ... |
The table should not change. But after execution it looks like this:
| id | branch |
+----+----------------+
| 1 | Manufacturing |
| 2 | DONT-INSERT |
|... | ... |
Instead of creating new branch instances with the new operator, retrieve a reference to them using EntityManager.getReference(), e.g.:
CompanyBranch cb1 = entityManager.getReference(CompanyBranch.class, 1);