Lisa Austin

Ranch Hand
+ Follow
since Jun 04, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Lisa Austin

Thank You guys so much!  This completely makes sense now.
1 month ago
Hi everyone,
This is all just for my learning.
So long story short is I'm trying to create a method that could be used from a utility class within my test automation.   The utility uses Selenium DevTools and can capture the request id from the Network tab of DevTools in Chrome.  This part is okay but I also want to pass an object name TestDataInfo from the class calling the method and update update it with the request id .



Devtools uses a lambda to call addListener https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/devtools/DevTools.html#addListener(org.openqa.selenium.devtools.Event,java.util.function.Consumer)  .  



So in the method it looks like this .




My question is , in order to use this method from another class file as a utility , I made it static but is there a way I pass the TestDataInfo from another class to this method and then use it in the Lambda ?   I'm receiving the message "Variable used in lambda expression should be final or effectively final"
I've tried a few ways and I'm not making this work.   I know how to create a new TestDataInfo as a final variable but then it complains that the variable is already initialized because it's passed to the method so I try giving different names but then line 18 doesn't see it .

Thanks for any help.





1 month ago

Carey Brown wrote:^[a-zA-Z][a-zA-Z0-9_]{7,29}$

The first part of the expression handles the first character leaving 7 - 29 left to match.

Don't use the '+'



