Skip to content

Adding selenium scripts to master #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions openmrs/DEV.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<classes>
<class name="org.tq.openmrs.tests.ParametersEx" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Binary file added openmrs/IEDriverServer.exe
Binary file not shown.
18 changes: 18 additions & 0 deletions openmrs/QA.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="5">
<test name="Test">
<parameter name="url" value="https://demo.openmrs.org" />
<parameter name="browserType" value="FF" />
<parameter name="username" value="Admin" />
<parameter name="password" value="Admin123" />
<parameter name="serviceName" value="Urology" />
<classes>
<class name="org.tq.openmrs.tests.OpenMrsTests" >
<methods>
<include name ="verifyListServiceTypeAvailable" />
</methods>
</class>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Binary file added openmrs/chromedriver.exe
Binary file not shown.
Binary file added openmrs/geckodriver.exe
Binary file not shown.
113 changes: 113 additions & 0 deletions openmrs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.tq</groupId>
<artifactId>openmrs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>openmrs</name>
<url>http://maven.apache.org</url>
<!-- https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html -->
<properties>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<profiles>
<profile>
<id>QA</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<forkCount>0</forkCount>
<suiteXmlFiles>
<suiteXmlFile>QA.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_65\bin\javac.exe</executable>
</configuration>
</plugin>


</plugins>


</build>



</profile>
<profile>
<id>DEV</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<forkCount>0</forkCount>
<suiteXmlFiles>
<suiteXmlFile>DEV.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>


</plugins>


</build>



</profile>


</profiles>

<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.13.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>

</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6</version>
</dependency>

</dependencies>
</project>
20 changes: 20 additions & 0 deletions openmrs/src/main/java/org/tq/openmrs/pages/HomePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.tq.openmrs.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class HomePage {

WebDriver driver;
public HomePage(WebDriver driver)
{
this.driver = driver;
}
public void navigateToServiceTypes()
{

//Navigate to ManageServiceTypes
driver.findElement(By.id("appointmentschedulingui-homeAppLink-appointmentschedulingui-homeAppLink-extension")).click();
driver.findElement(By.id("appointmentschedulingui-manageAppointmentTypes-app")).click();
}
}
23 changes: 23 additions & 0 deletions openmrs/src/main/java/org/tq/openmrs/pages/LoginPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.tq.openmrs.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class LoginPage {


WebDriver driver;
public LoginPage(WebDriver driver)
{
this.driver = driver;
}
public void login(String username,String password)
{
//login
driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("Inpatient Ward")).click();
driver.findElement(By.id("loginButton")).click();

}
}
20 changes: 20 additions & 0 deletions openmrs/src/main/java/org/tq/openmrs/pages/LogoutPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.tq.openmrs.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class LogoutPage {


WebDriver driver;
public LogoutPage(WebDriver driver)
{
this.driver = driver;
}
public void logout()
{
//Logout
driver.findElement(By.cssSelector(".logout>a")).click();

}
}
102 changes: 102 additions & 0 deletions openmrs/src/main/java/org/tq/openmrs/pages/ManageServiceTypesPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.tq.openmrs.pages;

