以下のコードでは、beforetestメソッドがstring srnumber
を返していることがわかります。この変数は、beforetestメソッドの実行中に生成される一意の識別子です。私がしたいことは、その一意の番号を保存し、それを他の方法で参照することです。私は様々な理由のためにしたくない参照時にメソッド全体を実行しないメソッドの戻り値を渡す方法はありますか?
public void ReferenceMethod(){
String InvoiceReference = beforetest()
Searchfield.sendkeys(InvoiceReference)
}
全体beforetest method
実行、それは新しい固有の番号を作成している主なもののような何かをするとき、私はに実行しています 問題があります。
package fcstestingsuite.fsnrgn;
import org.testng.annotations.Test;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
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;
HomePagePOFSC HomePageSC;
Utilities UtilClass;
@BeforeSuite
public String beforeTest() throws InterruptedException {
SRCreate.webdrive();
InvoicingPOF.webdrive();
HomePagePOFSC.webdrive();
PageFactory.initElements(new AjaxElementLocatorFactory(Utilities.driver, 60), this);
Utilities.driver.get("fsndevweb:81");
SRCreatePage = PageFactory.initElements(Utilities.driver, SRCreate.class);
LoginPage = PageFactory.initElements(Utilities.driver, Ourfsnlogin.class);
Invoicing = PageFactory.initElements(Utilities.driver, InvoicingPOF.class);
HomePage = PageFactory.initElements(Utilities.driver, HomePagePOF.class);
HomePageSC = PageFactory.initElements(Utilities.driver, HomePagePOFSC.class);
LoginPage.sendUserName("ebluth");
LoginPage.sendPassword("password");
LoginPage.clicksubmit();
LoginPage.USclick();
SRCreatePage.NavigateToSRCreatebtn();
SRCreatePage.SRCreationTestHVAC();
String srnumber = SRCreatePage.SRNumber.getText();
LoginPage.Logout();
LoginPage.sendUserNameSP("4335701");
LoginPage.sendPassword("password");
LoginPage.clicksubmit();
LoginPage.SPSRSearch(srnumber);
Thread.sleep(3000);
Invoicing.ActivtityCompletition();
HomePage.HomePageNaviate();
LoginPage.SPSRSearch(srnumber);
return srnumber;
}
これは、メソッドリターンオブジェクトを参照するときに期待される動作であると私は理解します。それを変更する方法はありますか? SR番号が必要なすべてのメソッドにbeforetestコードを含める必要はありません。どんな助けもありがとう!私もJavaにかなり新しいですので、私のコードで死ぬ罪があれば、私は事前に謝罪します。
「SR番号が必要なすべてのメソッドに事前テストコードを含める必要は本当にありません」という意味はどうですか? 'beforeTest()'をちょうど1回呼び出して結果を保存します。 'InvoiceReference'をもう一度呼びたくなければ、行の下の他のメソッドに渡す必要があるかもしれません。それがこの方法です。 –