I’ve to execute my check circumstances as a single in addition to a set, proper now its operating as a set however not as a single check case in selenium webdriver: Under is my check that are calling strategies current in enterprise class, and enterprise class calling web page class containing locators: Under is my check of 1 report, identical method we’ve to create totally different experiences:
Enterprise class:
package deal com.deere.gmsr.enterprise;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.assist.CacheLookup;
import org.openqa.selenium.assist.FindBy;
import org.openqa.selenium.assist.How;
import org.openqa.selenium.assist.ui.ExpectedConditions;
import org.openqa.selenium.assist.ui.Choose;
import org.openqa.selenium.assist.ui.WebDriverWait;
import com.deere.gmsr.web page.MhCurrentMonthReportPage;
import com.deere.gmsr.utility.PageUtility;
import com.deere.gmsr.utility.ScreenshotUtility;
public class MhCurrentMonthReportBusiness extends MhCurrentMonthReportPage {
non-public WebDriver driver;
//WaitUtility waitutility;
public MhCurrentMonthReportBusiness(WebDriver driver) {
tremendous(driver);
this.driver=driver;
}
public void clickToCreateNewButton() throws Exception {
// WaitUtility.waitForElement(createNewButton);
// WebDriverWait wait=new WebDriverWait(driver,10);
// WebElement createNewButton=wait.till(ExpectedConditions.elementIfVisible(By.xpath(PageUtility.CREATE_NEW_BUTTON_XPATH)));
// WebElement createNewButton=wait.till(ExpectedConditions.visibilityOfElementLocated(By.xpath(PageUtility.CREATE_NEW_BUTTON_XPATH)));
Thread.sleep(3000);
createNewButton.click on();
System.out.println("fffff");
ScreenshotUtility.captureScreenShot(this.driver);
}
public void selectEquipmentDivision() {
Choose equipmentDivisionDropdown=new Choose(driver.findElement(By.xpath(PageUtility.SELECT_EQUIPMENT_DIVISION)));
equipmentDivisionDropdown.selectByIndex(1);
System.out.println(equipmentDivisionDropdown.getFirstSelectedOption());
}
public void openLocation() throws Exception{
Thread.sleep(3000);
openLocationPopup.click on();
}
public void selectGeography() throws Exception {
Choose selectGeographyType=new Choose(driver.findElement(By.xpath(PageUtility.SELECT_GEAOGRAPHY_TYPE)));
selectGeographyType.selectByIndex(1);
Thread.sleep(3000);
clickOnGreaterThanSign.click on();
clickOnNextLevel.click on();
clickToUS.click on();
clickOnSaveButton.click on();
}
public void selectMarketSegment() throws Exception {
Thread.sleep(3000);
clickOnSelectButton.click on();
Thread.sleep(3000);
clickOnAuction.click on();
Thread.sleep(3000);
save1.click on();
}
public void openProductWindow() throws Exception {
// WebDriverWait wait=new WebDriverWait(driver,30);
// WebElement openProductPopup=wait.till(ExpectedConditions.visibilityOfElementLocated(By.xpath(PageUtility.OPEN_PRODUCT_POPUP)));
Thread.sleep(3000);
openProductPopup.click on();
selectProduct.click on();
clickOnProductSaveButton.click on();
}
public void selectHistoryReports() throws Exception {
// selectHistoryReports.isSelected();
Thread.sleep(3000);
selectHistoryReports.click on();
Thread.sleep(1000);
//WebDriverWait wait=new WebDriverWait(driver,15);
//WebElement selectMonthly=wait.till(ExpectedConditions.visibilityOf(selectMonthly));
selectMonthly.click on();
}
public void selectTimePeriod(){
Choose currentMonth= new Choose(driver.findElement(By.xpath(PageUtility.SELECT_TIMEPERIOD)));
currentMonth.selectByVisibleText("Present Month");
}
public void clickOnViewReport() throws Exception {
Thread.sleep(7000);
WebDriverWait wait=new WebDriverWait(driver,20);
WebElement clickOnViewReportButton=wait.till(ExpectedConditions.visibilityOfElementLocated(By.xpath(PageUtility.CLICK_ON_VIEWREPORT_BUTTON)));
clickOnViewReportButton.click on();
}
public void clearSelections() {
clearSelections.click on();
}
public void clickOnHomeIcon() {
homeIcon.click on();
}
public void scrollUp(){
((JavascriptExecutor) driver).executeScript("scroll(0, -250);");
}
}
TestCase Class:
package deal com.deere.gmsr.testcase;
import org.openqa.selenium.assist.PageFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Check;
import com.deere.gmsr.enterprise.MhCurrentMonthReportBusiness;
import com.deere.gmsr.driver.Driver;
public class MhCurrentMonthReportTest {
public MhCurrentMonthReportBusiness mhCurrentMonthReportBusiness;
public MhCurrentMonthReportTest() throws Exception {
mhCurrentMonthReportBusiness = PageFactory.initElements(Driver.getDriver(), MhCurrentMonthReportBusiness.class);
}
@Check(precedence=8)
public void CurrentMonthReport() throws Exception{
mhCurrentMonthReportBusiness.clickToCreateNewButton();
mhCurrentMonthReportBusiness.selectEquipmentDivision();
mhCurrentMonthReportBusiness.openLocation();
mhCurrentMonthReportBusiness.selectGeography();
mhCurrentMonthReportBusiness.selectMarketSegment();
mhCurrentMonthReportBusiness.openProductWindow();
mhCurrentMonthReportBusiness.selectHistoryReports();
mhCurrentMonthReportBusiness.selectTimePeriod();
mhCurrentMonthReportBusiness.scrollUp();
mhCurrentMonthReportBusiness.clickOnViewReport();
Thread.sleep(3000);
mhCurrentMonthReportBusiness.clickOnHomeIcon();
// Driver.getDriver().navigate().again();
// mhCurrentMonthReportBusiness.clearSelections();
Assert.assertTrue(true);
}
}
Loginbusiness Class:
package deal com.deere.gmsr.enterprise;
import java.util.Properties;
import org.openqa.selenium.WebDriver;
import com.deere.gmsr.web page.LoginPage;
import com.deere.gmsr.utility.Fixed;
import com.deere.gmsr.utility.ScreenshotUtility;
import com.deere.gmsr.utility.Utility;
public class LoginBusiness {
non-public WebDriver driver;
LoginPage loginPage;
public LoginBusiness(WebDriver driver) throws Exception {
this.driver = driver;
loginPage = new LoginPage(driver);
}
// public LoginDTO getLoginCredentials() throws Exception {
// Properties properties = Utility.getproperties(Fixed.CONFIGURATION_PROPERTIES_FILE_PATH);
// String userName = properties.getProperty(Fixed.USERNAME);
// String password = properties.getProperty(Fixed.PASSWORD);
// LoginDTO loginDTO = new LoginDTO();
// loginDTO.setUserName(userName);
// loginDTO.setPassword(password);
// return loginDTO;
// }
public void loginToApplication() throws Exception {
loginPage.getUserNameTextField().clear();
Properties properties = Utility.getproperties(Fixed.CONFIGURATION_PROPERTIES_FILE_PATH);
String username = properties.getProperty(Fixed.USERNAME);
loginPage.getUserNameTextField().sendKeys(username);
String password = properties.getProperty(Fixed.PASSWORD);
loginPage.getPasswordTextField().clear();
// ScreenshotUtility.captureScreenShot(driver);
loginPage.getPasswordTextField().sendKeys(password);
loginPage.getSignInButton().click on();
}
}
Login testclass:
public class LoginTest{
public LoginBusiness loginBusiness;
public LoginTest() throws Exception {
loginBusiness = new LoginBusiness(Driver.getDriver());
}
@Check
public void loginToGmsrApplication() throws Exception {
loginBusiness.loginToApplication();
}
Driver class
package deal com.deere.gmsr.driver;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
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.AfterSuite;
import com.deere.gmsr.utility.Fixed;
import com.deere.gmsr.utility.Message;
import com.deere.gmsr.utility.Utility;
import io.github.bonigarcia.wdm.WebDriverManager;
public class Driver {
non-public static WebDriver driver;
non-public Driver() {
}
/**
*
* @return
* @throws Exception
*/
public static synchronized WebDriver getDriver() throws Exception {
if (null == driver) {
Properties properties = Utility.getproperties(Fixed.CONFIGURATION_PROPERTIES_FILE_PATH);
String browser = properties.getProperty(Fixed.BROWSER);
String url = properties.getProperty(Fixed.URL);
change (browser) {
case Fixed.CHROME:
WebDriverManager.chromedriver().setup();
// System.setProperty("webdriver.chrome.driver", "D:chromedriverchromedriver.exe");
// WebDriverManager.chromedriver().model(Fixed.CHROME_DRIVER_VERSION).setup();
driver = new ChromeDriver();
// System.out.println(WebDriverManager.chromedriver().getVersions());
break;
case Fixed.IE:
WebDriverManager.iedriver().setup();
// WebDriverManager.iedriver().model(Fixed.IE_DRIVER_VERSION).setup();
driver = new InternetExplorerDriver();
break;
case Fixed.FIREFOX:
WebDriverManager.firefoxdriver().setup();
// WebDriverManager.firefoxdriver().model(Fixed.FIREFOX_DRIVER_VERSION).setup();
driver = new FirefoxDriver();
break;
default:
System.out.println(Message.SUITABLE_DRIVER_NOT_FOUND);
break;
}
if (driver != null) {
driver.handle().window().maximize();
driver.handle().deleteAllCookies();
driver.get(url);
driver.handle().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}
return driver;
}
public void navigateBack(){
driver.navigate().again();
}
@AfterSuite
public void quitDriver() {
if (null != driver) {
driver.stop();
}
}
}
The way to use this in our code in order that we will efficiently name login technique for particular person check circumstances in addition to a set.
Thanks upfront!!