Instead of having something like this:
#Given("^I have (\d+) cukes in my belly$")
public void i_have_cukes_in_my_belly(int cukes) throws Throwable {
Can we write the definition in this style below? The regex hurts my eyes.
#Given("I have $number cukes in my belly")
public void i_have_cukes_in_my_belly((Integer) cukes) throws Throwable {
Short answer: no you should do it
Long Answer:
no, because
as ar3s stated you woult lose your type safety for the int parameter
the missing "^" and "$" would allow a possible missmatch: "OtherText I have 10 cukes in my belly OtherText" would also be matched, because "^" and "$" mark the beginning and the end of the matching text
Related
public void iclickontemplatetab(){
SeleniumDriver.getDriver().findElement(By.xpath("//*[#id=\"global_nav_sidebar\"]/div/div[2]/nav/ul/li[4]/a")).click();
}
public void iclickonanalyticstab(){
SeleniumDriver.getDriver().findElement(By.xpath("//*[#id=\"global_nav_sidebar\"]/div/div[2]/nav/ul/li[6]/a")).click();
}
Try adding a wait (Implicit or explicit) if you are doing some actions before revisiting the elements for second time
public void iclickontemplatetab(){
SeleniumDriver.getDriver().findElement(By.xpath("....")).click();
}
Avoid using copy paste Xpaths. Instead use manual xpaths. Like: //tagname[#attribute=’Value‘]
To make sure this doesn't get closed, read this. This isn't a duplicate post because the only other user input setter is in C or c something and if not that it's for a completly different application. How can I set up my setWord method to use user input and not be null. My current code gives off a null pointer because the variable is null, but I can't find out a viable way to set it's value using user input. Current code: Subclass:
package hangman;
public class Hangman {
private String word;
public void setWord(String word) {
this.word = toString();
}
public String getWord() {
return this.word;
}
#Override
public String toString() {
System.out.println("Enter secret word: ");
return (this.getWord());
}
}
Main
public static void main(String[] args) {
Hangman hangman = new Hangman();
hangman.setWord();
String secretWord = hangman.getWord();
StringBuilder b = new StringBuilder(secretWord.length());
}
Again, the issue is that I can't find a way to set the private String "word" to user input without it ending up being null. Please dont mark this as duplicate I already looked at the generic cookie cutter nullpointerexception threads but haven't helped me at all. I've been stuck on this and it's my last part of my program. The null pointer is always at the stringbuilder, which suggests that secretWord is null.
Think about it: where do you ever set the word? setWord assigns the return of toString, which returns the result of getWord, but getWord just returns what this.word already was! Nowhere do you ever set a word, so it's never initialized! You just set this.word to what it was originally, which was null. This causes an NPE when you call secretWord.length(), since secretWord is null.
You have another problem, which I'm assuming is a typo here, where your call to setWord in your main isn't given an argument. That's illegal and creates an error of its own, so it should never reach the StringBuilder line.
Change setWord to:
public void setWord(String word) {
this.word = word; ; Set it to its argument
}
Then call it with a word as the argument:
hangman.setWord("Word");
Originally I had a toString which served no functional purpose. And the setWord method required a parameter which I didn't have so to fix it I replaced the setWord code with this
public void setWord() {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the secret word: (Under 7 letters)");
this.word = scan.nextLine();
this.word = word;
}
When I use the IDEA, type the if/for/while, the parentheses will auto added.But CLion will not auto complete.
IDEA
CLion
How to solve this problem?
You need to use complete statement (Ctrl+Shift+Enter).
void foo() {
if|<Ctrl+Shift+Enter>
}
generates
void foo() {
if (true|<Ctrl+Shift+Enter>) {
}
}
one more complete moves you into the block:
void foo() {
if (true) {
|
}
}
It can be found in Settings/Editor/General/Smart Keys (Or just go to Help-> Find -> Smart Keys)
There you have an option to check Home, End (on blank line), Insert pair bracket, etc. Check Insert pair bracket. This should do it.
Anyone know of a way of getting rid of the "empty block should be documented" warning in generated files when using ANTLR. I know I can disable the warning in Eclipse but I would like to keep it enabled and I like having a clean compile.
PathBaseListener.java
#Override public void enterPath(#NotNull PathParser.PathContext ctx) { }
So I think, you have to insert a command. E.g.:
#Override
public void enterPath(#NotNull PathParser.PathContext ctx){
/* not implemented */
}
I am writing a simple login form in JavaFX for which I am writing a test program in TestFX. My TestFX script automatically types the credentials in the textfields and clicks the login button and it works fine further.
But when I want the script to type credentials which contain underscore, it doesn't type the underscore and types until the underscore comes. I have used backslash before underscore but it didn't help me.
Below is a screenshot of my login page.
Below is my test script which works fine when I give string without an underscore.
#Test
public void invalidCredentialsShouldNotLogin()
{
controller.click("#username").type("invalid");
controller.click("#password").type("invalid");
controller.click("#button");
verifyThat("#welcome", hasText("Login failed"));
}
And this is the script which tries to type a string which contains underscore in it and does not work as intended, and gives exception as invalid key code.
#Test
public void invalidCredentialsShouldNotLogin()
{
controller.click("#username").type("user_name");
controller.click("#password").type("invalid");
controller.click("#button");
verifyThat("#welcome", hasText("Login failed"));
}
This is the output of the above code.
The same thing happens when I use colon in place of underscore.
Please help me fix this. If you require any more information, please tell me. Thanks
I have got the answer of this question. Actually every special character like underscore or colon has a keycode associated with it. We have to use that keycode to type in the TextField using TestFX script.
In the question above, I wanted to type underscore. Usually when we type underscore, we press two keys together i.e. shift and hyphen (-). Same way we will use the keycodes of these two keys to type underscore using TestFX script.
Below is the code that worked for me and typed underscore in the TextField.
#Test
public void enterCredentialsWithUnderscore()
{
TextField usernameField = (TextField)GuiTest.find("#username");
if(username.indexOf("_") != -1)
{
String[] tokens = username.split("_");
for(int i=0; i<tokens.length; i++)
{
if (i == 0)
controller.click(usernameField).type(tokens[i]);
else
controller.push(KeyCode.SHIFT, KeyCode.MINUS).type(tokens[i]);
}
}
}
KeyCode.MINUS is keycode for hyphen key. And push(KeyCode.SHIFT, KeyCode.MINUS) method pushes the both buttons together thus typing underscore.
Below is a screenshot of the output I received.
Thanks to all.