Whether you read books, play video games, or tabletop RPG’s, one thing is very common among them; swords. Swords are ubiquitous to the point of being considered the basic weapons of pre-modern melee fighters. I read however that swords historically were much less common in warfare than is widely believed and that the most used weapons tended to be spears, javelins, and other cheaper weapons with a longer reaches that were easier to replace.
Throughout military history, were swords as prevalent as depicted in fiction or is this just a result of romance stories featuring swords as a central symbol (Arthurian legends for instance)?
It might be fair to characterize swords as the most common weapon of war, but there are some important caveats. Swords were actually pretty rare as a primary military weapon. Spears and other pole weapons were much more common, significantly cheaper, and substantially more dangerous, especially in massed infantry formations. There are certain eras and military doctrines where this wasn't the case; for example, the early Roman Empire had a very sword-centric doctrine (although early republic and late empire, not so much). But broadly speaking, something in the spear or pike family has much greater claim to being the most common military armament before guns, and this is true just about everywhere in the world.
Swords do, however, have a much better claim on being the most common secondary weapon of war. While they were rarely the first choice for soldiers, they were quite a popular second choice. That's because swords were very good multi-purpose, all-round weapons--not necessarily what you need to get your primary job done, but definitely what you want to have handy when things got messy and chaotic, which they often did. So hoplites also carried a sword for when the phalanx broke down, knights carried a sword for when their lance broke, archers carried swords in case their position was overrun. Across all unit types, swords were pretty popular as a backup weapon.
In fact, swords were so useful as a backup weapon, that swordsmen carried swords as backup weapons. The two-handed great swords of the 16th Century, for example, were not general-purpose weapons, and soldiers who specialized in weapons like the zweihander generally carried a back-up sword in case an actual sword fight broke out.
The use of swords as secondary weapons continued into the gunpowder era, and not just for Dumas' musketeers. If your primary weapon was a cannon, you'd still carry a sword as a backup weapon. If your primary weapon was a repeating rifle, you could also be issued a sword bayonet, right up through WW2. Now both of those examples are short weapons, with blades in the 35-50 cm range, so they aren't the sort of "glam" weapons that you generally see in video games or Hollywood spectacles.
But backup swords were generally not prestige weapons; they were practical, short, light, cheap, easy to use, and capable of doing double or triple duty. For instance, 99% of the action seen by those artillery swords was probably clearing brush to prepare gun emplacements, and those sword bayonets saw a lot of use as makeshift entrenchment tools. But the requirements for a versatile backup weapon were the same as far back in history as you care to look. The hoplite xiphos was about 50 cm long, with the Spartans apparently preferring one that was closer to 30 cm. The Germanic seax had a similar range of sizes. So the ubiquity of swords as secondary weapons should not be taken to mean that everyone had an Andúril or a pattern-welded katana just sitting in reserve. Back-up swords were much closer to a big-ass knife than to the two-handed "prestige" swords that you are familiar with from movies and video games. A soldier has a lot of uses for a big knife, and very few for a long sword.
That doesn't mean that the "prestige" swords were a myth, just that they tended to be weapons of the aristocracy. It's a lot easier to carry around a larger backup sword if, say, you are riding a horse around all day. Or if you are a commander or officer who is not expected to be in the thick of fighting (so that you only carry a backup weapon, so to speak). Or, say, if you are a civilian aristocrat whose primary weapon is your tongue, for whose offences you might need to resort to a real weapon as backup from time to time.
But that "prestige" factor is what made those long swords more glamorous, and more prominent in legend and literature. Not exactly fiction, but more of a vision of the past as seen through an aristocratic lens, which I'm sure someone with a better understanding of class representation in literature could comment on better than me. But take a soldier like Haleth, son of Háma--the implication is that he is a peasant boy forced into a desperate fight, in which case the fact that he has just been issued a sword longer than his arm is patently ridiculous. Give the boy an axe, at least he'll know what to do with it!
This is not a direct answer to your question, but a caveat that "swords are romanticized as the most common weapons of war and single combat" is itself not universal!
For example, in Indian epics like the Ramayana and the Mahabharata, the bow and not the sword is the primary, celebrated, weapon. The greatest warriors are archers in chariots, and a sword is something a desperate warrior uses when he has lost his chariot and his bow. Some warriors are noted for using a mace (Bhima, Duryodhana), a spear (Shalya, Yudhisthira), or a sword (Sahadeva, Satyaki), but they are very much the exception.
Another example is in the 16th century Prithviraj Raso, a highly romanticized account of the life of Prithviraj Chauhan. Prithviraj, who has been imprisoned and blinded by Muhammad Ghori, kills Ghori by aiming an arrow at the sound of Ghori's voice. Again, archery, not swordsmanship, is celebrated.
So, just as swords were not always the primary weapon of war, neither was their depiction as primary weapons or even as symbols.
I don't have an answer but can recognize your question is rather broad (both in time and geography, as the era of swords would probably cover 1000 BCE to the 1700s CE), but this answer by /u/wotan_weevil may help a bit on how actual war in pre-gunpowder eras was waged. This answer by /u/BlueStraggler may also help.
You might also find this answer by /u/J-Force, while not directly sword related, of interest as actual battle is described, and this answer by /u/MI13 talks about the disposability of weapons - namely that all of them are treated as disposable and temporary.