Showing posts with label Selenium. Show all posts
Showing posts with label Selenium. Show all posts

Wednesday, 15 May 2024

How to implement AI in selenium automation testing

Implementing AI in Selenium automation testing can enhance the testing process by adding intelligence to your tests, such as smarter element identification, dynamic test case generation, or result analysis. Here's a general approach:

1. **Identify areas for AI integration**: Determine which aspects of your testing process could benefit from AI, such as test case generation, test data management, or result analysis.

2. **Select AI techniques**: Choose AI techniques that suit your requirements. This could include machine learning for predictive analysis, natural language processing for test case generation, or computer vision for visual testing.

3. **Integrate AI libraries or services**: Incorporate AI libraries or services into your Selenium automation framework. For example, you might use TensorFlow or PyTorch for machine learning tasks, NLTK or spaCy for natural language processing, or OpenCV for computer vision tasks.

4. **Enhance element identification**: Use AI to improve element identification in your tests. Instead of relying solely on XPath or CSS selectors, consider using machine learning algorithms to dynamically identify elements based on their visual appearance or other attributes.

5. **Dynamic test case generation**: Utilize AI techniques to generate test cases dynamically based on changing requirements or user behavior. This could involve using reinforcement learning algorithms to adapt test cases over time.

6. **Result analysis and reporting**: Implement AI algorithms to analyze test results more intelligently. This could include identifying patterns or anomalies in test results, predicting potential issues, or providing insights for improving test coverage.

7. **Continuous learning and improvement**: Continuously monitor and refine your AI-powered testing approach based on feedback and new data. This could involve retraining machine learning models, updating test case generation algorithms, or fine-tuning result analysis techniques.

Remember to consider factors such as data privacy, model interpretability, and performance optimization when integrating AI into your Selenium automation testing framework.

how to check both Actual value equals to Expected Value

How to check Actual Value contains in Expected Value

public void verifyActualValuePresentInExpected(List<String> expectedValue, set<String> actualValue){

Boolean status = actualValue.stream().allMatch(expectedValue:: contains);

if(status){
Pass
} else {
Fail
List<String> extraValue = actualValue.stream().
filter(val-> ! expectedValue.contains(val)).
Collect(Collectors.toList());
System.out.println(extraValue);

List<String> missingValue = expectedValue.stream().
filter(val1-> ! actualValue.contains(val1)).
Collect(Collectors.toList());
System.out.println(missingValue);

}

How to check Expected Value contains in Actual Value

public void verifyExpectedValuePresentInActual(List<String> expectedValue, set<String> actualValue){

Boolean status = expectedValue.stream().allMatch(actualValue:: contains);

if(status){
Pass
} else {
Fail
List<String> missingValue = actualValue.stream().
filter(val-> ! expectedValue.contains(val)).
Collect(Collectors.toList());
System.out.println(missingValue);

List<String> extraValue = expectedValue.stream().
filter(val1-> ! actualValue.contains(val1)).
Collect(Collectors.toList());
System.out.println(extraValue);

}

Best practice for create selenium Automation test

Creating robust and flexible Selenium automation tests involves following best practices for test design, implementation, and maintenance. Here are some steps to achieve this:

1. **Identify clear test objectives**: Clearly define the purpose and scope of each test case to ensure that it aligns with the overall testing goals.

2. **Use descriptive and meaningful test names**: Give each test case a descriptive and meaningful name that reflects its purpose and expected behavior. This makes it easier to understand the test's intent and results.

3. **Modularize test code**: Divide your test code into small, reusable modules or functions that focus on specific actions or scenarios. This promotes code reuse, simplifies maintenance, and enhances readability.

4. **Implement robust error handling**: Anticipate and handle potential exceptions or errors gracefully in your test code. Use try-catch blocks or assertion methods to verify expected outcomes and handle unexpected conditions effectively.

5. **Parameterize test data**: Parameterize test data to make tests more flexible and adaptable to different scenarios. Use data-driven techniques to separate test logic from test data, allowing for easier maintenance and scalability.

6. **Use explicit waits**: Use explicit waits to ensure that tests wait for specific conditions to be met before proceeding. This helps avoid timing issues and makes tests more reliable, especially when dealing with dynamic web elements or network latency.

7. **Create meaningful assertions**: Write meaningful assertions that verify the expected behavior of the application under test. Use assertions to validate page content, element properties, or application state to ensure that tests accurately reflect user expectations.

8. **Implement page object model (POM)**: Organize your test code using the page object model, which encapsulates web page elements and their interactions into reusable classes. This improves code maintainability, readability, and scalability.

9. **Implement cross-browser testing**: Test your application across different web browsers and versions to ensure compatibility and consistency. Use Selenium's capabilities to automate tests on multiple browsers, and consider using cloud-based testing platforms for broader coverage.

10. **Continuous integration and testing**: Integrate Selenium tests into your continuous integration (CI) pipeline to automate test execution and ensure timely feedback on code changes. This helps catch bugs early and facilitates faster release cycles.

11. **Monitor and maintain tests**: Regularly review and update your Selenium tests to keep pace with changes in the application under test. Monitor test results for failures or regressions, and prioritize fixing flaky tests to maintain test reliability.

By following these best practices, you can create Selenium automation tests that are robust, flexible, maintainable, and provide reliable feedback on the quality of your web applications.

Monday, 30 March 2020

Difference between Web driver, Remote Web Driver and Chrome Driver


Webdriver

Web driver is interface.
Global for all browsers
The interface provide common methods signature for all browser.
Ex : findElement(), get(),switchTo()

Remote Webdriver

Remote Webdriver is concrete class  implements Webdriver.
The implementation of webdriver method is available  in Remote Webdriver Class.
The Class provide additional  method  which is not available in webdriver. Provide method to run selenium test in remote machine.
ex : getSessionID()


Chrome driver

Chrome Driver is class extends Remote Webdriver.
Only specific to Chrome browser.
The class have implementation for only chrome browser. 

Saturday, 4 March 2017

How to implement Log in Selenium (Using Log4j)



-> During the Automation Execution users need some information about the Execution steps in console.

-> We need information which helps the users to understand the testcase or any failure during the testcase execution.

-> With the help of Log4j its possible to enable logging in selenium testcase.


Follow the below steps to implement logs


1) Log4j Download


Download Log4j by using this link -> https://logging.apache.org/log4j/1.2/download.html

2) Create Log4j.properties file

