Forum Discussion

obaid_shirwani's avatar
obaid_shirwani
Contributor
10 years ago

Executing test on a different domain.

I want to execute the test cases on a totally different domain. Suppose a part of my script goes like this:




function AddOneTrialReport()


{


  //1. Name: Generate a new Unique report name using the current time stamp.


  var CurrentTimeStamp = aqDateTime.Now();


  var ReportName =  "TestReport_"+aqConvert.DateTimeToFormatStr(CurrentTimeStamp,"%Y%m%d%H%M%S");


  Log.Message(ReportName);

 


  Aliases.browser.Page("http://staging01/myApp/AddReport.aspx", 0).Form("pageForm").Panel("colright").Panel("divContentsArea").Panel("ContentPlaceHolder1_reportPanel").Panel(0).Panel(0).Table(0).Cell(0, 1).Textbox("ContentPlaceHolder1_txtName").Text = ReportName; 


  

}



Now I want to change this URL to http://staging02/myApp/AddReport.aspx



Is there any project's property from where I can change this domain. The test scripts will formulate 1000's of lines and modifying every place is not easy. 



Creating Variables <as under> is one option but I dont think that is smart either.




function AddOneTrialReport()


{


  //1. Name: Generate a new Unique report name using the current time stamp.


  var CurrentTimeStamp = aqDateTime.Now();


  var ReportName =  "TestReport_"+aqConvert.DateTimeToFormatStr(CurrentTimeStamp,"%Y%m%d%H%M%S");


  Log.Message(ReportName);

 


var addReport = Project.Variables.domain+Project.Variables.addReport;

//where variable domain holds http://staging01/myApp/

//where variable addreport holds AddReport.aspx


 

Aliases.browser.Page("addReport", 0).Form("pageForm").Panel("colright").Panel("divContentsArea").Panel("ContentPlaceHolder1_reportPanel").Panel(0).Panel(0).Table(0).Cell(0, 1).Textbox("ContentPlaceHolder1_txtName").Text = ReportName; 


  

}



Please share if there is something else.



5 Replies

  • As long as you don't care which domain you're in (when referencing the reports page), you could just wildcard the domain entirely. We have different domains for our different environments, so in my name mapping all of the pages are mapped like "*/portal/index.aspx*". That way, the test itself doesn't care what environment I'm in. I just need a separate way to actually navigate to the correct domain to start with.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Also, you may store the domain address in the project variable and for the URL property in the NameMapping file indicate that the value for URL should be taken from this variable. After that, you'll have to correct the value of this variable when you need to change the domain address.
  • I tried this:



    1. In the nameMapping, I modified the Page URL's domain part with a wildcard (*) like this: "*/myApp/adminLogin.aspx"



    2.a. I defined a Persistent Variable in the Projects Variables named domain and assigned it the domain address: "http://myDomain"



    2.b. I defined another Persistent Variable in the Projects Variables named adminLogin and assigned it the adminLogins trail: "/myApp/adminLogin.aspx"



    3. The adminLogin function goes like this:




    function LoginMyApp()


    {


      var adminLoginURL;


      Browsers.Item(btChrome).Run("chrome://newtab/");


     

      adminLoginURL = Project.Variables.domain+Project.Variables.adminLogin;  


      


      Aliases.browser.ToUrl(adminLoginURL);


       Aliases.browser.myAppAdminloginMain.formForm1.textboxEmployeeOid.SetText("admin");


      Aliases.browser.myAppAdminloginMain.formForm1.passwordboxPassword.SetText("password");



     Aliases.browser.myAppAdminloginMain.formForm1.submitbuttonLogincontrolLoginbut.ClickButton();


      Aliases.browser.myAppAdminloginMain.Wait();


    }



    4.1. This is all working as desired.

    4.2. NameMapping works correctly when the domain variable's value is changed. 

    4.3 Executing tests on all desired domains works by simply modifying the 'domain' variables value.



    5. My question is: Is this the best practice or do we have a smarter way?

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    We constructed a domain path similar to yours and passed the pieces in through parameters.  If you did that, you could read the list of domains from a table and loop through the list.