Running cucumber with bdd in eclipse - java

I am having problem running this cucumber projects belows. It showing errors on line 7, 8, 20 and 32.
package stepDefinition;
import cucumber.api.java.en.Given;
public class aptitudeTest {
#Given ("I have successfully ([^\"]*)")
public void I have (String str)
{
if (str.equals("registered"))
{
System.out.println("registered Automation");
}
{
System.out.println("unregistered Automation");
}
}
#When ("I enter my valid ([^\"]*)")
public void I enter (String str)
{
if (str.equals("credentials"))
{
System.out.println("credentials Automation");
}
{
System.out.println("details Automation");
}
}
#Then ("I should see the welcome ([^\"]*) him")
public void I should (String str)
{
if (str.equals("welcome"))
{
System.out.println("welcome to your account");
}
{
System.out.println("please enter the correct credential");
}
}
}
Below is the Feature File
Scenario:I should see a message when i successfully logged in
Given I have successfully registered
When I enter my valid credentials
Then I should see the welcome message

There are many 2 issues with the feature file and how the Given, When & Then are used.
The method name should not have any spaces.
If you're passing the argument in to the method, it should be in quotes.
ex. I have successfully registered should be as 'I have successfully "registered"'. Also the corresponding method should be annotated as "I have successfully \"([^\"]*)\" - You should have an escape character there. The registered will be the string that's passed.

Related

Validation is not working if the account got created or not while testing in Selenium

