Test discovery error, please check the configuration settings||Resolved

 

Test discovery error, please check the configuration settings Resolved

Issue -

When we use pytest in our python automation project we sometime see the error  message saying "Test discovery error, please check the configuration settings for the tests", now the issue is we will not get to see the exact issue as shown in below snippet.


Reason for issue-

-This issue comes up due to some or other error in your code in any of the step definition or test file. 
- Other reason could be that you missed to enable to pytest module in your project.


Resolution for issue -1

you need to find the list of error in your code, now to find the errors  you can either use Problems tab present under the terminal of Visual studio or you can go to output tab and select output as python test log as shown in below image.




Resolution for issue -2

you need to find go inside the .vscode folder and select settings.json file and enable the pytest framework for the project.

{
    "python.testing.pytestArgs": [
        "."
    ],
    "python.testing.unittestEnabled"false,
    "python.testing.nosetestsEnabled"false,
    "python.testing.pytestEnabled"true,
    "python.pythonPath""C:\\Users\\.virtualenvs\\pyt-uF11lD_o\\Scripts\\python.exe"
}


Thanks you please let me know if it helps..

What are common Rest authentication methods?


What are common Rest authentication methods ?

Basic Authentication-

This is the most straightforward method. the sender places a username: password into the request header. The username and password are encoded, encoding technique that converts the username and password into a set of 64 characters to ensure safe transmission. e.g. :Authorization: Basic bG9sOnNlY3VyZQ==

Bearer authentication- 

Also called ‘token’ authentication. Token - a cryptic string, usually generated by the server in response to a login request.e.g. Authorization: Bearer <token>

API Keys-

Generate a key [unique value assigned to each first-time user] >> then use this key the next time you try to access the system. e.g. Authorization: Apikey 1234567890abcdef

OAuth- 

OAuth is technically an method of both authentication and authorization. In this approach, user logs into a system. That system will then request authentication, usually in the form of a token. The user will then forward this request to an authentication server. From here, the token is provided to the user, and then to the requester. Such a token can then be checked at any time independently of the user by the requester for validation and can be used over time with strictly limited scope and age of validity.

Explain implicit and explicit wait?

 