-> Log4j.properties file for display log message only in console

# Root logger option
log4j.rootLogger=INFO,stdout

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


->Log4j.propertiesfiles for display log message only in file

# Root logger option
log4j.rootLogger=INFO,file

# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./Log/log_${current.date}.log
log4j.appender.fileout.Append=false
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.Append=false
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


->Log4j.propertiesfiles for display log message in both console and File

# Root logger option
log4j.rootLogger=INFO,stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./Log/log_${current.date}.html
log4j.appender.fileout.Append=false
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.Append=false
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


-> Load properties file in Main()


Initial Environment variable (Current.date) which is used in Log4j.properties file and load Log4j.properties file.

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh_mm_ss");
        System.setProperty("current.date", dateFormat.format(new Date()));
       
           PropertyConfigurator.configure("C:/Selenium/log4j.properties");
          


-> create log for required class files



public class Login {
   
    final static Logger logger = Logger.getLogger(Login.class);

public static boolean LoginGmail(){

logger.info("Information Message");
logger.debug("Warning Message");
logger.error("Error Message");
}

}


-> Best practise for use logger

logger.info = Instead of Sysout we can use looger.info
logger.debug = use inside of conditional Statments and looping statments.
logger.error =  use inside catch block.


-> LoGGER Level

See the link for logger level ->  http://arunrajvdm.blogspot.in/2016/12/log4j-how-to-disable-all-log-details.html


Tuesday, 6 December 2016

How to launch safari browser in selenium webdriver



Please follow belows steps for launching safari browser in selenium webdriver


We need to install safari driver extension in safari browser. please follow the below steps for launch safari browser.

1) Go to http://docs.seleniumhq.org/download/

2) Scroll down -> Go to the section "SafariDriver" and download "SafariDriver.safariextz"

3) Double click on "SafariDriver.safariextz" (previously downloaded)

4) Safari would open with a pop up containing "Install" button -> Click Install button

