我是自动化质量保证工程师,我使用Eclipse,java和selenium来完成大部分自动化操作。现在我正在编写脚本测试,包括生成一个唯一的号码作为一种用户(用户1),然后搜索该特定号码作为另一种类型的用户(用户2)
用户类型的方法/操作分为不同的类,并且都在测试类中引用。这是唯一的号码,被识别并存储为用户1类中的变量(srnumber 2)。
public class InvoicingPOF {
@FindBy(id = "ctl00_ContentPlaceHolder1_LabelSRNumberHeader")
WebElement SRNumberBillingReq;
public void InvoiceBillingRequirementCompletion(String Srnumber) throws InterruptedException {
CreateInvoicebtn.click();
String srnumber2 = SRNumberBillingReq.getText(); //Example of getting Service request number in invoice class
InvoiceNumberfield.sendKeys(srnumber2);
InvoiceAmount.sendKeys("0.00");
WorkDateField.click();
Thread.sleep(2000);
TodaysDatebtn.click();
WorkDateField.sendKeys(Keys.ENTER);
CustomerSignatureQuestion.sendKeys("Y", Keys.TAB);
NextStep1.click();
}
}
我想在用户1的类(InvoicingPOF)中使用srnumber2变量和值(假设生成的数字是1234我想将其传递给另一个类)并在User 2的类(HomePagePOFSC)中使用它。以下是代码的其余部分
Test Class
package fcstestingsuite.fsnrgn;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.openqa.selenium.WebDriver;
import pageobjectfactory.*;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
public class E2ESRInvoiceTest {
WebDriver driver;
Ourfsnlogin LoginPage;
SRCreate SRCreatePage;
InvoicingPOF Invoicing;
HomePagePOF HomePage;
@BeforeTest
public void beforeTest() throws InterruptedException {
SRCreate.webdrive();
InvoicingPOF.webdrive();
// SRCreate.driver = new ChromeDriver();
// setting global explicit wait
PageFactory.initElements(new AjaxElementLocatorFactory(InvoicingPOF.driver, 60), this);
InvoicingPOF.driver.get("fsndevweb:81");
// initiating elements in page factory
SRCreatePage = PageFactory.initElements(InvoicingPOF.driver, SRCreate.class);
LoginPage = PageFactory.initElements(InvoicingPOF.driver, Ourfsnlogin.class);
Invoicing = PageFactory.initElements(InvoicingPOF.driver, InvoicingPOF.class);
HomePage = PageFactory.initElements(InvoicingPOF.driver, HomePagePOF.class);
LoginPage.sendUserName("ebluth");
LoginPage.sendPassword("password");
LoginPage.clicksubmit();
LoginPage.USclick();
SRCreatePage.NavigateToSRCreatebtn();
SRCreatePage.SRCreationTestHVAC();
String srnumber = SRCreatePage.SRNumber.getText();
System.out.println(srnumber + " it worked !");
LoginPage.Logout();
LoginPage.sendUserNameSP("4335701");
LoginPage.sendPassword("password");
LoginPage.clicksubmit();
LoginPage.SPSRSearch(srnumber);
Thread.sleep(3000);
Invoicing.ActivtityCompletition();
HomePage.HomePageNaviate();
LoginPage.SPSRSearch(srnumber);
}
@Test(priority = 1)
public void SPInvoiceSubmissionTest() throws InterruptedException {
String Srnumber = null;
Invoicing.InvoiceBillingRequirementCompletion(Srnumber);
Invoicing.SPInvoiceWorkPerformed();
Invoicing.SPInvoiceLaboraPartsandSummary();
Invoicing.SPInvoiceAttachment();
Invoicing.InvoiceConfirmation();
LoginPage.LogoutSP();
}
@Test(priority = 2)
public void SCInvoiceSubmissionTest() throws InterruptedException {
String Srnumber = null;
Thread.sleep(3000);
LoginPage.sendUserNameServiceCenter("SCUser");
LoginPage.sendPassword("password");
//Service Request search action would happen here
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
Relevant Page Object Classes
package pageobjectfactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.testng.Assert;
import java.text.NumberFormat;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
public class InvoicingPOF {
@FindBy(id = "ctl00_ContentPlaceHolder1_ibSRNum")
WebElement SPSRSearchbtn;
@FindBy(id = "ctl00_ContentPlaceHolder1_tbSRNum")
WebElement SPSRSearchbox;
// Activity Management
@FindBy(id = "ctl00_ContentPlaceHolder1_checkInButton")
WebElement CheckinBtn;
@FindBy(id = "ctl00_ContentPlaceHolder1_checkOutButton")
WebElement CheckOutBtn;
@FindBy(id = "ddlCompleted")
WebElement JobCompleteDropDown;
@FindBy(id = "ifrmManageActivity")
WebElement ManageActivityBox;
@FindBy(id = "txtETA")
WebElement ETABox;
@FindBy(id = "TextboxSRNote")
WebElement TextBoxSRNote;
@FindBy(id = "txtTimeIn")
WebElement TimeinBox;
@FindBy(id = "ctl00_ContentPlaceHolder1_timeInRepair")
WebElement Timeinstamp;
@FindBy(id = "txtTimeOut")
WebElement TimeoutBox;
@FindBy(id = "txtReturnETA")
WebElement ReturnETABox;
@FindBy(id = "btnSave")
WebElement SavebtnActivityPopup;
@FindBy(id = "ctl00_ContentPlaceHolder1_rptrSRData_ctl01_hlSR#")
WebElement SRListSelect;
@FindBy(id = "ctl00_ContentPlaceHolder1_createInvoiceButton")
WebElement CreateInvoicebtn;
// Invoice Module Billing Requirements
@FindBy(id = "ctl00_ContentPlaceHolder1_TextboxInvNum")
WebElement InvoiceNumberfield;
@FindBy(id = "ctl00_ContentPlaceHolder1_TextboxInvAmt")
WebElement InvoiceAmount;
@FindBy(id = "ctl00_ContentPlaceHolder1_LabelSiteLimit")
WebElement NTE;
@FindBy(id = "ctl00_ContentPlaceHolder1_DropdownlistSignature")
WebElement CustomerSignatureDropDown;
@FindBy(id = "ctl00_ContentPlaceHolder1_TextboxWorkDate")
WebElement WorkDateField;
@FindBy(xpath = "//*[@class='datepick-current']/a")
WebElement TodaysDatebtn;
@FindBy(id = "ctl00_ContentPlaceHolder1_LabelSRNumberHeader")
WebElement SRNumberBillingReq;
@FindBy(id = "ctl00_ContentPlaceHolder1_DropdownlistSignature")
WebElement CustomerSignatureQuestion;
// Remember to include work date alert acceptance before proceeding to step
// Invoice SP Labor and Taxes
@FindBy(id = "ctl00_ContentPlaceHolder1_gridLabor_ctl02_ddlLabor")
WebElement LabortypeDD;
@FindBy(id = "ctl00_ContentPlaceHolder1_gridLabor_ctl02_txtQty")
WebElement HoursSP;
@FindBy(id = "ctl00_ContentPlaceHolder1_gridLabor_ctl02_btnEdit")
WebElement EditbtnLabor;
@FindBy(id = "ctl00_ContentPlaceHolder1_gridLabor_ctl02_btnUpdate")
WebElement UpdatebtnLabor;
// Invoicing Steps Work Performed.Assets.Parts
@FindBy(xpath = "//*[contains(@href,'Edit$0')]")
WebElement Editbtn0;
@FindBy(xpath = "//*[contains(@onclick,'Update$0')]")
WebElement Updatebtn0;
@FindBy(xpath = "//*[contains(@href,'Edit$1')]")
WebElement Editbtn1;
@FindBy(xpath = "//*[contains(@onclick,'Update$1')]")
WebElement Updatebtn1;
@FindBy(xpath = "//*[contains(@href,'Edit$2')]")
WebElement Editbtn2;
@FindBy(xpath = "//*[contains(@onclick,'Update$2')]")
WebElement Updatebtn2;
@FindBy(id = "ctl00_ContentPlaceHolder1_workDonePartsUsed_gridWorkPerf_ctl02_DropdownlistEquipment ")
WebElement AssetDropDownWrkPerformed;
@FindBy(xpath = "//*[contains(@onclick,'workperf')]")
WebElement AddNewWorkPerformedbtn;
@FindBy(id = "frameAddWPorParts ")
WebElement AddNewWorkSearchFrame;
// navigate to asset with keyboard commands, select using enter
@FindBy(id = "ctl00_ContentPlaceHolder1_laborTaxes_gridLabor_ctl02_btnEdit")
WebElement LaborEditbtn;
@FindBy(id = "ctl00_ContentPlaceHolder1_laborTaxes_gridLabor_ctl02_btnUpdate ")
WebElement LaborUpdatebtn;
@FindBy(id = "ctl00_ContentPlaceHolder1_laborTaxes_gridLabor_ctl02_ddlLabor")
WebElement LaborTypeDD;
@FindBy(id = "ctl00_ContentPlaceHolder1_laborTaxes_gridLabor_ctl02_txtSCQty")
WebElement SCHours;
@FindBy(id = "ctl00_ContentPlaceHolder1_laborTaxes_gridLabor_ctl02_txtSCRate")
WebElement SCRate;
@FindBy(id = "ctl00_ContentPlaceHolder1_laborTaxes_gridLabor_ctl02_txtCustQty")
WebElement CustomerHours;
@FindBy(id = "ctl00_ContentPlaceHolder1_laborTaxes_gridLabor_ctl02_txtCustRate")
WebElement CustomerRate;
@FindBy(id = "btnSearch")
WebElement SearcbtnAddNewWork;
// Will have to use keyboard commands to navigate to the first asset type
@FindBy(id = "ui-id-216-button")
WebElement AssetSelection;
// Will have to use keyboard commands to navigate to the first asset
// selection
@FindBy(id = "btnAddCheckedItems ")
WebElement AddCheckeditemsbtn;
@FindBy(id = "ctl00_ContentPlaceHolder1_workDonePartsUsed_btnCloseAddWPorParts")
WebElement CloseWindowbtn;
// RTPSpecificObjects
@FindBy(id = "ctl00_ContentPlaceHolder1_txtSRNumber")
WebElement SRSearchRTP;
@FindBy(id = "ctl00_ContentPlaceHolder1_btnYes")
WebElement YesContinueInvoice;
@FindBy(id = "ctl00_ContentPlaceHolder1_btnYes")
WebElement YesPaperWorkMatch;
@FindBy(id = "ctl00_ContentPlaceHolder1_lnkAttach")
WebElement InvoiceAttachmentrtpbtn;
// InvoiceAttachment
@FindBy(id = "frmShowAttachment")
WebElement FileAttachmentFrame;
@FindBy(id = "attachment")
WebElement Choosefilebtn;
//Submit invoice
@FindBy(xpath = "//*[@id='InvoicingContainer']/div[1]/div/ul/li[3]")
WebElement SubmitInvoicebtn;
// Need additional research on attaching files
@FindBy(id = "ImageNext")
WebElement Nextbtnframe;
@FindBy(id = "btnShowAttachmentClose")
WebElement CloseFileAttachWindow;
@FindBy(id = "ctl00_ContentPlaceHolder1_ImageNext")
WebElement NextStep1;
@FindBy(id = "ctl00_ContentPlaceHolder1_lnkAccept")
WebElement AcceptCalculatedAmountSelection;
@FindBy(id = "ctl00_ContentPlaceHolder1_finalValidation_chkAcceptDiff")
WebElement InvoiceVarianceAcceptanceCheckBox;
@FindBy(id = "ctl00_ContentPlaceHolder1_attachment")
WebElement InvoiceAttachmenttbnSP;
@FindBy(id = "ctl00_ContentPlaceHolder1_ImageSubmit")
WebElement SubmitInvoice;
// Confirmation page
@FindBy(id = "ctl00_ContentPlaceHolder1_ucSummary_lblNoPaymentReferenceNumber")
WebElement InvoiceReferenceNumber;
@FindBy(id = "ctl00_ContentPlaceHolder1_ucSummary_lblSRNumber")
WebElement SRNumberConfirmationPage;
@FindBy(xpath = "//*[@id='ctl00_ContentPlaceHolder1_ucSummary_gridWork']/tbody/tr[2]/td[1]")
WebElement WorkPerformedConfirmationPage;
@FindBy(xpath = "//*[@id='ctl00_ContentPlaceHolder1_ucSummary_gridWork']/tbody/tr[2]/td[2]")
WebElement AssetConfirmationPage;
@FindBy(xpath = "//*[@id='ctl00_ContentPlaceHolder1_ucSummary_gridLaborServiceCenterView']/tbody/tr[2]/td[@class='GridViewWideColumn']]")
WebElement LaborTypeConfirmationPage;
@FindBy(xpath = "//*[@id='ctl00_ContentPlaceHolder1_ucSummary_gridLaborServiceCenterView']/tbody/tr[2]/td[@class='NumericCell'][1]")
WebElement HoursConfirmationPage;
@FindBy(xpath = "//*[@id='ctl00_ContentPlaceHolder1_ucSummary_gridLaborServiceCenterView']/tbody/tr[2]/td[@class='NumericCell'][2]")
WebElement SystemRateConfirmationPage;
@FindBy(xpath = "//*[@id='ctl00_ContentPlaceHolder1_ucSummary_gridLaborServiceCenterView']/tbody/tr[2]/td[@class='NumericCell'][3]")
WebElement RequestedRateConfirmationPage;
@FindBy(xpath = "//*[@id='ctl00_ContentPlaceHolder1_ucSummary_gridLaborServiceCenterView']/tbody/tr[2]/td[@class='NumericCell'][4]")
WebElement RequestedRate;
public static WebDriver driver;
public static void webdrive() {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\dmohamed\\Documents\\Testing Environment\\Testing Environment\\Web Drivers\\chromedriver_win32 (1)\\chromedriver.exe");
WebDriver chromedriver = new ChromeDriver();
driver = chromedriver;
}
public void SPSRSearch(String srnumber) {
SPSRSearchbox.sendKeys(srnumber);
SPSRSearchbtn.click();
}
public void SRSelect() {
SRListSelect.click();
}
public void ActivtityCompletition() throws InterruptedException {
CheckinBtn.click();
Thread.sleep(2000);
String Timein = Timeinstamp.getText();
CheckOutBtn.click();
Thread.sleep(5000);
Alert savealert = driver.switchTo().alert();
savealert.accept();
Thread.sleep(2000);
driver.switchTo().frame(ManageActivityBox);
ETABox.clear();
ETABox.sendKeys(Timein);
/*
* //Thread.sleep(2000); TimeinBox.clear();
* TimeinBox.sendKeys("8/1/2016 1:35:00 PM"); //Thread.sleep(2000);
* TimeoutBox.clear(); TimeoutBox.sendKeys("8/1/2016 1:40:00 PM");
* //Thread.sleep(2000);
*/
JobCompleteDropDown.sendKeys("y");
Thread.sleep(2000);
TextBoxSRNote.sendKeys("test");
SavebtnActivityPopup.click();
Thread.sleep(3000);
SavebtnActivityPopup.click();
}
public void InvoiceBillingRequirementCompletion(String Srnumber) throws InterruptedException {
CreateInvoicebtn.click();
String srnumber2 = SRNumberBillingReq.getText(); //Example of getting Service request number in invoice class
InvoiceNumberfield.sendKeys(srnumber2);
InvoiceAmount.sendKeys("0.00");
WorkDateField.click();
Thread.sleep(2000);
TodaysDatebtn.click();
WorkDateField.sendKeys(Keys.ENTER);
CustomerSignatureQuestion.sendKeys("Y", Keys.TAB);
NextStep1.click();
}
public void SPInvoiceWorkPerformed() throws InterruptedException {
Editbtn0.click();
Thread.sleep(2000);
/*
* if (isAlertPresent()) { driver.switchTo().alert().accept(); }
*/
Updatebtn0.click();
Thread.sleep(2000);
NextStep1.click();
}
@FindBy(id = "ctl00_ContentPlaceHolder1_txtSubTotal")
WebElement LaborTotal;
@FindBy(id = "ctl00_ContentPlaceHolder1_lblTaxS")
WebElement TaxAmt;
@FindBy(id = "ctl00_ContentPlaceHolder1_txtTotal")
WebElement LaborTaxTotal;
@FindBy(id = "ctl00_ContentPlaceHolder1_gridLabor_ctl02_txtRate")
WebElement RateSP;
//*[@id='ctl00_ContentPlaceHolder1_gridLabor']/tbody/tr[2]/td[@class='NumericCell'][1]
@FindBy(xpath = "//*[@id='ctl00_ContentPlaceHolder1_gridLabor']/tbody/tr[2]/td[@class='NumericCell'][1]")
WebElement HoursSPInput;
public void SPInvoiceLaboraPartsandSummary() throws InterruptedException {
EditbtnLabor.click();
Thread.sleep(2000);
HoursSP.clear();
HoursSP.sendKeys("1");
UpdatebtnLabor.click();
Thread.sleep(2000);
double LaborHours = Double.parseDouble(HoursSPInput.getText());
System.out.println(LaborHours);
String LaborValue = RateSP.getAttribute("value");
String LaborValue1 = LaborValue.replace("$", "");
System.out.println(LaborValue1);
double LaborRate = Double.parseDouble(LaborValue1);
String SPTotalValue = LaborTotal.getAttribute("value");
String SPTotalValue1= SPTotalValue.replace("$", "");
double SPTotal = Double.parseDouble(SPTotalValue1);
Assert.assertTrue(LaborHours*LaborRate==SPTotal, "Labor Total Mismatch");
String Taxvalue = TaxAmt.getText();
if (TaxAmt.getText().contains("N/A")){
String TaxRealValue=Taxvalue.replace("N/A", "0");
double Tax= Double.parseDouble(TaxRealValue);
String TotalLaborTax = LaborTaxTotal.getAttribute("value");
String TotalLaborTax1= TotalLaborTax.replace("$", "");
double Total = Double.parseDouble(TotalLaborTax1);
Assert.assertTrue(SPTotal+Tax==Total, "Labor + Tax Mismatch");
System.out.println(SPTotal+Tax +" Sum of Labor and Taxes ");
System.out.println( Total + " MyFSN Calculation");
}
else {
//String TaxRealValue=Taxvalue.replace("N/A", "0");
double Tax= Double.parseDouble(Taxvalue);
String TotalLaborTax = LaborTaxTotal.getAttribute("value");
String TotalLaborTax1= TotalLaborTax.replace("$", "");
double Total = Double.parseDouble(TotalLaborTax1);
Assert.assertTrue(SPTotal+Tax==Total, "Labor + Tax Mismatch");
}
NextStep1.click();
NextStep1.click();
AcceptCalculatedAmountSelection.click();
}
public void SPInvoiceAttachment() {
InvoiceAttachmenttbnSP.sendKeys("C:\\Users\\dmohamed\\Desktop\\testPDF.pdf");
NextStep1.click();
SubmitInvoicebtn.click();
}
//InvoiceConfirmation
@FindBy(xpath= "//*[@id='ctl00_ContentPlaceHolder1_ucSummary_pnlLegacyMessage']/strong[1]")
WebElement InvoiceConfirmationMessage;
@FindBy(id= "ctl00_ContentPlaceHolder1_ucSummary_lblSCInvoiceNumber")
WebElement SRNumberInvoiceConfirmation;
@FindBy(id= "ctl00_ContentPlaceHolder1_ucSummary_lblGrandTotal")
WebElement InvoiceTotalConfirmation;
public void InvoiceConfirmation () throws InterruptedException{
Thread.sleep(3000);
if (InvoiceConfirmationMessage.getText().contains("You have successfully submitted your invoice ")) {
System.out.println("MyFSN SP invoice submission successful");
}
else {
Assert.fail("MyFSN SP invoice submission failed");
}
String Srnumber3 = SRNumberInvoiceConfirmation.getText();
System.out.println(Srnumber3);
}
}
package pageobjectfactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.Alert;
public class HomePagePOFSC {
@FindBy(id = "ctl00_Menu1_0")
WebElement Home;
@FindBy(id = "ctl00_Menu1_1")
WebElement Inventory;
// InventorySublinks
@FindBy(id = "ctl00_Menu1_2")
WebElement Cyclecount;
@FindBy(id = "ctl00_Menu1_3")
WebElement PartsOnHand;
@FindBy(id = "ctl00_Menu1_4")
WebElement TransactionSearch;
@FindBy(id = "ctl00_Menu1_5")
WebElement ParManagement;
// InventorySublinks
@FindBy(id = "ctl00_Menu1_6")
WebElement Orders;
@FindBy(id = "ctl00_Menu1_7")
WebElement Queues;
// Queue Sublinks
@FindBy(id = "ctl00_Menu1_8")
WebElement InvoiceQueue;
@FindBy(id = "ctl00_Menu1_9")
WebElement QuoteQue;
@FindBy(id = "ctl00_Menu1_10")
WebElement RequisitionQueue;
// Queue Sublinks
@FindBy(id = "ctl00_Menu1_11")
WebElement MyAccount;
@FindBy(id = "ctl00_Menu1_12")
WebElement CreateNewSRlink;
@FindBy(id = "ctl00_Menu1_13")
WebElement PrintVouchers;
@FindBy(id = "ctl00_Menu1_14")
WebElement Tools;
@FindBy(id = "ctl00_Menu1_29")
WebElement Logout;
@FindBy(id = "ctl00_ContentPlaceHolder1_txtSRNumber")
WebElement SRSearchfield;
@FindBy(id = "ctl00_ContentPlaceHolder1_btnViewSR")
WebElement SRSearchBtn;
@FindBy(id = "ctl00_ContentPlaceHolder1_pnlButtons")
WebElement ProcessSRAsContractorbtn;
public void NavigateToInvoice() {
Actions action = new Actions(driver);
action.moveToElement(Queues).perform();
WebElement subElement = InvoiceQueue;
action.moveToElement(subElement);
action.click();
action.perform();
//Would search for service request at this point
}
public static WebDriver driver;
public static void webdrive() {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\dmohamed\\Documents\\Testing Environment\\Testing Environment\\Web Drivers\\chromedriver_win32 (1)\\chromedriver.exe");
WebDriver chromedriver = new ChromeDriver();
driver = chromedriver;
}
}
答案 0 :(得分:0)
尝试使方法InvoiceBillingRequirementCompletion()
返回您想要的变量并通过调用方法将其传递给您的实际测试并将其分配给这样的var:
String var = InvoicingPOF.InvoiceBillingRequirementCompletion(x);