How to programmatically "translate" a page in EPiServer 10 - c#

I am currently creating a new page from code to use as my startpage for a sitedefinition which I also create from code..however.. even if I publish the newly created startpage I always end up with the following message in the CMS UI:
"This content is in English. It does not exist in svenska. Would you like to translate it now?"
How can I "Translate" the page from programmatically and then publish it as well? I haven't been able to find anything related to this here or while googling it.

You need to use the CreateLanguageBranch available in the IContentRepository.
In my example below Swedish is the default language on the site
var parent = ContentReference.RootPage;
IContentRepository contentRepository =
EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
StartpagePage startpage = contentRepository.GetDefault<StartpagePage>(parent);
startpage.PageName = "Teststartsida";
startpage.Title = "Teststartsida";
// this will create a startpage in the default language, Swedish in my case,
// use SaveAction.Publish and save the page into a new variable
var createdPage = contentRepository.Save(startpage,
EPiServer.DataAccess.SaveAction.Publish,
AccessLevel.NoAccess);
// invoke CreateLanguageBranch with LanguageSelector
var startpageLanguageBranch =
contentRepository.CreateLanguageBranch<StartpagePage>(createdPage,
new LanguageSelector("en"));
startpageLanguageBranch.PageName = "Start page test";
startpageLanguageBranch.Title = "Start page test";
// this will create a languagebranch in the language stated with the LanguageSelector.
// Use SaveAction.Save
contentRepository.Save(startpageLanguageBranch,
EPiServer.DataAccess.SaveAction.Save,
AccessLevel.NoAccess);

Related

DocuSign API: Populating dynamic fields

I am trying to have fields in my template be populated when I call the post request of my API, currently I am getting the template which I created in DocuSign's Template creator. But I need to be able dynamically change these fields contents.
How do I find the custom field which I created? I am currently using TextCustomField. The only thing I can see which would find the custom field is FieldId but there is no option on the website to set or find one. So I am not sure what to do from here. Here is a code snippet to how I have tried it so far, to no success.
I a junior developer and I am new to docusign, and I feel that the documentation leaves a lot to be desired.
CustomFields cf = new CustomFields();
cf.TextCustomFields = new List<TextCustomField>();
TextCustomField tcf = new TextCustomField();
tcf.FieldId = "001";
tcf.Name = "test";
tcf.Value = "NewValueFor test_field_1";
cf.TextCustomFields.Add(tcf);
env.CustomFields = cf;
I set the data label on the website to 001.
Looks like there's been a misunderstanding in DocuSign vocabulary. Your screenshot shows a "field", which in eSignature API terms is a "tab". The TextCustomField object you currently have would be used to populate an Envelope Custom Field - not what you're currently trying to do.
If you've placed that tab on your template, then you can populate it's value by creating a TextTab object and assigning it to your signer's list of tabs like so. The TabLabel aligns with the web console's Name parameter, and the Value is what you want to populate it with.
Text exampleTab1 = new Text //Create the Tab definition
{
Value = "Example Value",
TabLabel = "test_field_1",
};
Signer signer1 = new Signer //Create a Signer
{
Email = signerEmail,
Name = signerName,
RecipientId = "1",
RoutingOrder = "1",
};
Tabs signer1Tabs = new Tabs //Assign Tab to Signer
{
TextTabs = new List<Text> { exampleTab1 }
};
You probably can leverage the C# feature called LINQ, you need to add the following namespace to your class:
using System.Linq;
And then you can find your objects with this code:
var mycustomField = cf.TextCustomFields.FirstOrDefault(f => f.FieldId == "MYIDENTIFICATOR");

Can the PageSource property in Selenium be updated as JavaScript loads data?

I'm trying to determine if there's specific text on the page. I'm doing this:
public static void WaitForPageToLoad(this IWebDriver driver, string textOnPage)
{
var pageSource = driver.PageSource.ToLower();
var timeOut = 0;
while (timeOut < 60)
{
Thread.Sleep(1000);
if (pageSource.Contains(textOnPage.ToLower()))
{
timeOut = 60;
}
}
}
The problem is that the web driver's PageSource property isn't updated after the initial load. The page I'm navigating to loads a bunch of data via JS after the page has already loaded. I don't control the site, so I'm trying to figure out a method to get the updated HTML.
You are trying to solve the wrong problem. You need to wait for the text to appear using an XPath locator:
var wait = new WebDriverWait(driver);
var xpath = $"//*[contains(., '{textOnPage}')]";
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(xpath));
Do you really need to search entire page?
I'll reference you to here: https://stackoverflow.com/a/41223770/1387701
with this code:
String Verifytext= driver.findElement(By.tagName("body")).getText().trim();
You can then check to see if the Verifytext contains the string you're checking for.
This works MUCH better if you can narrow the location of the text down to a particular webElement other than the body.

Selenium can't handle multiple ChromiumWebBrowser instances in C#