5) Now go to Preferences of Safari and you would see WebDriver (in my case WebDriver 2.48.0) is installed (Enable WebDriver checkbox is checked))

6) It's now time to instantiate SafariDriver and get the desired URL by using Java code:

WebDriver driver = new SafariDriver();
driver.get("https://www.google.com");




Error :

If we are not install SafariDriver.safariextz extension in safari browser, we will get the below error in safari browser during the automation

"Unable to establish a connection with the SafariDriver Extension"


Solution : Follow the above steps to get install "SafariDriver.safariextz" extension in safari browser.



Exception :


If we are not install SafariDriver.safariextz extension in safari browser, we will get the below exception in console during the automation

Driver instantiation Exception Remote Client is not accessible



Solution : Follow the above steps to get install "SafariDriver.safariextz" extension in safari browser.

Log4j - How to disable all log details




We can logging the step by step activity during automation. If any instance we want to disable all log details then follow the below steps


1) go to the //log/log4j.properties file

2) And set the log4j.rootLogger=OFF


log4j.rootLogger=OFF


we can set the restriction to display the log messages



1) If log4j.rootLogger= DEBUG

then it display the all level

log.debug(),log.info(), log.warn(),  log.error(), log.fatal();


2)  If log4j.rootLogger= INFO

then it will display

log.info(), log.warn(),  log.error(), log.fatal();


3)  If log4j.rootLogger= WARN

then it will display

log.warn(),  log.error(), log.fatal();


4)  If log4j.rootLogger= WARN

then it will display

log.warn(),  log.error(), log.fatal();


5)  If log4j.rootLogger= ERROR

then it will display

log.error(), log.fatal();


6)  If log4j.rootLogger= FATAL

then it will display

log.fatal();


7)  If log4j.rootLogger= OFF

then it will NOT display



http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/log4j/log4j.html#LOG4J-Basics-Logger


How to change font color in Excel Sheet by using Apache POI




By using below code we can change the font color in Apache POI



private static void updateColor(String FilePath,int row,int col,String Sheet, String color1) throws FileNotFoundException, IOException {

Workbook book2=verifyExcelVersion(FilePath);
Sheet sheet2=book2.getSheet(Sheet);

// update Font with colors

CellStyle style=book2.createCellStyle();
Font font=book2.createFont();

if(color1.equals("RED"))
font.setColor(IndexedColors.RED.getIndex());
if(color1.equals("GREEN"))
font.setColor(IndexedColors.GREEN.getIndex());
if(color1.equals("BLUE"))
font.setColor(IndexedColors.BLUE.getIndex());

style.setFont(font);


    sheet2.getRow(row).getCell((short) col).setCellStyle(style);
   
     FileOutputStream output_file =new FileOutputStream(new File(FilePath));
     book2.write(output_file);
     output_file.flush();
     output_file.close();
     sheet2=null;
     book2=null;


}

How to display message box in java




We can display the message box during the selenium automation by using Java Swing


public static void main(String args[])
{
msgbox("The verification part is done. We can procced with update the timesheets");
}

private static void msgbox(String string) {
JOptionPane.showMessageDialog(null, string);

}

Saturday, 4 June 2016

How to create excel sheet using apache poi





By using below code we can create excel sheet using apache poi



code:


public static void main(String agrs[])
{

Workbook book2=verifyExcelVersion(ToFilePath);
Sheet sheet2=null;


createExcelSheet(wb,"Sheet2",Download_FilePath);

}



// create new Excel sheet in workbook

public static void createExcelSheet(Workbook wb, String SheetName, String ExcelPath) throws IOException
{
wb.createSheet(SheetName);
FileOutputStream output_file =new FileOutputStream(new File(ExcelPath));  
wb.write(output_file); 
output_file.flush();
output_file.close(); 

}


// verify Excel version

public static Workbook verifyExcelVersion(String FilePath) throws FileNotFoundException, IOException
{
Workbook book1=null;
String fileExtn=FilenameUtils.getExtension(FilePath);

if(fileExtn.equals("xls"))
book1=new HSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsx"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsm"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
return book1;
}


How to verify excel sheet present or not in apache poi



By using below code we can verify the perticular excel sheet present or not. If not available we can create by using apache POI command.



