Forum Discussion

ḥari's avatar
ḥari
Frequent Contributor
2 years ago

Mobile testing

Hi team,

1) I am doing mobile web testing using emulators. It is opening as a "smartbear test extension" started debugging this browser. Here i need to set a resolution based on the mobile we are selecting. So, i need to set a resolution over there.

>>refer the below code,

function main(){

VirtualBrowsers.Item("iPad").Run();

var mblPage=VirtualBrowsers.CurrentBrowser.Navigate("https://www.smartbear.com/");

var element=mblPage.FindElement("xpath");

element.click();

}

>>Here need to set resolution over there as width (768) and height (1024) 

 

2) I tried to click over an element in that page but it throws error as TypeError: cannot read property "FindElement" of undefined

Could any one helpme regarding this issue??

  • In your code that you have written

     

    var mblPage=VirtualBrowsers.CurrentBrowser.Navigate("https://www.smartbear.com/");

     

    the Navigate Method returns none, and not a Page object.

     

    and,

     

    var page=VirtualBrowsers.Item("iPad").Run("https://www.smartbear.com/");

     

    the Run Method returns a Process object if found, and not a Page object.

     

    Make sure you fully understand the above methods and their return objects. In my previous response, did you see the code example in Page Object? It's vital you learn the basics, knowing how to select an object on a page, before jumping ahead and wanting to use VirtualBrowser

    • ḥari's avatar
      ḥari
      Frequent Contributor

      I have verified this option, but i didn't noticed that width and height. Thank you

       

      How to accessing web objects in virtual browsers???

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    In your code that you have written

     

    var mblPage=VirtualBrowsers.CurrentBrowser.Navigate("https://www.smartbear.com/");

     

    the Navigate Method returns none, and not a Page object.

     

    and,

     

    var page=VirtualBrowsers.Item("iPad").Run("https://www.smartbear.com/");

     

    the Run Method returns a Process object if found, and not a Page object.

     

    Make sure you fully understand the above methods and their return objects. In my previous response, did you see the code example in Page Object? It's vital you learn the basics, knowing how to select an object on a page, before jumping ahead and wanting to use VirtualBrowser

    • ḥari's avatar
      ḥari
      Frequent Contributor

       

      rraghvani Am i did the correct code for mobile testing. Refer bellow code and let me know if i make any mistakes over there

      function amazon_LogIn
      {
      var devices=["Samsung Galaxy Note 9","Samsung Galaxy S9"];
      for(var k=0;k<devices.length;k++)
      {
      var mode=["Portrait()","Landscape()"];
      for(var m=0;m<mode.length();m++)
      {
      VirtualBrowsers.Item(devices[k]).Run("http://www.amazon.com/");
      aqUtils.Delay(2000);
      let browser=Aliases.browser;
      browser.BrowserWindow.Maximize();
      let page=browser.Page("*");
      if(m==1 && (VirtualBrowser.CurrentBrowser.ScreenWidth<VirtualBrowser.CurrentBrowser.ScreenHeight))
      {
      VirtualBrowser.CurrentBrowser.Landscape();
      Log.Picture(page.PagePicture(),"In Landscape mode");
      }
      else if(VirtualBrowser.CurrentBrowser.ScreenWidth>VirtualBrowser.CurrentBrowser.ScreenHeight)
      {
      VirtualBrowser.CurrentBrowser.Portrait();
      Log.Picture(page.PagePicture(),"In portrait mode");
      }
      var logIn=page.FindElement("//*[@class='nav-progressive-content']//a[@href]");
      if(logIn.Exists)
      {
      logIn.ScrollIntoView(true);
      logIn.Click();
      }
      var userName=page.FindElement("//*[@id='ap_email_login']");
      userName.Keys("User");
      page.FindElement("(//*[@class='a-button-input'])[3]").click();
      if(m==1)
      browser.close();
      }}}

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Use appropriate indentation and spacing in your code. For example,

     

    function amazon_LogIn
    {
    	var devices = ["Samsung Galaxy Note 9", "Samsung Galaxy S9"];
    	for (var k = 0; k <devices.length; k++)
    	{
    		var mode = ["Portrait()", "Landscape()"];
    		for (var m = 0; m < mode.length(); m++)
    		{
    			VirtualBrowsers.Item(devices[k]).Run("http://www.amazon.com/");
    			aqUtils.Delay(2000);
    			let browser = Aliases.browser;

     

    So that it is easier to read.

     

    • ḥari's avatar
      ḥari
      Frequent Contributor
      rraghvani ok. Sorry for the inconvenience . I can't able to share my code directly so i have typed so only
    • ḥari's avatar
      ḥari
      Frequent Contributor

      Did you refer this code

      function main(){

      VirtualBrowsers.Item("iPad").Run();

      var mblPage=VirtualBrowsers.CurrentBrowser.Navigate("https://www.smartbear.com/");

      var element=mblPage.FindElement("xpath");

      element.click();

      }

       

      >>error as "TypeError cannot read property "FindElement " of undefined

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Navigate Method doesn't return anything, and you are calling FindElement. You need to get the Page object - refer to TC documents, there's plenty of examples.

    • ḥari's avatar
      ḥari
      Frequent Contributor

      var page=VirtualBrowsers.Item("iPad").Run("https://www.smartbear.com/");

      here also page object return empty only

      Can you pls help me here somewhere i am missing out the logic ???

    • ḥari's avatar
      ḥari
      Frequent Contributor

      rraghvani i can understand what you are saying but

      Here I am using page object for virtualBrowser but it's throwing error as cannot read property "FindElement" of undefined

       

      >>Navigate method doesn't return anything means now am using Run method. Now also am getting same error.

      Refer the sample code below,

      let page=VirtualBrowsers.Item("Apple iPad").Run("https://www.google.com/");

      var element=page.FindElement("XPath");

      element.click();

       If I use Run method also page object doesn't return any object!! 

      Here I need to search like findelements method for mobile object

      Literally confused her about the (locationstrategy and selectorvalue) 

      Page. Findelement("xpath", "//*[@class='mblvalu']) 

      If am wrong correct me 

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If you run your code, does it work, the way you expect it to?

    • ḥari's avatar
      ḥari
      Frequent Contributor
      Yeah, I want to run that script in 2 device and 2 orientation it was working fine. I have an doubt the way I have created the script is fine or not??