I have two instances of the ChromiumWebBrowser in my WinForms project (Visual Studio 2012). My goal is to have the second browser instance "copy" the behavior of the user input in the first browser instance. I can successfully retrieve the input from the first browser, and I managed to hook up Selenium in the project as well.
However, I'm having one issue. Whenever Selenium sends its commands, the first browser is the one that responds to them. For the life of me, I can't seem to figure out how to make the second browser respond. Whenever I completely remove the first browser, the second one starts responding correctly, but adding the first browser again will make only have the first browser use the Selenium commands. I even tried to switch out the moments the browsers are added to the form, but to no avail: whenever there are two available, the wrong one is responsive.
Relevant code:
public BrowserManager(Controller controller, string startingUrl)
{
_controller = controller;
var settings = new CefSettings { RemoteDebuggingPort = 9515 };
Cef.Initialize(settings);
// Input browser
inputBrowser = new ChromiumWebBrowser(startingUrl);
var obj = new XPathHelper(this);
inputBrowser.RegisterJsObject("bound", obj); //Standard object registration
inputBrowser.FrameLoadEnd += obj.OnFrameLoadEnd;
// Output browser
var browserSettings = new BrowserSettings();
var requestContextSettings = new RequestContextSettings { CachePath = "" };
var requestContext = new RequestContext(requestContextSettings);
outputBrowser = new ChromiumWebBrowser(startingUrl);
outputBrowser.RequestContext = requestContext;
outputBrowser.AddressChanged += InitializeOutputBrowser;
outputBrowser.Enabled = false;
outputBrowser.Name = "outputBrowser";
}
The selenium part:
public class SeleniumHelper
{
public SeleniumHelper()
{
DoWorkAsync();
}
private Task DoWorkAsync()
{
Task.Run(() =>
{
string chromeDriverDir = #"ActionRecorder\bin\x64\Debug\Drivers";
var chromeDriverService = ChromeDriverService.CreateDefaultService(chromeDriverDir);
chromeDriverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.BinaryLocation = #"ActionRecorder\bin\x64\Debug\ActionRecorder.exe";
options.DebuggerAddress = "127.0.0.1:9515";
options.AddArguments("--enable-logging");
using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(chromeDriverService, options))
{
driver.Navigate().GoToUrl("http://www.google.com");
var query = driver.FindElement(By.Name("q"));
query.SendKeys("A google search test");
query.Submit();
}
});
return null;
}
}
And finally, a screenshot for some visualization:
Some help with the issue would be very much appreciated. If i missed some crucial info, feel free to ask for it. Thanks in advance!
Greetz,
Tybs
The behavior is correct. You have one debug address and you can only have one debug address for CEF. Which means when you use Selenium it is only seeing one browser.
By default Selenium will send an command to current active Tab or Window. Now in your case you have multiple Chrome view embedded, but they are technically Chrome Tab/Windows which you have placed on the same form.
So if you are in luck below code in should be able to move you to the Window you are interested in
driver.SwitchTo().Window(driver.WindowHandles.Last());
See if it works. If it doesn't then your only other workaround would be to change the order of Adding ChromiumWebBrowser and that should reverse the window it works on.
Below are some important threads that you should read from top to bottom. Very relevant to your issue/request
https://code.google.com/archive/p/chromiumembedded/issues/421
https://github.com/cefsharp/CefSharp/issues/1076

DocuSign SOAP API Title Tab does not keep value

I am using DocuSign SOAP API in an ASP.NET app in C# to send some docs for e-signature.
One of the field is the title tab. I have the following code for that.
When testing, the tab correctly shows the title, which is picked up from the back-end DB. But when I see the completed document, the title is changed to something else. Does anyone know how can I resolve this?
When signing, if I modify the value - add and remove space - it works OK.
tab5 = new DocuSignAPI.Tab();
tab5.RecipientID = rcpt1.ID;
tab5.DocumentID = docId;
tab5.Type = DocuSignAPI.TabTypeCode.Custom;
tab5.CustomTabType = DocuSignAPI.CustomTabType.Text;
tab5.Name = "clientTitle";
tab5.CustomTabTypeSpecified = true;
tab5.Value = (dr["Rcpt_1_Role"]).ToString();
tab5.Type = DocuSignAPI.TabTypeCode.Title;
tab5.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab5.AnchorTabItem.AnchorTabString = "CLIENT TITLE:";
tab5.AnchorTabItem.Unit = DocuSignAPI.UnitTypeCode.Pixels;
tab5.AnchorTabItem.UnitSpecified = false;
tab5.AnchorTabItem.IgnoreIfNotPresent = true;
tab5.AnchorTabItem.UnitSpecified = true;
tab5.AnchorTabItem.YOffset = -10;
tab5.AnchorTabItem.XOffset = 100;
When using certain DocuSign tab types (such as titleTabs or emailTabs for instance) the DocuSign platform will populate some of that information from the user's account if they have one.
For example, if the user has a DocuSign account where they have entered the title "CEO", then whenever you send an envelope to that exact recipient (name and email combo) and you use a titleTab the system will populate from their account.
I do not believe there is a way to override this, probably your best option is to just use a textTab instead and with that you can populate with any data from a database or wherever else you want to supply it from.

How to verify that a new tab is opened in a browser with TestComplete using C#

I am testing a website. In the body of website has a URL. After clicking that URL it should be opened in a new tab, not in same window. After clicking the URL link it is opened in new tab browser. I have tested it manually.
I want to verify that feature by using TestComplete with C#Script. How to do it?
You can simulate a click to this link and then check whether the URL of the current page object has been changed and whether a new page object with the target URL has appeared.
function Test1()
{
var browser = Sys.Browser("firefox");
var numOfTabs = browser.FindAllChildren("ObjectType", "Page").toArray().length;
var page = browser.ToUrl("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_links_target");
var pageUrl = page.Url;
frame = page.Panel(0).Panel(1).Panel(0).Panel(1).Frame("iframeResult");
frame.Link(0).Click();
if (page.Url != pageUrl)
Log.Error("The page's URL has been changed!");
if (browser.FindAllChildren("ObjectType", "Page").toArray().length == numOfTabs)
Log.Error("A new tab has not been opened!");
}

Categories