import java.util.HashMap;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class ManageServiceTypesPage {

WebDriver driver;
public ManageServiceTypesPage(WebDriver driver)
{
this.driver = driver;
}
public HashMap<String,String> addServiceType(String serviceName)
{

HashMap<String,String> hMap = new HashMap<String,String>();

driver.findElement(By.cssSelector(".confirm.appointment-type-label.right")).click();
driver.findElement(By.id("name-field")).clear();
hMap.put("serviceName", serviceName);
driver.findElement(By.id("name-field")).sendKeys(serviceName);
hMap.put("duration","10");
driver.findElement(By.id("duration-field")).sendKeys("10");
hMap.put("description","Adding Service Type");
driver.findElement(By.id("description-field")).sendKeys("Adding Service Type");
driver.findElement(By.id("save-button")).click();
return hMap;

}
public boolean isServiceTypeAvailable(String serviceName)
{

boolean result = false;
//Identify the List of Pages and navigate to every page
List<WebElement> pageList = driver.findElements(By.cssSelector("#appointmentTypesTable_paginate>span>a"));
System.out.println("Size of pagesList" + pageList.size());
outer:
for(int i=0;i<pageList.size();i++)
{
pageList = driver.findElements(By.cssSelector("#appointmentTypesTable_paginate>span>a"));
pageList.get(i).click();

List<WebElement> trList = driver.findElements(By.cssSelector("#appointmentTypesTable>tbody>tr>td:nth-of-type(1)"));
System.out.println("Size of the Table row Lst " + trList.size());
for(int j=0;j<trList.size();j++)
{
System.out.println(trList.get(j).getText());
if(trList.get(j).getText().contains(serviceName))
{
System.out.println("Service Name Found!!!!");
result = true;
break outer;
}
}

}
return result;
}
public boolean isServiceTypeAvailable(HashMap<String,String> hMap)
{

boolean result = false;
//Identify the List of Pages and navigate to every page
List<WebElement> pageList = driver.findElements(By.cssSelector("#appointmentTypesTable_paginate>span>a"));
System.out.println("Size of pagesList" + pageList.size());
outer:
for(int i=0;i<pageList.size();i++)
{
pageList = driver.findElements(By.cssSelector("#appointmentTypesTable_paginate>span>a"));
pageList.get(i).click();

List<WebElement> trList = driver.findElements(By.cssSelector("#appointmentTypesTable>tbody>tr>td:nth-of-type(1)"));
System.out.println("Size of the Table row Lst " + trList.size());
for(int j=0;j<trList.size();j++)
{
System.out.println(trList.get(j).getText());
if(trList.get(j).getText().contains(hMap.get("serviceName")))
{
System.out.println("Duration Xpath" + ".//*[@id='appointmentTypesTable']/tbody/tr["+(j+1) +"]/td[2]");
String duration = driver.findElement(By.xpath(".//*[@id='appointmentTypesTable']/tbody/tr["+(j+1) +"]/td[2]")).getText();
String description = driver.findElement(By.xpath(".//*[@id='appointmentTypesTable']/tbody/tr["+(j+1) +"]/td[3]")).getText();
if(hMap.get("duration").equals(duration) && hMap.get("description").equals(description) )
{
result = true;
System.out.println("Duration and Descrition are equal!!!!");
break outer;

}

System.out.println("Service Name Found!!!!");

}
}

}
return result;
}
}
73 changes: 73 additions & 0 deletions openmrs/src/main/java/org/tq/util/BaseClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.tq.util;

import java.io.File;
import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class BaseClass {


protected WebDriver driver;
@Parameters({"url","browserType"})
@BeforeTest
public void launchApplication(String url,String browserType)
{
switch(browserType)
{
case "FF":
System.out.println("in FF");
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
driver = new FirefoxDriver();
break;
case "IE":
System.out.println("in IE");
System.setProperty("webdriver.ie.driver","IEDriverServer.exe");
driver = new InternetExplorerDriver();
//zoom set to 100%
//Enabled protected mode for all the zones..
break;
case "CH":
System.out.println("in CH");
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
driver = new ChromeDriver();
break;
default:
break;
}
driver.get(url);
}
protected static String[][] readXLSFile(String fileName,String sheetName) throws BiffException, IOException
{
File f = new File(fileName);
Workbook wb = Workbook.getWorkbook(f);
Sheet sh = wb.getSheet(sheetName);
int rows = sh.getRows();
int cols = sh.getColumns();

String arr [] [] = new String[rows][cols];
for(int i =0 ; i < rows ;i++)
{

for(int j =0 ; j<cols;j++)
{
Cell cell = sh.getCell(j,i);
arr[i][j]= cell.getContents();
System.out.println("Values stored in Array "+ arr[i][j]);
}

}
return arr;
}

}
Loading