After answers given by Anand and Prophet, I made the changes in the code but now it is not validating the test results whether the account got created or not. Ideally, it should validate whether after giving all the required information account got created or not. I am not sure where it went wrong please help me on the same.
package Seleniumtesting;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Selenium {
ChromeDriver driver;
String url ="https://login.mailchimp.com/signup/";
public void invokeBrowser() {
try {
System.setProperty("webdriver.chrome.driver","C:\\Users\\hp\\Desktop\\Selenium\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
TimeUnit.SECONDS.sleep(2);
driver.get(url);
String urlFromWebpage = driver.getCurrentUrl();
if(urlFromWebpage.equals("https://login.mailchimp.com/signup/")) {
System.out.println("PASS");
}
else {
System.out.println("FAIL");
}
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
public void signup(){
try {
WebElement createAccountHeading = driver.findElement(By.xpath("//span[text()='Create an account or ']"));
if(createAccountHeading.isDisplayed()) {
System.out.println("PASS");
}else
System.out.println("FAIL");
driver.findElement(By.name("email")).sendKeys("Testvina12435#gmail.com");
driver.findElement(By.name("username")).sendKeys("Testvina1243");
driver.findElement(By.name("password")).sendKeys("Test123#");
TimeUnit.SECONDS.sleep(2);
driver.findElement(By.name("marketing_newsletter")).click();
TimeUnit.SECONDS.sleep(2);
//driver.findElement(By.xpath("//button[#id='create-account']")).click();
driver.findElement(By.xpath("//*[#id=\"create-account\"]")).click();
TimeUnit.SECONDS.sleep(2);
String u = driver.getCurrentUrl();
System.out.println("URL: "+u);
/*if(u.equalsIgnoreCase("https://login.mailchimp.com/signup/success/"))
{
System.out.println("PASS !! Account created successfully");
}
else
{
System.out.println("FAIL !! It might have not met the criteria");
}*/
driver.close();
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args) {
Selenium mc = new Selenium();
mc.invokeBrowser();
mc.signup();
}
}
This you can use for Sign up:
driver.find_element(By. ID, "create-account").click()
The caveat is that it gets enabled only when the password criteria is met with, which for mailchimp is at least (as per the website) : 1 lower character, 1 upper character, 1 number, 1 special character, and minimum password length is 8.
I see you used your password as 'Test123' which would not enable the button, as the set criteria is not met. Please check the password rules given just below the password input box of the website.
UPDATE:
Per your latest comment, I am updating here.
I see that when I tested, it redirects to another page where it asks for email confirmation.
https://login.mailchimp.com/signup/success/?username=Test1243&userId=168758830&loginId=181489470
Now, there is /success/ in it. And I suppose you are using this page to assert that your act was successful; in which case, I would say that you used .equals in your code, which fails it as there is more to the url than you are looking for, so it should not be .equals, but it should something be like .contains or something like that (I do not know what Java uses, so please search for that equivalent keyword)
UPDATE (Java code edit of #vicky per request)
public void signup(){
try {
WebElement createAccountHeading = driver.findElement(By.xpath("//span[text()='Create an account or ']"));
if(createAccountHeading.isDisplayed()) {
System.out.println("PASS");
}else
System.out.println("FAIL");
driver.findElement(By.name("email")).sendKeys("Testvina12435#gmail.com");
driver.findElement(By.name("username")).sendKeys("Testvina1243");
driver.findElement(By.name("password")).sendKeys("Test123#");
TimeUnit.SECONDS.sleep(2);
// code edit by #anandgautam
driver.findElement(By.xpath("//div[#id='onetrust-close-btn-container")).click();
TimeUnit.SECONDS.sleep(1);
driver.findElement(By.name("marketing_newsletter")).click();
TimeUnit.SECONDS.sleep(5);
// end of code edit by #anandgautam
//driver.findElement(By.xpath("//button[#id='create-account']")).click();
driver.findElement(By.xpath("//*[#id=\"create-account\"]")).click();
TimeUnit.SECONDS.sleep(2);
String u = driver.getCurrentUrl();
System.out.println("URL: "+u);
/*if(u.equalsIgnoreCase("https://login.mailchimp.com/signup/success/"))
{
System.out.println("PASS !! Account created successfully");
}
else
{
System.out.println("FAIL !! It might have not met the criteria");
}*/
driver.close();
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
Your password is missing a special character. The Sign Up button not appearing on that page until you filled all the fields with valid data.
So if you change your password from Test123 to f.e. Test123$ you will be able to see, locate and click the Sing Up button with this code:
driver.findElement(By.xpath("//button[#id='create-account']")).click();

Is there a way to catch a players chat input without an AsyncPlayerChatEvent?

I'm once again writing another Banksystem plugin, but this time with an ATM. I'm trying to figure out how to get a players chat-input after clicking on the option, to prevent clicking 100 times to deposit 50,000 Dollars on the bank-account.
I'm writing this Plugin with Paper-Spigot 1.14.4 and I've tried following steps:
A AsyncPlayerChatEvent as a separate Class, which activates only when I register the Event with the Pluginmanager:
Bukkit.getPluginManager().registerEvents(new ChatListener(), Main.getPlugin());
Creating a private AsyncPlayerChatEvent variable e with get- and set-method, and calling it in the method when I need it.
String input = getChat().getMessage();
My current chatListener() Method:
public void chatListener(Inventory inv, Player pl) {
pl.closeInventory();
pl.sendMessage("§6Please enter your amount:");
String input = getChat().getMessage();
if(input.matches("[0-9]+")) {
pl.openInventory(inv);
inv.setItem(0, new ItemStack(Material.AIR));
inv.setItem(0, CustomHeads.customHead(CustomHeads.BITCOIN,
input));
} else {
pl.sendMessage("§cPlease enter only numeric characters!");
}
}
AsyncPlayerChatEvent get-method:
public AsyncPlayerChatEvent getChat() {
return chat;
}
I expect the message of the player to be saved inside the input variable, after the message "Please enter your amount:" appears.
When I create a System.out.println(input), the console shows nothing, including neither errors nor any warnings.
Create an AsyncPlayerChatEvent and a public static ArrayList.
ExampleChatEvent.class
public static ArrayList<Player> waitingForAmountPlayers = new ArrayList<>();
public void onChat(AsyncPlayerChatEvent e) {
Player p = e.getPlayer();
if (waitingForAmountPlayers.indexOf(p) != -1) {
//
// YOUR CODE
//
waitingForAmountPlayers.remove(p);
}
}
Don't forget to add the player to waitingForAmountPlayers when you want to type the player the amount in the chat (ExampleChatEvent.waitingForAmountPlayers.add(p);).

Not getting sessin value in vaadin framework

Not getting sessin value in vaadin framework
Used below :
private void setCurrentUsername(String username){
VaadinService.getCurrentRequest().getWrappedSession().setAttribute("LOGGED_IN_AS_USER",username);
userSubMenu.setText(username);
}
public static String getCurrentUsername() {
//log.info("User:::::::::::::::::" + (String) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("LOGGED_IN_AS_USER"));
return (String) VaadinService.getCurrentRequest().getWrappedSession().getAttribute("LOGGED_IN_AS_USER");
}
getting value as null when flow going to other class
You could try using VaadinSession.getCurrent().getSession() instead?
iIf you are using this for a user interface i.e a user logging in. Don't forget that when your app first builds/ when the user first enters it they will of course have a null value(including any sub pages).
Try adding a ViewChangeListener to the page that the user now enters (apologies for any errors in coding i'm not currently able to gain access to my machine) into:
#Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
this.username = VaadinSession.getCurrent().getAttribute("LOGGED_IN_AS_USER");
}

Discord java bot verify user by name

in my current Discord (java) bot im trying to apply a command to a user name. how can i make sure this is an actual existing user ?
in psuedo code:
if User "A" exists {
User "A" types something at all
send message "hello"+ user "A"
}
else
{
this is no valid user;
}
i can't figure out how to write the 'check if exist code'.
This is from JDA-Utilities which is a really useful tool when building discord bots.
import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
public class Example extends Command {
public Example() {
this.name = "'isBot";
this.help = "Tells you if the user is a bot!";
}
#Override
protected void execute(CommandEvent e) {
if (e.getAuthor().isBot()) {
e.reply("Hey you're not a person!!");
} else {
e.reply("Hey " + e.getAuthor().getName() + ", you're not a bot!");
}
}
}

Parse (Java for Android) login returns Object Not Found

I'm trying to login using Parse for android.
If I enter the correct username and password, I log in successfully.
But when I use a wrong password or username, I always get error 101: object not found.
Here's the code (Notice "username" and "password" are EditText):
private void doLogin() {
if (!validate()) { // IF VALIDATION FAILS, DO NOTHING
return;
} // ELSE...
String name = email.getText().toString();
String pass = password.getText().toString();
ParseUser.logInInBackground(name, pass, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
goToMainActivity(user.getUsername());
} else {
handleParseError(e);
}
}
});
}
Thanks for your help.
Update: Parse does not have means to check if there was an incorrect login field. Hence they use the general 101: Object Not Found error to catch it. Reference: https://parse.com/docs/android/api/com/parse/ParseException.html
Previous stackoverflow link: Parse : invalid username, password
If you want your app to respond to an incorrect login, just replace the line handleParseError(e); with code to handle it.
For example, if you want a message box to show up, place that code there. If you do not want to do anything, comment out that line. Not sure what else you are looking for...
I would suggest replacing it with a Toast message

Categories

Resources