How to use a text file in Velocity - velocity

I have a text file with name data.txt which includes Customer's details. I need to send a Msg to each Customer using apache velocity. My file look like this
enter code here
First_Name, City, ...
Rakesh, Hyderabad,...
Jack, berlin,...
...., ...., ...
like this 10000 records are their..
i don't know apache velocity very much..
i am unable to load my file in velocity.
my java file
public static void main(String[] args) throws Exception {
Velocity.init();
Template t = Velocity.getTemplate("./src/VMDemo.vm");
VelocityContext ctx = new VelocityContext();
Writer writer = new StringWriter();
t.merge(ctx, writer);
System.out.println(writer);
VM file
#if ($City == "Hyderabad")
Hi $first_Name welcome to Hyderabad.
#elseif ($City == "Berling")
Hi $First_Name welcome to Berlin
#elseif ($City == "Mumbai")
Hi $First_Name welcome to Mumbai
#else
Please contact Us
#end
enter code here
the output should be like this..
Hi Rakesh welcome to Hyderabad.
Someone please suggest me how to load data and use in velocity.
If Person belongs to some city then the name should be taken dynamically from a file.
Please Someone help me out with this.. just help me including my file in velocity.

Related

How to take runtime input in selenium while automation testing?

I'm trying to take data from user at run time while automating a Webapplication. I have searched a lot but I couldn't find anything. I have tried this method. (code mentioned below)
Scanner scanner_user = new Scanner(System.in);
System.out.println("Enter your Email or Phone : ");
String user = scanner_user.nextLine();
System.out.println("our otp is " + user.toString());
but It doesn't work . it ask to enter data in console but it says read only view. please help me how can I take data at runtime.
You can use the below in this scenario user is passing the password manually through console.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String password;
System.out.println("Please Enter the user password :: ");
password= br.readLine();
driver.findElement(By.id("pwd")).sendKeys("password");

The primitive type int of OutputType does not have a field FILE while using screenshot code

hi i am using this code for screen shot but i am getting above error please help me if some one can thank you enter image description here
public static void takeScreen(String FilePath, String Value) {
File ts=(File) ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(ts,new File(FilePath));
}
I got the same problem and was able to resolved by adding below to OutputType.FILE
File ts=(File) ((TakesScreenshot)driver).getScreenshotAs(org.openqa.selenium.OutputType.FILE);
FileUtils.copyFile(ts,new File(FilePath));

How do I make a Register and Login example in Java and store the registration records without using database languages?

I'm trying to make a project which includes the Registration Form and Login Form that the program will check if the user is registered or not and will log in if the user is registered.
I'm using FileWriter to store data like usernames and passwords "separately"
try {
FileWriter fw = new FileWriter("C:\\Users\\Krayst\\Documents\\NetBeansProjects\\Cashiering and Sales System\\src\\"+fName+"\\Full Name.txt", false);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw);
out.print(fName);
out.close();
bw.close();
fw.close();
} catch(IOException no) {
System.out.println("Error processing data!");
}
And by the way, I created a folder to store specific data like The Full Name of the registered user so the data can be organized well
File regUser = new File("C:\\Users\\Krayst\\Documents\\NetBeansProjects\\Cashiering and Sales System\\src\\" + name);
if (!regUser.exists()) {
if (regUser.mkdir()) {
System.out.println("User Folder created");
} else {
System.out.println("User Folder not created");
}
}
The problem is I cannot access to these files because it has been "newly" created and written by the program so if I try to access its directory, it doesn't work. Plus, it has to be accessed to the other class because I created another class which is the Login JFrame and I'm using Netbeans IDE (The Registration Form is also a JFrame though). All I wanted to do is to read these Records (registration files) from another JFrame class so it can check in the Login Form whether the user is already registered or not.
I am sorry if I made some confusing statements and questions but I can accept any clarifications.
I'm a student and a beginner of programming so I would appreciate all the help from everyone. :)

input external parameters java fx

I need to run a program from the command line. There should be two inputs. username and password.
My problem is that I cannot find a clean easy way to do it. Either my syntax in the CMD console is bad or my code...
My code looks like this:
stage.setScene(scene);
stage.setTitle("Bmi Calculator");
stage.setResizable(false);
final Parameters params = getParameters();
final List<String> parameters = params.getRaw();
BMI.username = parameters.get(0);
BMI.password = parameters.get(1);
stage.show();
The problem is catching the input. I'm trying to set the variables from the main class to the two public static variables in my contoller class.
My CMD input would look like this:
Start BmiCalculator.jar e:\Desktop\BmiCalculator.jar username password
// Alex

How to create WritebleBitmap from a resource image with C++ for Windows Metro app?

I can easily create a BitmapImage from a resource JPG image file using the following code...
Windows::Foundation::Uri^ uri = ref new Windows::Foundation::Uri(L"ms-appx:///Hippo.JPG");
Imaging::BitmapImage^ image = ref new Imaging::BitmapImage(uri);
But WritableBitmap does not take an Uri. I see a SetSource method, but that needs a IRandomaccessStream and not an Uri. And I have no clue how to create one from a JPG file. I searched the net over and over again, but could not find a straight forward answer. Any help would be greatly appreciated.
I want something like this...
Windows::UI::Xaml::Media::Imaging::WriteableBitmap image = ref new Windows::UI::Xaml::Media::Imaging::WriteableBitmap();
image->SetSource(somehowGetRandomAccessStreamFromUri);
But, how do I get the IRandomaccessStream instance from a uri? I started working on C++ Metro app only today, so might be wrong, but I find it to be overly complicated with too much of onion peeling.
In C# you would do something like
var storageFile = await Package.Current.InstalledLocation.GetFileAsync(relativePath.Replace('/', '\\'));
var stream = await storageFile.OpenReadAsync();
var wb = new WriteableBitmap(1, 1);
wb.SetSource(stream);
I think in C++/CX you would do something like this:
#include <ppl.h>
#include <ppltasks.h>
...
Concurrency::task<Windows::Storage::StorageFile^> getFileTask
(Package::Current->InstalledLocation->GetFileAsync(L"Assets\\MyImage.jpg"));
auto getStreamTask = getFileTask.then(
[] (Windows::Storage::StorageFile ^storageFile)
{
return storageFile->OpenReadAsync();
});
getStreamTask.then(
[] (Windows::Storage::Streams::IRandomAccessStreamWithContentType^ stream)
{
auto wb = ref new Windows::UI::Xaml::Media::Imaging::WriteableBitmap(1, 1);
wb->SetSource(stream);
});