Need to change a value in my data source

Class library usage, coding and language questions.
tiffin.filion
Posts: 56
Joined: Thu Oct 29, 2020 12:47 am

Need to change a value in my data source

Post by tiffin.filion » Fri Aug 13, 2021 5:39 am

In our test suite, I have smart folders for mobile and desktop as our website is responsive and the only difference is the navigation. I have a code module checking for mobile and setting the variable IsMobile to true. I have a data source with one column (IsMobile) with one value in the single row (False). How can I change that one value on my data source to true? It would not need to be a permanent change as we always want the default to be false. I initially used the simple connector but going through the forums I changed to csv. But I can't seem to figure out how to grab that value.

JasonY
Posts: 9
Joined: Fri May 28, 2021 3:51 pm
Contact:

Re: Need to change a value in my data source

Post by JasonY » Fri Aug 13, 2021 9:53 pm

Hello Tiffin,

You should be able to change values in your data source by either right clicking your Test Case/Smart Folder and then selecting the Data Source option in the list. The other method would be to find file location of the .csv file that you created and then edit the value there. You can refer to our User Guide for more specific steps on the two actions mentioned: https://www.ranorex.com/help/latest/ran ... a-binding/.

Best Regards
Image

tiffin.filion
Posts: 56
Joined: Thu Oct 29, 2020 12:47 am

Re: Need to change a value in my data source

Post by tiffin.filion » Fri Aug 13, 2021 10:44 pm

I meant within a code module. But I think I've got it figured out. I saw another post that said you have to link the code module variable to the repository variable. And that seems to have done the trick.

repository modue:

Code: Select all

public class TestForMobile : ITestModule
    {

    string _IsMobile = "False";
    [TestVariable("51795d57-f213-4fdd-908e-ecb49ec0fa00")]
    public string IsMobile
    {
    	get { return _IsMobile; }
    	set { _IsMobile= value; }
    
    }
The in the run() section I created the code variable mobile and linked it to "IsMobile". Then after I did my checks and all that to determine if it was mobile or not (setting mobile = "True" or "False"), I then linked IsMobile back to mobile to update the value (if it changed).

Code: Select all

var repo = TestRepository.Instance;
            var mobile = IsMobile;
            
            var host = Host.Current;
            var webdriver = host.TryGetAsWebDriverEndpoint();
            if (webdriver != null)
            {
            	mobile = GetConfigIsMobile(webdriver).ToString();
            }

            if (repo.Test.Self.Browser.ScreenRectangle.Width < 1025) {
            	mobile = "True";
            }
            
			IsMobile = mobile;