code:

public static void main(String agrs[])
{

Workbook book2=verifyExcelVersion(ToFilePath);
Sheet sheet2=null;


if(!isExcelSheetExist(wb,"Sheet2"))
createExcelSheet(wb,"Sheet2",Download_FilePath);

}


// verify Excel Sheet exist or not

public static boolean isExcelSheetExist(Workbook wb, String SheetName)
{
if(wb.getSheetIndex(SheetName)>=0)
return true;
else
return false;

}


// create new Excel sheet in workbook

public static void createExcelSheet(Workbook wb, String SheetName, String ExcelPath) throws IOException
{
wb.createSheet(SheetName);
FileOutputStream output_file =new FileOutputStream(new File(ExcelPath));  
wb.write(output_file); 
output_file.flush();
output_file.close(); 

}


// verify Excel version

public static Workbook verifyExcelVersion(String FilePath) throws FileNotFoundException, IOException
{
Workbook book1=null;
String fileExtn=FilenameUtils.getExtension(FilePath);

if(fileExtn.equals("xls"))
book1=new HSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsx"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsm"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
return book1;
}




How to create common functions for working with different format of Excel Sheet by using Apache POI



By using below verifyExcelVersion() we can create common function for handle with different Excel format by using Apache POI



code:

public static void main(String agrs[])
{

Workbook book2=verifyExcelVersion(ToFilePath);
Sheet sheet2=null;


if(!isExcelSheetExist(wb,"Sheet2"))
createExcelSheet(wb,"Sheet2",Download_FilePath);

}




// verify Excel version

public static Workbook verifyExcelVersion(String FilePath) throws FileNotFoundException, IOException
{
Workbook book1=null;
String fileExtn=FilenameUtils.getExtension(FilePath);

if(fileExtn.equals("xls"))
book1=new HSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsx"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
else if(fileExtn.equals("xlsm"))
book1=new XSSFWorkbook(new FileInputStream(FilePath));
return book1;
}

How to set auto detect proxy settings by using selenium in browser



Normally selenium referred the system proxy settings. If we want to use auto detect proxy setting from selenium code then we have to use different code like below



       org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
       proxy.setAutodetect(true); 
       DesiredCapabilities cap = new DesiredCapabilities();
       cap.setCapability(CapabilityType.PROXY, proxy);
       WebDriver driver5 = new FirefoxDriver(cap);
       
       driver5.manage().window().maximize();

How to Generate XSLT reports by using Ant+TestNG



We have to follow below steps to generate XSLT reports

1) ANT Installation
2) Configure XSLT and build.xml
3) Genrate XSLT report by using ANT

1) ANT Installation

-> Download Latest Version of apache-ant zip
Download latest version of apache-ant from

http://ant.apache.org/bindownload.cgi.

Extract zip folder and save into our local path.

-> Set JAVA_HOME Environment variables

* Right click on My Computer -> Properties and go to -> Advanced tab.
* Clicking on Environment variables button will open Environment variable dialog.
* Click on New button from System Variables box and add Variable Name = JAVA_HOME and Variable Value = Path of your jdk folder.
* Here my JDK folder path is 'C:\Program Files\Java\jdk1.8.0'

-> Set ANT_HOME Environment Variables

* Right click on My Computer -> Properties and go to -> Advanced tab.
* Clicking on Environment variables button will open Environment variable dialog.
* Click on New button from System Variables box and add Variable Name = ANT_HOME and Variable Value = Path of your jdk folder.
* Here my ANT folder path is 'D:\Selenium\apache-ant-1.9.7'

-> Edit Path Variable

* Right click on My Computer -> Properties and go to -> Advanced tab.
* Clicking on Environment variables button will open Environment variable dialog.
* Edit existing Path variable by selecting Path variable from System variables list.
* And click Edit button and insert  %JAVA_HOME%\bin;%ANT_HOME%\bin  at the end of Path variable value string.
* Do not forget to put semicolon (;) before %JAVA_HOME%\bin

-> Copy tools.jar from jdk/lib and paste It In jre/lib
* There will be 2 folders In your C:Program Files\Java folder.
* In my system It Is jdk1.8.0 and jre8.
* Open C:\Program Files\Java\jdk1.8.0\lib folder and copy tools.jar file.
* Open C:\Program Files\Java\jre8\lib and paste tools.jar In to It.