Explain implicit and explicit wait?

    • Implicit Wait: 
      • During Implicit wait if the Web Driver cannot find it immediately because of its availability, the WebDriver will wait for mentioned time and it will not try to find the element again during the specified time period. 
      • Once the specified time is over, it will try to search the element once again the last time before throwing exception. The default setting is zero. 
      • Once we set a time, the Web Driver waits for the period of the WebDriver object instance.
    • Explicit Wait: 

      • There can be instance when a particular element takes more than a minute to load. In that case you definitely not like to set a huge time to Implicit wait, as if you do this your browser will going to wait for the same time for every element.
      • To avoid that situation you can simply put a separate time on the required element only. By following this your browser implicit wait time would be short for every element and it would be large for specific element.
      • Please find the below code snippet for the same.
    =================================================

            WebDriver driver = new FirefoxDriver();
            driver.get("http://somedomain/url_that_delays_loading");
            WebElement myDynamicElement = (new                             WebDriverWait(driver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));

    ================================================

    Understand the HTML DOM Structure

     


    Understand the HTML DOM Structure

      • DOM stands for Document object model.
      • Webpage is consist of multiple web elements.
      • webpages are written in HTML language.
      • These web elements present in the webpage are arranged in Document object model which is created by the bowser.
      • The DOM presents an HTML document as a tree structure as shown below.

      • We (Developer & QA) can perform multiple operations like 
          • Build Document
          • Navigate there structure
          • Add element
          • update element
          • remove element
      • Now these elements are basically combination of tags and attributes.

          • Few Examples of tags
            • Input
            • Div
            • Iframe
            • Anchor
            • html 
            • img
            • body

          • Few Examples of attributes
            • ID
            • Name
            • Type
            • classname
            • value


      • Now to locate an element in selenium we generally use tags and attributes.

      What is WebElement


      As the name suggested WebElement refers to the elements present on the webpage like buttons, textboxes, links, images, radiobutton etc.

      In Selenium WebElement is an interface which is use to handle these webElements using below methods.

      Mostly frequently used methods 

      findElement()

      findElements()

      click()

      clear()

      getText()

      getTagName()

      getAttribute()

      isEnabled()

      isDisplayed()

      isSelected()

      sendkeys()

      Different components in Rest API header?

       


      Different components in Rest API header?

      Headers are mostly classified as request and response headers - property-value pairs that are separated by a colon. Set the request headers when you are sending the request > Set the assertion against the response headers. Some header types,


      Authorization: Carries credentials containing the authentication information of the client for the resource being requested.

      • Content-Type: The MIME type of the request or response. E.g., text/html or text/JSON.

      • Date: The date and time of the request or response.

      • Accept: Informs the server about the types of data that can be sent back. E.g., Accept-Charset: which character sets are acceptable by the client.

      • WWW-Authenticate: Sent by the server if it needs a form of authentication before it can respond with the actual resource being requested. Often sent along with a response code of 401, which means ‘unauthorized’.

      • Cache-Control: Cache policy defined by the server for this response, a cached response can be stored by the client and re-used till the time defined by the Cache-Control header.

      • Expires: Response header indicating the time after which the response is considered stale.

      • Set-Cookie: Send cookies from the server to the user-agent.

      How to fix "no Appenders could be found for logger"

       


      LOG4J: no Appenders could be found for logger

      I        Issue : Getting warning message as below

      =============================================================

                  log4j:WARN No appenders could be found for logger (LoggerCode.UnderstandLogger).

                  log4j:WARN Please initialize the log4j system properly.

                   log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

      =============================================================                    

                     Fix :    

      Ø           To resolve above issue we need to implement Logging in our framework or class.

      Ø              Define the root logger properly based on the levels and syntax given below

      l            log4j.rootLogger = FATAL, FILE

      ==================================================================

      1.       So basically Log4j has three major components

      Ø  Loggers

      Ø  Appenders / Handlers

      Ø  Layouts / Formatters 

      2.       All above mentioned components are basically work together to enable dev/QA to log message accordingly based on the message type and levels also formatting and location where we can see these logs.

      3.       Advantage of using logger over plain System.out.println is to categories the logging based on some specific criteria/type or level you can say.

      4.       Generally we have three questions in mind while working with logger.

      Ø  How to log

      o In Appenders with the help of Formatters

      Ø  What to log

      o Based on logger function and level define in the log4j.config file

      Ø  Where to log

      o Appender -console/File

       

      Levels and visibility in Log4j

       

      1. ALL

      2. TRACE

      3. DEBUG

      4. INFO

      5. WARN

      6. ERROR

      7. FATAL

       

      1. ALL

      Yes

      Yes

      Yes

      Yes

      Yes

      Yes

      Yes

       

      2. TRACE

       

      Yes

      Yes

      Yes

      Yes

      Yes

      Yes

       

      3. DEBUG

       

       

      Yes

      Yes

      Yes

      Yes

      Yes

       

      4. INFO

       

       

       

      Yes

      Yes

      Yes

      Yes

       

      5. WARN

       

       

       

       

      Yes

      Yes

      Yes

       

      6. ERROR

       

       

       

       

       

      Yes

      Yes

       

      7. FATAL

       

       

       

       

       

       

      Yes

       

      8. OFF

       

       

       

       

       

       

       

       

       

      Based on the above table lets understand how we can set the levels in logger.

      If in the configuration file we set Log4j.rootLogger =  Debug it will Log all the values related to levels which are lesser then it like Info, Warn, error etc.

      But let suppose if you set Log4j.rootLogger =  Error and try to log the values using debug , info and warn appender it will not log these informations.

      This is how we can control the levels of logging

       

      Log4j.Properties file

      # Define the root logger with appender file

      # where you want to log the data while

      log = C:/Users/test/Music/Batch-Feb-2021/Online/Selenium/src/results/

      # Define the root logger and level of logging

      log4j.rootLogger = FATAL, FILE

       

      # Define the file appender

      log4j.appender.FILE=org.apache.log4j.RollingFileAppender

      # Rolling file appender is a child class of file appender file to take the back of log file when they reach to certain size in below lines you can see size is defined with backup index

       

      log4j.appender.FILE.File=${log}/logs.out

      log4j.appender.FILE.MaxFileSize=5MB

      log4j.appender.FILE.MaxBackupIndex=3

       

      # Define the layout for file appender

      log4j.appender.FILE.layout=org.apache.log4j.PatternLayout

      # Define to print the log value with IST timestamp

      log4j.appender.FILE.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n

       

      #do not append the old file. Create a new log file everytime

      log4j.appender.dest1.Append=true

       

      Java Program Code

      package LoggerCode;

      import org.apache.log4j.Logger;

      public class UnderstandLogger {

      static Logger log = Logger.getLogger(UnderstandLogger.class.getName());

      public static void main(String[] args) {

              log.debug("Hello this is a debug message");

      log.info("Hello this is an info message");

      log.trace("failed");  

      }

      }



      How to remove the message for "SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"".

       

      SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder


      Ø SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

      Ø SLF4J: Defaulting to no-operation (NOP) logger implementation

      Ø SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.


      To get rid of this message we need to download (slf4j-log4j12 JAR) and import packages in our java project.

      Once the import is done you will not see this message.