Thank You!
2 months ago
I'm trying to get better with Regex and have worked on a HackerRank challenge but I notice what I came up with doesn't behave exactly as I thought it should.
The challenge's requirements are the following

  • 8 - 30 characters
  • Only alphanumeric and under scores allowed
  • First character is an alpha
  • Return valid if the name meets the requirements, invalid if it doesn't.


  • My regex I came up:


    The problem is if the name is exactly 8 it says it's invalid ( Samantha ) but at 9 characters (Samantha1) it's valid .  If a name has 31 characters it's valid but at 32 it's invalid .
    Name Lisa is invalid ( as expected ) but Lisa1234 is also invalid ( not expected ) where Lisa12345 is valid.

    So rather than 8,30 it acts like I'm using 9,31 and I know it's something I'm doing wrong but I can't figure out why and I want to understand.
    While I was trying to figure out other parts of my REGEX the values 8,30  was acting as I expected it should ( names with 8 characters were valid )


    2 months ago
    I didn't mean to hit submit yet

    My apologies in advance for the lousy title .  I've been learning Java by myself for quite some time but I still obliviously only understand the basics.  I only really been able to use it in a more professional atmosphere since May 2024 since learning it and I use it for automation so I want to get better.

    My current question is regarding

    3 months ago

    Tim Holloway wrote:No, Junit, at least, does NOT return anything from tests. If a test fails, it throws an Exception.

    I can see where it might facilitate testing for the method UNDER test to return a result, but I don;'t recommend doing so, partly because sooner or later someone is likely to mis-use it in production.

    Then again, going a "get" on a list doesn't normally cause UI effects, which is what the sample code seems to be expecting.  At a minimum, I'd expect to see the list-management code in a separate method from the UI-affecting code and tested seperately. Even if a higher-level method wsa used to mutually invoke them.

    Going to an even higher level, in Model/View/Controller terms, it gives me the impression that Model and Controller are both part of the same class and that's not really how MVC should be working. It's one reason why I take people to task when they call their JSF backing beans "Controllers". They aren't. They're Modes, which may have connexion to business logic, but their Controllers are located elsewhere.



    I'm not saying any of the methods I posted uses Junit.  We are moving from cucumber to Junit because from what I'm told want to use it in Gitlab's CICD pipeline to run these automation tests now.  These are just for testing and not code we are using in production.

    We do have the methods in different classes.  

    I'm just trying to understand if the modification the person made is consider best practice or doesn't really matter.  I wanted to say "Hey we should create a different method for what you want to do" but then I don't feel confident as to whether it mattered or not.
    6 months ago

    Campbell Ritchie wrote:Welcome back

    Do testing methods usually return a value? I may well be mistaken, but I would sooner stick to the void method and write another method to return a String.



    Hey Thanks!  My learning path has taken me from learning Java to being moved from backend stuff to front end automation testing so now I had to learn Selenium, and Cucumber but oh wait!  We don't want to use Cucumber anymore so now we are doing everything in just Junit .  Now I'm taking a class in REST Assured ...  Oiy.  LOL.  So I'm always a newbie I think.   No complaints .  At least I have the opportunity .

    The change made was to return the current URL and he's doing some validation there using junit .  I think MY instinct would to create a new method that would return the string and leave the existing method alone but I wasn't sure if my instincts were right since by returning the current URL value doesn't hurt anything .
    6 months ago
    I still am learning and would like to know what would be considered better here .  This is all automation test code.   I did a code review and the person changed a few method's signature from void to String and added a String value to be returned.  There are four other methods which use this one method and would not do anything with the returned String value so I guess he did this for his one method which does use the String value.

    So the method WAS


    The method NOW



    So the four methods which calls the method selectFirstCard() doesn't do anything with a String value so it's not breaking anything but I'm just curious if this really is the best way to handle a situation where you need what the method does but you need it to return something rather than the method to just do something?    Existing method does an action , you need that action but you also need it to return something.  So rather than create a new method that does the nearly identical steps AND returning a value doesn't break anything, so just change the method's signature and have it return what you want.


    Example of a method that was using this



    6 months ago
    Thanks for the suggestion!  I have on my ToDo to take a cucumber course so this helps me out a lot for a suggested course.   I will do that.
    1 year ago

    Junilu Lacar wrote:You can also use a data table with word and URL in your test specification (the Gherkin part) -- this allows you to parameterize at the specification level instead of in the step definition as I showed earlier.

    Bottom line, if you find yourself writing multiple conditionals in a test or step definition, then think about changing to a data-driven parameterized test instead.



    Thank you for all your help and advice. I'm going to try and implement the changes you suggested regarding the data table .  The steps are written by our product owners on a Jira xray test and then we implement the Gherkin , step defs etc.  So I try and follow what the product owners had for the xray tests.

    So for one of the tests it's actually like

    Scenario:  Verify user should navigate to Security page upon Clicking Security hyperlink
      When  User confirms they see the Security hyperlink
      And  User clicks on the Security hyperlink
      Then User has landed on the Security page


    So if I understand correctly and  write it up the way you suggest ,


    Scenario:  Verify user should navigate to Security page upon Clicking Security hyperlink
      When  User confirms they see the Security hyperlink
      Then User navigates to the Security page

    Is that right?  


    1 year ago
    Thank You so much!  I ALWAYS appreciate the help.  
    1 year ago
    Is there a better way than using Java's switch case to handle this scenario?  

    I'm using the Cucumber framework and creating some test cases to verify whether specific links exists on a webpage.  

    For starters right now,  I'm verifying if I can find the link, if I can click on the link and after I click on the link, whether the page loads, what the webpage title is, and what the URL is.   In my example code below ( just an example ) each of the switch cases is handling an assert statement which verifies what the page's URL value is.    It gets the job done but I'm just curious if I can do better?

    Thank You in advance.  


    Example code

    1 year ago

    Campbell Ritchie wrote:
    Yes; it's good to see you back


    Thank you very much Ritchie for the advice.  I do not know why I was completely blind to the fact that I was extending Throwable vs. what the instructor was doing.  Great information as always.  You have always been a great instructor and I'm lucky there are people like you out there to help people like me.
    1 year ago
    Hi there!  It's been a while .  

    Could someone please explain to me why my Intellij IDE flagged what I did as an error when I was copying what the instructor did in her own code?


    I'm trying to learn Spock and I'm following a Youtube video here https://www.youtube.com/watch?v=i5Qu3qYOfsM .

    She provides her whole code set in git but I'm following along writing the code out myself and only using her code in case I get stuck.

    In the video the instructor has a class "Polygon"  and a "TooFewSidesException" class under package com.mechanitis.demo.spock

    Her Polygon constructor has the "throw new TooFewSidesException" .   Full code is after my question but this is a snippet of what I'm talking about.




    MY intellij didn't like it when I followed her example ( didn't like = red light bulb and squiggly line ) .  I took it's suggestion and it added the "throws TooFewSidesException" to the constructor.   Any idea why my intellij insists on the method having  "throws TooFewSidesException" when her code is just fine without it?

    My Java is 11 ( 11.0.6_10 )  and her's is 11.0.9  if that makes the difference.    Thank You!










    Instructor's Polygon class.








    Instructor's TooFewSidesException class






    MY Polygon Class





    MY TooFewSidesException class ( just a start )


    1 year ago

    Matthew Bendford wrote:Another common type of attack vector should also get mentioned: SQL injection.
    It's pretty much the same idea: Unfortunately many beginner level tutorials, teachers and books commonly use simple string concatination to piece together sql queries. This works with provided sample data but already breaks on something common as a forum. The english language commonly uses both types of quote-marks: The single quote ' and the double quote ". If you now try to store this very line in a database one of them is used as delimiter character - and when encountered unexpected means end of input string which corrupts the sql query and the best case is an error returned from the database.
    If you manipulate an input to a vulnerable qurry in a specific way you can get any sort of result from wiping the database over free access to leak its content.
    So to get around this you have to sanitize the user input and properly build your query. One part of it is to use PreparedStatements. The query is done with placeholder characters (usually the question mark ?) and the values are filled with setters. This is also a way of type safety: If you expect a numerical value but you get a letter or other symbol the setter alrwady fail fast building the sql query before anything is ever send to the database.
    An additional way of user input sanitization is limit the input characters. For a name there's a reason for a single dash - but a double dash -- (the sql comment marker to ignore the rest of the query srring) doesn't make sense. This can be a simple typo - but can also be an attacker trying to forge a bad query. You should reject such a name even before building the query as the input already looks too suspicious.
    This list goes one for quite some lines. Atracker found all crazy issues over the decades like what's called a reverse shell abusing a bug in the apache web server or the recent log4j (which I became a victim of). The overall gist is: NEVER trust the user input. Always pre-check and validate and sanitize it and don't use simple string concatination if other methods are available like varargs methods for execute sub-processes, prepared statements for sql or simple I/O like a file by using a languages internal api rather then rely on a potential flawed shell command.



    Thank You!  Yes this was in another of their lessons.  Thank you though for this info.  
    2 years ago