Now restart your system to getting system variables changes effect.

Verify ant configured properly or not
To verify that ant Is configured properly or not, follow the bellow given steps after restarting system
* Open command prompt.
* Type command "ant" and press Enter button.
* It should show you message as bellow.


C:\Users\user>ant
Buildfile: build.xml does not exist!
Build failed





2) Configure XSLT and build.xml


-> The below jar files shoule be under lib folder

* saxon-8.7
* SaxonLiaison
* testng-xslt-maven-plugin-test-0.0
* Selenium-server-standalone 2.47

-> The below files should be under project path

* build.xml  -> Link to download
* testng-results.xsl -> Link to Download

-> Configure build.xml file

Verify the Value for "project.jars" property at line no 10 of build.xml file. It should be the path of "lib" folder of project.
Verify the path of testng-results.xsl file at line no 91 of build.xml file. It should be  path of testng-results.xsl.

Note : Don't change any thing else In build.xml file.




3) Genrate XSLT report by using ANT


Once your test execution get completed and testng results generated, We can go to generate XSLT report. You need to follow bellow given steps to generate XSLT report.


-> Open command prompt.

-> Goto your project

E:\Selenium_Project\Selenium_Testing>

-> Type "ant" to check we are in correct path to generate XSLT report.


E:\Selenium_Project\Selenium_Testing>ant
Buildfile: E:\Selenium_Project\Selenium_Testing\build.xml

usage:
     [echo]
     [echo]             ant run will execute the test
     [echo]

BUILD SUCCESSFUL
Total time: 0 seconds


-> Remove Previous Build : Type Command = "ant clear"

 It should give message "BUILD SUCCESSFUL"


E:\Selenium_Project\Selenium_Testing>ant clear
Buildfile: E:\Selenium_Project\Selenium_Testing\build.xml

clear:
   [delete] Deleting directory E:\Selenium_Project\Selenium_Testing\build

BUILD SUCCESSFUL
Total time: 0 seconds


-> Compile And Generate New Build Folder : Type Command = "ant compile".

 It should give message "BUILD SUCCESSFUL"

E:\Selenium_Project\Selenium_Testing>ant compile


-> Verify Build Folder Is Generated : Now Refresh your project In eclipse.
 ant compile command will created new folder with name of  build under your project

-> Execute Test Suites : Type Command = ant run In command prompt and press enter.
It will execute your all software automation test suites which are included In testng.xml file.

 So now you can execute your software test suites from command prompt Instead of testng.xml file.

-> Generate XSLT Reports : Type Command = ant reports In command prompt and press enter.
It should give message "BUILD SUCCESSFUL"

-> open XSLT Report : Once more refresh your project In eclipse.

 ant reports command will create new folder with name = XSLT_Reports under your project


->You will find index.html file In XSLT_Reports folder.
That Is XSLT Report of your webdriver test. Open that file In any web browser.
 It Is Interactive and easy to understand that how many test cases are Pass, Fail and Skip for specific test case.



Note : If pie chart is not available in your report then you will get error message in browser like below


Error Message : SVG Pie Charts are not available. Please install a SVG viewer for your browser


So please install SVG viewer in order to see pie chart in XSLT reports.

Saturday, 30 April 2016

XPATH Functions




1) Node Set Function
2) String Function
3) Boolean Function
4) Number Function




1) Node Set Function

-> last()

Identify the last item of current node set.

Ex : https://www.google.co.in

//div[@id='sfdiv']//input[last()]  -> its identify last input tag



-> position()

Identify the item as per the postion. Position value start from 14.

Ex : https://www.google.co.in

//div[@id='sfdiv']//input[position()=1]  -> its identify first input tag



-> count()

Its count the number of element from context node.


Ex : https://www.google.co.in

count(//div[@id='sfdiv']//input)  -> o/p=3, Return total number of input element.



-> local-name()


Instead of element tag(//div)) we can use local-name() (local-name()='div')

Ex : https://www.google.co.in

local-name(//div[@id='sfdiv']//input)

//*[local-name()='div' and starts-with(@id,'sfdiv')]//input



-> id()

Its returns elements which ID specified in code


Ex : https://www.google.co.in

id("sfdiv")/div//input  -> o/p=3, Identify all 3 input tag.


The xpath id("sfdiv")/div//input  and //div[@id='sfdiv']//input both are same.


**********************************************************************



2) String Functions


-> String()

we can identify the object by using text. Both Text() and String() are same.


Ex : https://www.google.co.in

//div[@id='gbw']//a[String()='Gmail']

//div[@id='gbw']//a[text()='Gmail']

Both are same.


o/p identify the object which having the GMAIL text.



-> Concat()

Its Used to concatenate the two string


Ex : https://www.google.co.in


concat(//div[@id='gbw']//a[text()],' ',//div[@id='gbw']//a[text()])

O/p String: Gmail Gmail

concat(//div[@id='gbw']//a[text()],' ',//div[@id='gbw']//div[2]//a[text()])


O/p String: Gmail Images




-> starts-with()


Its identify the object by using text which starts given string.


Ex : https://www.google.co.in

//*[local-name()='div' and starts-with(@id,'sfdiv')]//input


o/p identify all three objects.



-> Contains()

Its identify the object which contains the text

Ex: https://www.google.co.in


//div[contains(id,'sfdiv']//input

o/p identify all three objects.



-> substring-before()

Its retrives the substring of first argument

Ex : https://www.google.co.in

substring-before(//div[@id='gbw']//a[text()],'a')

o/p  String: il


we can use this xpath like below for identify the object

//div[@id='gbw']//a[contains(.,substring-before(//div[@id='gbw']//a[text()],'a'))]





-> substring-after()

Its retrives the substring of first argument

substring-after(//div[@id='gbw']//a[text()],'a')


O/P     String: il


we can use this xpath like below for identify the object

//div[@id='gbw']//a[contains(.,substring-after(//div[@id='gbw']//a[text()],'a'))]



*******************************************************************8


3) Boolean Function


-> Boolean boolean(object)

Converts the argument to a Boolean value.

Example - boolean(/journal/article/author/last[.='Jones'])



-> Boolean not(boolean)

Negates the boolean value.

Example - not(/journal/article/author/last[.='Jones'])


***************************************************


4) Number Function


Will update shortly




https://docs.oracle.com/cd/E35413_01/doc.722/e35419/dev_xpath_functions.htm#autoId19

Behaviour Driven Development framework - Cucumber


Cucumber

Cucumber is tool based on Behaviour Driven Development framework which is used with selenium for perform acceptance testing.


It allows automation of functional validation in easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc.


@Test
public void should_do_something() {
    // given
    Something something = getSomething();

    // when
    something.doSomething();
    // then
    assertSomething();

    // when
    something.doSomethingElse();
    // then
    assertSomethingElse();
}



Behavior Driven Development is extension of Test Driven Development and it is used to test the system rather than testing the particular piece of code.

Saturday, 23 January 2016

Getting Error Message : java.util.regex.PatternSyntaxException: Unclosed character class near index 0

While try to split the value by using "[" OR "]" then we are getting the above issue.


Ex : String str="Selenium []"
    str.split("[")

we are getting the below exception.


Exception :

java.util.regex.PatternSyntaxException: Unclosed character class near index 0


Solution

The Special character "["  and "]" used in Regular Experssions, so these characters are not standared characters.

So we should add excape character for use this special character ("\[" and "\]"). But the escape character "\" is not allowed for "["  and "]".

So we should use string as "\\[" or "\\]"


Exact code will be

Ex : String str="Selenium []"
    str.split("\\[")


http://stackoverflow.com/questions/21816788/unclosed-character-class-error

Getting Error Message : Access restriction: The type Provider is not accessible due to restriction on required library C:\Program Files\Java\jre8\lib\jsse.jar




Solution


Go to the Build Path settings in the project properties.
Remove the JRE System Library
Add it back; Select "Add Library" and select the JRE System Library. The default worked for me.


Reason :


This works because you have multiple classes in different jar files. Removing and re-adding the JRE lib will make the right classes be first. If you want a fundamental solution make sure you exclude the jar files with the same classes.